From efe3388ac9e8172234776649820bc3c963245b46 Mon Sep 17 00:00:00 2001 From: ayn2op Date: Thu, 12 Sep 2024 14:22:03 +0530 Subject: [PATCH] feat: hide messages from blocked users Closes #392 --- README.md | 6 +++--- cmd/messages_text.go | 16 ++++++++++++++++ internal/config/config.go | 11 +++++++---- 3 files changed, 26 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 77b14606..e8310a93 100644 --- a/README.md +++ b/README.md @@ -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" diff --git a/cmd/messages_text.go b/cmd/messages_text.go index 2666516b..3c339b95 100644 --- a/cmd/messages_text.go +++ b/cmd/messages_text.go @@ -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 diff --git a/internal/config/config.go b/internal/config/config.go index 755d0486..80c54f89 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -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"` @@ -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,