Add upstream message-tags capability support

This commit is contained in:
delthas 2020-03-23 01:34:34 +01:00 committed by Simon Ser
parent 44d808be8d
commit 27dae3e8ad
No known key found for this signature in database
GPG key ID: 0FDE7BE0E88F5E48

View file

@ -50,6 +50,8 @@ type upstreamConn struct {
channels map[string]*upstreamChannel channels map[string]*upstreamChannel
caps map[string]string caps map[string]string
tagsSupported bool
saslClient sasl.Client saslClient sasl.Client
saslStarted bool saslStarted bool
} }
@ -190,11 +192,25 @@ func (uc *upstreamConn) handleMessage(msg *irc.Message) error {
break // wait to receive all capabilities break // wait to receive all capabilities
} }
requestCaps := make([]string, 0, 16)
for _, c := range []string{"message-tags"} {
if _, ok := uc.caps[c]; ok {
requestCaps = append(requestCaps, c)
}
}
if uc.requestSASL() { if uc.requestSASL() {
requestCaps = append(requestCaps, "sasl")
}
if len(requestCaps) > 0 {
uc.SendMessage(&irc.Message{ uc.SendMessage(&irc.Message{
Command: "CAP", Command: "CAP",
Params: []string{"REQ", "sasl"}, Params: []string{"REQ", strings.Join(requestCaps, " ")},
}) })
}
if uc.requestSASL() {
break // we'll send CAP END after authentication is completed break // we'll send CAP END after authentication is completed
} }
@ -891,6 +907,8 @@ func (uc *upstreamConn) handleMessage(msg *irc.Message) error {
Params: []string{dc.marshalNick(uc, nick), dc.marshalChannel(uc, channel)}, Params: []string{dc.marshalNick(uc, nick), dc.marshalChannel(uc, channel)},
}) })
}) })
case "TAGMSG":
// TODO: relay to downstream connections that accept message-tags
case irc.RPL_YOURHOST, irc.RPL_CREATED: case irc.RPL_YOURHOST, irc.RPL_CREATED:
// Ignore // Ignore
case irc.RPL_LUSERCLIENT, irc.RPL_LUSEROP, irc.RPL_LUSERUNKNOWN, irc.RPL_LUSERCHANNELS, irc.RPL_LUSERME: case irc.RPL_LUSERCLIENT, irc.RPL_LUSEROP, irc.RPL_LUSERUNKNOWN, irc.RPL_LUSERCHANNELS, irc.RPL_LUSERME:
@ -987,6 +1005,8 @@ func (uc *upstreamConn) handleCapAck(name string, ok bool) error {
Command: "AUTHENTICATE", Command: "AUTHENTICATE",
Params: []string{auth.Mechanism}, Params: []string{auth.Mechanism},
}) })
case "message-tags":
uc.tagsSupported = ok
} }
return nil return nil
} }