Leave/Unsubscribe a topic
(msg *ClientComMessage)
| 240 | |
| 241 | // Leave/Unsubscribe a topic |
| 242 | func (s *Session) leave(msg *ClientComMessage) { |
| 243 | var reply *ServerComMessage |
| 244 | |
| 245 | if msg.Leave.Topic == "" { |
| 246 | s.QueueOut(ErrMalformed(msg.Leave.Id, "", msg.timestamp)) |
| 247 | return |
| 248 | } |
| 249 | |
| 250 | topic := msg.Leave.Topic |
| 251 | if msg.Leave.Topic == "me" { |
| 252 | topic = s.uid.UserId() |
| 253 | } |
| 254 | |
| 255 | if sub, ok := s.subs[topic]; ok { |
| 256 | if msg.Leave.Topic == "me" && msg.Leave.Unsub { |
| 257 | // User should not unsubscribe from 'me'. Just leaving is fine |
| 258 | reply = ErrPermissionDenied(msg.Leave.Id, msg.Leave.Topic, msg.timestamp) |
| 259 | } else { |
| 260 | // unlink from topic |
| 261 | delete(s.subs, topic) |
| 262 | |
| 263 | sub.done <- &sessionLeave{sess: s, unsub: msg.Leave.Unsub, pkt: msg} |
| 264 | reply = NoErr(msg.Leave.Id, msg.Leave.Topic, msg.timestamp) |
| 265 | } |
| 266 | } else { |
| 267 | // FIXME(gene): allow topic to unsubscribe to unsubscribe without joining first; send to hub to unsub |
| 268 | reply = ErrAttachFirst(msg.Leave.Id, msg.Leave.Topic, msg.timestamp) |
| 269 | } |
| 270 | |
| 271 | s.QueueOut(reply) |
| 272 | } |
| 273 | |
| 274 | // Broadcast a message to all topic subscribers |
| 275 | func (s *Session) publish(msg *ClientComMessage) { |
no test coverage detected