Leave/Unsubscribe a topic
(msg *ClientComMessage)
| 648 | |
| 649 | // Leave/Unsubscribe a topic |
| 650 | func (s *Session) leave(msg *ClientComMessage) { |
| 651 | // Expand topic name |
| 652 | var resp *ServerComMessage |
| 653 | msg.RcptTo, resp = s.expandTopicName(msg) |
| 654 | if resp != nil { |
| 655 | s.queueOut(resp) |
| 656 | return |
| 657 | } |
| 658 | |
| 659 | s.inflightReqs.Add(1) |
| 660 | if sub := s.getSub(msg.RcptTo); sub != nil { |
| 661 | // Session is attached to the topic. |
| 662 | if (msg.Original == "me" || msg.Original == "fnd") && msg.Leave.Unsub { |
| 663 | // User should not unsubscribe from 'me' or 'find'. Just leaving is fine. |
| 664 | s.queueOut(ErrPermissionDeniedReply(msg, msg.Timestamp)) |
| 665 | s.inflightReqs.Done() |
| 666 | } else { |
| 667 | // Unlink from topic, topic will send a reply. |
| 668 | sub.done <- msg |
| 669 | } |
| 670 | return |
| 671 | } |
| 672 | s.inflightReqs.Done() |
| 673 | if !msg.Leave.Unsub { |
| 674 | // Session is not attached to the topic, wants to leave - fine, no change |
| 675 | s.queueOut(InfoNotJoined(msg.Id, msg.Original, msg.Timestamp)) |
| 676 | } else { |
| 677 | // Session wants to unsubscribe from the topic it did not join |
| 678 | // TODO(gene): allow topic to unsubscribe without joining first; send to hub to unsub |
| 679 | logs.Warn.Println("s.leave:", "must attach first", s.sid) |
| 680 | s.queueOut(ErrAttachFirst(msg, msg.Timestamp)) |
| 681 | } |
| 682 | } |
| 683 | |
| 684 | // Broadcast a message to all topic subscribers |
| 685 | func (s *Session) publish(msg *ClientComMessage) { |
nothing calls this directly
no test coverage detected