implement QuickList, save a network roundtrip on supported hubs (ptokax)

This commit is contained in:
mappu 2017-02-08 19:22:07 +13:00
parent 553ec20850
commit 8536cb0a5c
1 changed files with 24 additions and 4 deletions

View File

@ -28,6 +28,8 @@ type HubConnection struct {
connValid bool
sentOurHello bool
autoReconnect bool
supports map[string]struct{}
}
// Thread-safe user accessor.
@ -133,9 +135,8 @@ func (this *HubConnection) processProtocolMessage(message string) {
switch commandParts[0] {
case "$Lock":
this.SayRaw("$Supports NoHello NoGetINFO UserCommand UserIP2|" +
"$Key " + unlock([]byte(commandParts[1])) + "|" +
"$ValidateNick " + Escape(this.Hco.Self.Nick) + "|")
this.SayRaw("$Supports NoHello NoGetINFO UserCommand UserIP2 QuickList|" +
"$Key " + unlock([]byte(commandParts[1])) + "|")
this.sentOurHello = false
case "$Hello":
@ -276,8 +277,27 @@ func (this *HubConnection) processProtocolMessage(message string) {
this.processEvent(HubEvent{EventType: EVENT_DEBUG_MESSAGE, Message: "Malformed usercommand '" + commandParts[1] + "'"})
}
// IGNORABLE COMMANDS
case "$Supports":
this.supports = make(map[string]struct{})
for _, s := range strings.Split(commandParts[1], " ") {
this.supports[s] = struct{}{}
}
if !this.sentOurHello {
// Need to log in.
// If the hub supports QuickList, we can skip one network roundtrip
if _, ok := this.supports["QuickList"]; ok {
this.SayInfo()
this.SayRaw("$GetNickList|")
this.sentOurHello = true
} else {
this.SayRaw("$ValidateNick " + Escape(this.Hco.Self.Nick) + "|")
}
}
// IGNORABLE COMMANDS
case "$HubTopic":
case "$Search":
case "$ConnectToMe":