From 2e718e15a6c1f8acb151ea539bb21595c82b25ab Mon Sep 17 00:00:00 2001 From: Noah Petherbridge Date: Sun, 9 Mar 2025 15:52:34 -0700 Subject: [PATCH] Echo: Skip messages sent by blocked usernames --- pkg/echo_messages.go | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/pkg/echo_messages.go b/pkg/echo_messages.go index 436bb30..c518873 100644 --- a/pkg/echo_messages.go +++ b/pkg/echo_messages.go @@ -27,11 +27,27 @@ var ( func (sub *Subscriber) SendEchoedMessages() { var echoes []messages.Message + // Gather the subscriber's block list, so we don't echo users who are on it. + var blocks = map[string]interface{}{} + sub.muteMu.RLock() + for username := range sub.blocked { + blocks[username] = nil + } + for username := range sub.muted { + blocks[username] = nil + } + sub.muteMu.RUnlock() + // Read lock to collect the messages. echoLock.RLock() for _, msgs := range echoMessages { - echoes = append(echoes, msgs...) + for _, msg := range msgs { + if _, ok := blocks[msg.Username]; ok { + continue + } + echoes = append(echoes, msg) + } } // Release the lock.