Skip to content

Commit

Permalink
feat: hide messages from blocked users
Browse files Browse the repository at this point in the history
Closes #392
  • Loading branch information
ayn2op committed Sep 12, 2024
1 parent bda8419 commit efe3388
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 7 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,14 @@ The configuration file allows you to configure and customize the behavior, keybi

```toml
mouse = true
hide_blocked_users = true
messages_limit = 50
editor = "default"

timestamps = false
timestamps_before_author = false
timestamps_format = "3:04PM"

messages_limit = 50
editor = "default"

[keys]
focus_guilds_tree = "Ctrl+G"
focus_messages_text = "Ctrl+T"
Expand Down
16 changes: 16 additions & 0 deletions cmd/messages_text.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,22 @@ func (mt *MessagesText) reset() {
}

func (mt *MessagesText) createMessage(m discord.Message) {
if cfg.HideBlockedUsers {
ready := discordState.Ready()
var isBlocked bool
for _, relationship := range ready.Relationships {
if relationship.Type == discord.BlockedRelationship && relationship.UserID == m.Author.ID {
isBlocked = true
break
}
}

if isBlocked {
fmt.Fprintln(mt, "[:red:b]Blocked message[:-:-]")
return
}
}

switch m.Type {
case discord.DefaultMessage, discord.InlinedReplyMessage:
// Region tags are square brackets that contain a region ID in double quotes
Expand Down
11 changes: 7 additions & 4 deletions internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ import (
)

type Config struct {
Mouse bool `toml:"mouse"`
Mouse bool `toml:"mouse"`
HideBlockedUsers bool `toml:"hide_blocked_users"`

MessagesLimit uint8 `toml:"messages_limit"`
Editor string `toml:"editor"`

Expand All @@ -24,9 +26,10 @@ type Config struct {

func defaultConfig() *Config {
return &Config{
Mouse: true,
MessagesLimit: 50,
Editor: "default",
Mouse: true,
HideBlockedUsers: true,
MessagesLimit: 50,
Editor: "default",

Timestamps: false,
TimestampsBeforeAuthor: false,
Expand Down

0 comments on commit efe3388

Please sign in to comment.