Aggregate AWAY status from all connected clients

Closes: https://todo.sr.ht/~emersion/soju/200
This commit is contained in:
Simon Ser 2022-07-11 19:36:12 +02:00
parent 9ba03b9095
commit 4e683af535
2 changed files with 27 additions and 2 deletions

View file

@ -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()

View file

@ -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