This topic got a request from a 'me' topic to start/stop sending presence updates. The originating topic reports its own status in 'what' as "on", "off", "gone" or "?unkn". "on" - requester came online "off" - requester is offline now "?none" - anchor for "+" command: requester status is unkn
(fromUserID, what string, wantReply bool)
| 95 | // "+dis" disable subscription withot removing it, the opposite of "en". |
| 96 | // The "+en/rem/dis" command itself is stripped from the notification. |
| 97 | func (t *Topic) procPresReq(fromUserID, what string, wantReply bool) string { |
| 98 | if t.isInactive() { |
| 99 | return "" |
| 100 | } |
| 101 | |
| 102 | if t.isProxy { |
| 103 | // Passthrough on proxy: there is no point in maintaining peer status |
| 104 | // at the proxy, it's an exact replica of the master. |
| 105 | return what |
| 106 | } |
| 107 | |
| 108 | var reqReply, onlineUpdate bool |
| 109 | |
| 110 | online := &onlineUpdate |
| 111 | replyAs := "on" |
| 112 | |
| 113 | parts := strings.Split(what, "+") |
| 114 | what = parts[0] |
| 115 | cmd := "" |
| 116 | if len(parts) > 1 { |
| 117 | cmd = parts[1] |
| 118 | } |
| 119 | |
| 120 | switch what { |
| 121 | case "on": |
| 122 | // online |
| 123 | *online = true |
| 124 | case "off": |
| 125 | // offline |
| 126 | case "?none": |
| 127 | // no change to online status |
| 128 | online = nil |
| 129 | what = "" |
| 130 | case "gone": |
| 131 | // offline: off+rem |
| 132 | cmd = "rem" |
| 133 | case "?unkn": |
| 134 | // no change in online status |
| 135 | online = nil |
| 136 | reqReply = true |
| 137 | what = "" |
| 138 | default: |
| 139 | // All other notifications are not processed here |
| 140 | return what |
| 141 | } |
| 142 | |
| 143 | if t.cat == types.TopicCatMe { |
| 144 | // Find if the contact is listed. |
| 145 | if psd, ok := t.perSubs[fromUserID]; ok { |
| 146 | if cmd == "rem" { |
| 147 | replyAs = "off+rem" |
| 148 | if !psd.enabled && what == "off" { |
| 149 | // If it was disabled before, don't send a redundant update. |
| 150 | what = "" |
| 151 | } |
| 152 | delete(t.perSubs, fromUserID) |
| 153 | } else { |
| 154 | switch cmd { |
no test coverage detected