client: Handle capabilities better and more on-spec

This commit is contained in:
Daniel Oaks 2016-02-13 21:38:00 +10:00
parent 8ef550106a
commit f9b3f29216
3 changed files with 22 additions and 10 deletions

@ -63,14 +63,12 @@ func (cc *ClientCapabilities) AddCaps(tags ...string) {
// EnableCaps enables the given capabilities.
func (cc *ClientCapabilities) EnableCaps(caps ...string) {
for _, name := range caps {
cc.Enabled[name] = true
}
}
// DisableCaps disbles the given capabilities.
func (cc *ClientCapabilities) DisableCaps(caps ...string) {
for _, name := range caps {
delete(cc.Enabled, name)
if strings.HasPrefix(name, "-") {
name = strings.TrimPrefix(name, "-")
delete(cc.Enabled, name)
} else {
cc.Enabled[name] = true
}
}
}

@ -41,8 +41,6 @@ func capHandler(event string, info eventmgr.InfoMap) {
if subcommand == "ACK" {
sc.Caps.EnableCaps(strings.Split(params[2], " ")...)
} else if subcommand == "NAK" {
sc.Caps.DisableCaps(strings.Split(params[2], " ")...)
} else if subcommand == "LS" {
if len(params) > 3 {
sc.Caps.AddCaps(strings.Split(params[3], " ")...)

@ -281,6 +281,22 @@ func testServerConnection(t *testing.T, reactor Reactor, client *ServerConnectio
sendMessage(conn, nil, "example.com", "CAP", client.Nick, "ACK", "sasl")
sendMessage(conn, nil, "example.com", "CAP", client.Nick, "DEL", "sasl")
_, exists := client.Caps.Avaliable["sasl"]
if exists {
t.Error(
"SASL cap is still available on client after CAP DEL sasl",
)
}
_, exists = client.Caps.Enabled["sasl"]
if exists {
t.Error(
"SASL cap still enabled on client after CAP DEL sasl",
)
}
// shutdown client
reactor.Shutdown(" Get mad! ")