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

View File

@ -28,6 +28,8 @@ type HubConnection struct {
connValid bool connValid bool
sentOurHello bool sentOurHello bool
autoReconnect bool autoReconnect bool
supports map[string]struct{}
} }
// Thread-safe user accessor. // Thread-safe user accessor.
@ -133,9 +135,8 @@ func (this *HubConnection) processProtocolMessage(message string) {
switch commandParts[0] { switch commandParts[0] {
case "$Lock": case "$Lock":
this.SayRaw("$Supports NoHello NoGetINFO UserCommand UserIP2|" + this.SayRaw("$Supports NoHello NoGetINFO UserCommand UserIP2 QuickList|" +
"$Key " + unlock([]byte(commandParts[1])) + "|" + "$Key " + unlock([]byte(commandParts[1])) + "|")
"$ValidateNick " + Escape(this.Hco.Self.Nick) + "|")
this.sentOurHello = false this.sentOurHello = false
case "$Hello": case "$Hello":
@ -276,8 +277,27 @@ func (this *HubConnection) processProtocolMessage(message string) {
this.processEvent(HubEvent{EventType: EVENT_DEBUG_MESSAGE, Message: "Malformed usercommand '" + commandParts[1] + "'"}) this.processEvent(HubEvent{EventType: EVENT_DEBUG_MESSAGE, Message: "Malformed usercommand '" + commandParts[1] + "'"})
} }
// IGNORABLE COMMANDS
case "$Supports": 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 "$HubTopic":
case "$Search": case "$Search":
case "$ConnectToMe": case "$ConnectToMe":