Create new isBlocked method as util method
MODIFY
discordutil/users.go
discordutil/users.go
@@ -132,3 +132,16 @@ func SortUserRoles(roles []string, guildRoles []*discordgo.Role) {
return firstRole.Position > secondRole.Position
})
}
+
+// IsBlocked checks whether the state contains any relationship that says the
+// given user has been blocked.
+func IsBlocked(state *discordgo.State, user *discordgo.User) bool {
+ for _, relationship := range state.Relationships {
+ if relationship.User.ID == user.ID &&
+ relationship.Type == discordgo.RelationTypeBlocked {
+ return true
+ }
+ }
+
+ return false
+}

MODIFY
ui/chatview.go
ui/chatview.go
@@ -244,14 +244,7 @@ OUTER_LOOP:
}
func (chatView *ChatView) addMessageInternal(message *discordgo.Message) {
- var isBlocked bool
- for _, relationship := range chatView.session.State.Relationships {
- if relationship.User.ID == message.Author.ID &&
- relationship.Type == discordgo.RelationTypeBlocked {
- isBlocked = true
- break
- }
- }
+ isBlocked := discordutil.IsBlocked(chatView.session.State, message.Author)
if !config.GetConfig().ShowPlaceholderForBlockedMessages && isBlocked {
return

Create new isBlocked method as util method