Ver código fonte

feat: hide messages from blocked users

Closes #392
ayn2op 1 ano atrás
pai
commit
efe3388ac9
3 arquivos alterados com 26 adições e 7 exclusões
  1. 3 3
      README.md
  2. 16 0
      cmd/messages_text.go
  3. 7 4
      internal/config/config.go

+ 3 - 3
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"

+ 16 - 0
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

+ 7 - 4
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,