MCPcopy
hub / github.com/tinode/chat / leave

Method leave

server/session.go:650–682  ·  view source on GitHub ↗

Leave/Unsubscribe a topic

(msg *ClientComMessage)

Source from the content-addressed store, hash-verified

648
649// Leave/Unsubscribe a topic
650func (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
685func (s *Session) publish(msg *ClientComMessage) {

Callers

nothing calls this directly

Calls 9

expandTopicNameMethod · 0.95
queueOutMethod · 0.95
getSubMethod · 0.95
ErrPermissionDeniedReplyFunction · 0.85
InfoNotJoinedFunction · 0.85
ErrAttachFirstFunction · 0.85
DoneMethod · 0.80
PrintlnMethod · 0.80
AddMethod · 0.45

Tested by

no test coverage detected