Forward user mode changes in single-upstream mode

References: https://todo.sr.ht/~emersion/soju/20
This commit is contained in:
Gregory Anders 2021-06-09 13:58:27 -06:00 committed by Simon Ser
parent 2fe0a57e43
commit 0e9ef1f97c
2 changed files with 41 additions and 13 deletions

View File

@ -1102,6 +1102,13 @@ func (dc *downstreamConn) welcome() error {
for _, msg := range generateIsupport(dc.srv.prefix(), dc.nick, isupport) { for _, msg := range generateIsupport(dc.srv.prefix(), dc.nick, isupport) {
dc.SendMessage(msg) dc.SendMessage(msg)
} }
if uc := dc.upstream(); uc != nil {
dc.SendMessage(&irc.Message{
Prefix: dc.srv.prefix(),
Command: irc.RPL_UMODEIS,
Params: []string{dc.nick, string(uc.modes)},
})
}
dc.SendMessage(&irc.Message{ dc.SendMessage(&irc.Message{
Prefix: dc.srv.prefix(), Prefix: dc.srv.prefix(),
Command: irc.ERR_NOMOTD, Command: irc.ERR_NOMOTD,
@ -1601,11 +1608,15 @@ func (dc *downstreamConn) handleMessageRegistered(msg *irc.Message) error {
}) })
}) })
} else { } else {
// TODO: only do this in multi-upstream mode var userMode string
if uc := dc.upstream(); uc != nil {
userMode = string(uc.modes)
}
dc.SendMessage(&irc.Message{ dc.SendMessage(&irc.Message{
Prefix: dc.srv.prefix(), Prefix: dc.srv.prefix(),
Command: irc.RPL_UMODEIS, Command: irc.RPL_UMODEIS,
Params: []string{dc.nick, ""}, // TODO Params: []string{dc.nick, userMode},
}) })
} }
return nil return nil

View File

@ -932,8 +932,18 @@ func (uc *upstreamConn) handleMessage(msg *irc.Message) error {
if name != uc.nick { if name != uc.nick {
return fmt.Errorf("received MODE message for unknown nick %q", name) return fmt.Errorf("received MODE message for unknown nick %q", name)
} }
return uc.modes.Apply(modeStr)
// TODO: notify downstreams about user mode change? if err := uc.modes.Apply(modeStr); err != nil {
return err
}
uc.forEachDownstream(func(dc *downstreamConn) {
if dc.upstream() == nil {
return
}
dc.SendMessage(msg)
})
} else { // channel mode change } else { // channel mode change
ch, err := uc.getChannel(name) ch, err := uc.getChannel(name)
if err != nil { if err != nil {
@ -982,7 +992,14 @@ func (uc *upstreamConn) handleMessage(msg *irc.Message) error {
if err := uc.modes.Apply(modeStr); err != nil { if err := uc.modes.Apply(modeStr); err != nil {
return err return err
} }
// TODO: send RPL_UMODEIS to downstream connections when applicable
uc.forEachDownstream(func(dc *downstreamConn) {
if dc.upstream() == nil {
return
}
dc.SendMessage(msg)
})
case irc.RPL_CHANNELMODEIS: case irc.RPL_CHANNELMODEIS:
var channel string var channel string
if err := parseMessageParams(msg, nil, &channel); err != nil { if err := parseMessageParams(msg, nil, &channel); err != nil {