From ca3557d9effa8a619094d2567a702f0c524f0509 Mon Sep 17 00:00:00 2001 From: Simon Ser Date: Fri, 24 Jun 2022 13:41:37 +0200 Subject: [PATCH] upstream: improve server message detection Stop relying on user/host being unset: this is fragile, some servers send messages coming from users without these. --- upstream.go | 48 +++++++++++++++++++++++++----------------------- 1 file changed, 25 insertions(+), 23 deletions(-) diff --git a/upstream.go b/upstream.go index bb68add..2e3bd6b 100644 --- a/upstream.go +++ b/upstream.go @@ -503,36 +503,38 @@ func (uc *upstreamConn) handleMessage(ctx context.Context, msg *irc.Message) err break } - if msg.Prefix.User == "" && msg.Prefix.Host == "" { // server message + if msg.Prefix.Name == uc.serverPrefix.Name || msg.Prefix.Name == "*" || strings.HasPrefix(target, "$") { + // This is a server message uc.produce("", msg, 0) - } else { // regular user message - bufferName := target - if uc.isOurNick(target) { - bufferName = msg.Prefix.Name + break + } + + bufferName := target + if uc.isOurNick(target) { + bufferName = msg.Prefix.Name + } + + self := uc.isOurNick(msg.Prefix.Name) + + ch := uc.network.channels.Get(bufferName) + if ch != nil && msg.Command != "TAGMSG" && !self { + if ch.Detached { + uc.handleDetachedMessage(ctx, ch, msg) } - self := uc.isOurNick(msg.Prefix.Name) - - ch := uc.network.channels.Get(bufferName) - if ch != nil && msg.Command != "TAGMSG" && !self { - if ch.Detached { - uc.handleDetachedMessage(ctx, ch, msg) - } - - highlight := uc.network.isHighlight(msg) - if ch.DetachOn == database.FilterMessage || ch.DetachOn == database.FilterDefault || (ch.DetachOn == database.FilterHighlight && highlight) { - uc.updateChannelAutoDetach(bufferName) - } - if highlight { - uc.network.broadcastWebPush(ctx, msg) - } + highlight := uc.network.isHighlight(msg) + if ch.DetachOn == database.FilterMessage || ch.DetachOn == database.FilterDefault || (ch.DetachOn == database.FilterHighlight && highlight) { + uc.updateChannelAutoDetach(bufferName) } - if ch == nil && uc.isOurNick(target) { + if highlight { uc.network.broadcastWebPush(ctx, msg) } - - uc.produce(bufferName, msg, downstreamID) } + if ch == nil && uc.isOurNick(target) { + uc.network.broadcastWebPush(ctx, msg) + } + + uc.produce(bufferName, msg, downstreamID) case "CAP": var subCmd string if err := parseMessageParams(msg, nil, &subCmd); err != nil {