Auto away

Closes: https://todo.sr.ht/~emersion/soju/13

git-svn-id: file:///srv/svn/repo/suika/trunk@198 f0ae65fe-ee39-954e-97ec-027ff2717ef4
This commit is contained in:
contact 2020-04-01 10:16:32 +00:00
parent fc82577f45
commit b476131682
2 changed files with 34 additions and 1 deletions

View File

@ -54,6 +54,7 @@ type upstreamConn struct {
channels map[string]*upstreamChannel
caps map[string]string
batches map[string]batch
away bool
tagsSupported bool
labelsSupported bool
@ -1269,6 +1270,8 @@ func (uc *upstreamConn) handleMessage(msg *irc.Message) error {
// TODO: relay to downstream connections that accept message-tags
case "ACK":
// Ignore
case irc.RPL_NOWAWAY, irc.RPL_UNAWAY:
// Ignore
case irc.RPL_YOURHOST, irc.RPL_CREATED:
// Ignore
case irc.RPL_LUSERCLIENT, irc.RPL_LUSEROP, irc.RPL_LUSERUNKNOWN, irc.RPL_LUSERCHANNELS, irc.RPL_LUSERME:
@ -1483,3 +1486,24 @@ func (uc *upstreamConn) appendLog(entity string, format string, a ...interface{}
uc.logger.Printf("failed to log message to %q: %v", log.name, err)
}
}
func (uc *upstreamConn) updateAway() {
away := true
uc.forEachDownstream(func(*downstreamConn) {
away = false
})
if away == uc.away {
return
}
if away {
uc.SendMessage(&irc.Message{
Command: "AWAY",
Params: []string{"Auto away"},
})
} else {
uc.SendMessage(&irc.Message{
Command: "AWAY",
})
}
uc.away = away
}

11
user.go
View File

@ -175,7 +175,8 @@ func (u *user) run() {
for e := range u.events {
switch e := e.(type) {
case eventUpstreamConnected:
// Nothing to do
uc := e.uc
uc.updateAway()
case eventUpstreamDisconnected:
uc := e.uc
for _, log := range uc.logs {
@ -200,6 +201,10 @@ func (u *user) run() {
}
u.downstreamConns = append(u.downstreamConns, dc)
u.forEachUpstream(func(uc *upstreamConn) {
uc.updateAway()
})
case eventDownstreamDisconnected:
dc := e.dc
for i := range u.downstreamConns {
@ -208,6 +213,10 @@ func (u *user) run() {
break
}
}
u.forEachUpstream(func(uc *upstreamConn) {
uc.updateAway()
})
case eventDownstreamMessage:
msg, dc := e.msg, e.dc
if dc.isClosed() {