From 8536cb0a5c9e2a39757931163f798899f36f50c3 Mon Sep 17 00:00:00 2001 From: mappu Date: Wed, 8 Feb 2017 19:22:07 +1300 Subject: [PATCH] implement QuickList, save a network roundtrip on supported hubs (ptokax) --- HubConnection.go | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/HubConnection.go b/HubConnection.go index ef77138..f33e920 100644 --- a/HubConnection.go +++ b/HubConnection.go @@ -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":