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 username string
hostname string hostname string
account string // RPL_LOGGEDIN/OUT state account string // RPL_LOGGEDIN/OUT state
away *string
capVersion int capVersion int
caps xirc.CapRegistry 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.logger.Printf("starting %v with account name %v", msg.Command, msg.Params[0])
uc.enqueueCommand(dc, msg) 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": case "MONITOR":
// MONITOR is unsupported in multi-upstream mode // MONITOR is unsupported in multi-upstream mode
uc := dc.upstream() uc := dc.upstream()

View File

@ -2140,8 +2140,10 @@ func (uc *upstreamConn) updateAway() {
ctx := context.TODO() ctx := context.TODO()
away := true away := true
uc.forEachDownstream(func(*downstreamConn) { uc.forEachDownstream(func(dc *downstreamConn) {
if dc.away == nil {
away = false away = false
}
}) })
if away == uc.away { if away == uc.away {
return return