3
0
mirror of https://github.com/ergochat/ergo.git synced 2024-11-10 22:19:31 +01:00

Merge pull request #464 from oragono/fix-cap-notify

Fix cap-notify
This commit is contained in:
Shivaram Lingamneni 2019-04-28 02:01:21 -04:00 committed by GitHub
commit 8c68b9f8d7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 24 additions and 3 deletions

View File

@ -207,6 +207,23 @@ func (clients *ClientManager) AllWithCaps(capabs ...caps.Capability) (sessions [
return
}
// AllWithCapsNotify returns all clients with the given capabilities, and that support cap-notify.
func (clients *ClientManager) AllWithCapsNotify(capabs ...caps.Capability) (sessions []*Session) {
capabs = append(capabs, caps.CapNotify)
clients.RLock()
defer clients.RUnlock()
for _, client := range clients.byNick {
for _, session := range client.Sessions() {
// cap-notify is implicit in cap version 302 and above
if session.capabilities.HasAll(capabs...) || 302 <= session.capVersion {
sessions = append(sessions, session)
}
}
}
return
}
// FindAll returns all clients that match the given userhost mask.
func (clients *ClientManager) FindAll(userhost string) (set ClientSet) {
set = make(ClientSet)

View File

@ -535,8 +535,12 @@ func capHandler(server *Server, client *Client, msg ircmsg.IrcMessage, rb *Respo
if !client.registered {
rb.session.capState = caps.NegotiatingState
}
if len(msg.Params) > 1 && msg.Params[1] == "302" {
rb.session.capVersion = 302
if 1 < len(msg.Params) {
num, err := strconv.Atoi(msg.Params[1])
newVersion := caps.Version(num)
if err == nil && rb.session.capVersion < newVersion {
rb.session.capVersion = newVersion
}
}
// weechat 1.4 has a bug here where it won't accept the CAP reply unless it contains
// the server.name source... otherwise it doesn't respond to the CAP message with

View File

@ -744,7 +744,7 @@ func (server *Server) applyConfig(config *Config, initial bool) (err error) {
removedCaps.Union(updatedCaps)
if !addedCaps.Empty() || !removedCaps.Empty() {
capBurstSessions = server.clients.AllWithCaps(caps.CapNotify)
capBurstSessions = server.clients.AllWithCapsNotify()
added[caps.Cap301] = addedCaps.String(caps.Cap301, CapValues)
added[caps.Cap302] = addedCaps.String(caps.Cap302, CapValues)