MCPcopy Index your code
hub / github.com/tinode/chat / handleSubscription

Method handleSubscription

server/topic.go:650–719  ·  view source on GitHub ↗

Session subscribed to a topic, created == true if topic was just created and {pres} needs to be announced

(msg *ClientComMessage)

Source from the content-addressed store, hash-verified

648
649// Session subscribed to a topic, created == true if topic was just created and {pres} needs to be announced
650func (t *Topic) handleSubscription(msg *ClientComMessage) error {
651 asUid := types.ParseUserId(msg.AsUser)
652 authLevel := auth.Level(msg.AuthLvl)
653 asChan, err := t.verifyChannelAccess(msg.Original)
654 if err != nil {
655 // User should not be able to address non-channel topic as channel.
656 msg.sess.queueOut(ErrNotFoundReply(msg, types.TimeNow()))
657 return err
658 }
659
660 if err := t.subscriptionReply(asChan, msg); err != nil {
661 return err
662 }
663
664 msgsub := msg.Sub
665 getWhat := 0
666 if msgsub.Get != nil {
667 getWhat = parseMsgClientMeta(msgsub.Get.What)
668 }
669 if getWhat&constMsgMetaDesc != 0 {
670 // Send get.desc as a {meta} packet.
671 if err := t.replyGetDesc(msg.sess, asUid, asChan, msgsub.Get.Desc, msg); err != nil {
672 logs.Warn.Printf("topic[%s] handleSubscription Get.Desc failed: %v sid=%s", t.name, err, msg.sess.sid)
673 }
674 }
675
676 if getWhat&constMsgMetaSub != 0 {
677 // Send get.sub response as a separate {meta} packet
678 if err := t.replyGetSub(msg.sess, asUid, authLevel, asChan, msg); err != nil {
679 logs.Warn.Printf("topic[%s] handleSubscription Get.Sub failed: %v sid=%s", t.name, err, msg.sess.sid)
680 }
681 }
682
683 if getWhat&constMsgMetaTags != 0 {
684 // Send get.tags response as a separate {meta} packet
685 if err := t.replyGetTags(msg.sess, asUid, msg); err != nil {
686 logs.Warn.Printf("topic[%s] handleSubscription Get.Tags failed: %v sid=%s", t.name, err, msg.sess.sid)
687 }
688 }
689
690 if getWhat&constMsgMetaCred != 0 {
691 // Send get.tags response as a separate {meta} packet
692 if err := t.replyGetCreds(msg.sess, asUid, msg); err != nil {
693 logs.Warn.Printf("topic[%s] handleSubscription Get.Cred failed: %v sid=%s", t.name, err, msg.sess.sid)
694 }
695 }
696
697 if getWhat&constMsgMetaAux != 0 {
698 // Send get.aux response as a separate {meta} packet
699 if err := t.replyGetAux(msg.sess, asUid, msg); err != nil {
700 logs.Warn.Printf("topic[%s] handleSubscription Get.Aux failed: %v sid=%s", t.name, err, msg.sess.sid)
701 }
702 }
703
704 if getWhat&constMsgMetaData != 0 {
705 // Send get.data response as {data} packets
706 if err := t.replyGetData(msg.sess, asUid, asChan, msgsub.Get.Data, msg); err != nil {
707 logs.Warn.Printf("topic[%s] handleSubscription Get.Data failed: %v sid=%s", t.name, err, msg.sess.sid)

Callers 1

registerSessionMethod · 0.95

Calls 15

verifyChannelAccessMethod · 0.95
subscriptionReplyMethod · 0.95
replyGetDescMethod · 0.95
replyGetSubMethod · 0.95
replyGetTagsMethod · 0.95
replyGetCredsMethod · 0.95
replyGetAuxMethod · 0.95
replyGetDataMethod · 0.95
replyGetDelMethod · 0.95
ParseUserIdFunction · 0.92
LevelTypeAlias · 0.92
TimeNowFunction · 0.92

Tested by

no test coverage detected