From 4e683af535c0778332aa96d327572fcba02aabad Mon Sep 17 00:00:00 2001 From: Simon Ser Date: Mon, 11 Jul 2022 19:36:12 +0200 Subject: [PATCH] Aggregate AWAY status from all connected clients Closes: https://todo.sr.ht/~emersion/soju/200 --- downstream.go | 23 +++++++++++++++++++++++ upstream.go | 6 ++++-- 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/downstream.go b/downstream.go index e93b9ae..dac7ca0 100644 --- a/downstream.go +++ b/downstream.go @@ -330,6 +330,7 @@ type downstreamConn struct { username string hostname string account string // RPL_LOGGEDIN/OUT state + away *string capVersion int caps xirc.CapRegistry @@ -2666,6 +2667,28 @@ func (dc *downstreamConn) handleMessageRegistered(ctx context.Context, msg *irc. uc.logger.Printf("starting %v with account name %v", msg.Command, msg.Params[0]) uc.enqueueCommand(dc, msg) + case "AWAY": + if len(msg.Params) > 0 { + dc.away = &msg.Params[0] + } else { + dc.away = nil + } + + cmd := irc.RPL_NOWAWAY + desc := "You have been marked as being away" + if dc.away == nil { + cmd = irc.RPL_UNAWAY + desc = "You are no longer marked as being away" + } + dc.SendMessage(&irc.Message{ + Command: cmd, + Params: []string{dc.nick, desc}, + }) + + uc := dc.upstream() + if uc != nil { + uc.updateAway() + } case "MONITOR": // MONITOR is unsupported in multi-upstream mode uc := dc.upstream() diff --git a/upstream.go b/upstream.go index e0a61de..01f625b 100644 --- a/upstream.go +++ b/upstream.go @@ -2140,8 +2140,10 @@ func (uc *upstreamConn) updateAway() { ctx := context.TODO() away := true - uc.forEachDownstream(func(*downstreamConn) { - away = false + uc.forEachDownstream(func(dc *downstreamConn) { + if dc.away == nil { + away = false + } }) if away == uc.away { return