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

Method sendImmediateSubNotifications

server/topic.go:892–954  ·  view source on GitHub ↗

Send immediate presence notification in response to a subscription. Send push notification to the P2P counterpart. In case of a new channel subscription subscribe user to an FCM topic. These notifications are always sent immediately even if background is requested.

(asUid types.Uid, acs *MsgAccessMode, sreg *ClientComMessage, now time.Time)

Source from the content-addressed store, hash-verified

890// In case of a new channel subscription subscribe user to an FCM topic.
891// These notifications are always sent immediately even if background is requested.
892func (t *Topic) sendImmediateSubNotifications(asUid types.Uid, acs *MsgAccessMode, sreg *ClientComMessage, now time.Time) {
893 modeWant, _ := types.ParseAcs([]byte(acs.Want))
894 modeGiven, _ := types.ParseAcs([]byte(acs.Given))
895 mode := modeWant & modeGiven
896
897 asChan := t.isChan && types.IsChannel(sreg.Original)
898
899 if t.cat == types.TopicCatP2P {
900 uid2 := t.p2pOtherUser(asUid)
901 pud2 := t.perUser[uid2]
902 mode2 := pud2.modeGiven & pud2.modeWant
903 if pud2.deleted {
904 mode2 = types.ModeInvalid
905 }
906
907 // Inform the other user that the topic was just created.
908 if sreg.Sub.Created {
909 t.presSingleUserOffline(uid2, mode2, "acs", &presParams{
910 dWant: pud2.modeWant.String(),
911 dGiven: pud2.modeGiven.String(),
912 actor: asUid.UserId(),
913 }, "", false)
914 }
915
916 if sreg.Sub.Newsub {
917 // Notify current user's 'me' topic to accept notifications from user2
918 t.presSingleUserOffline(asUid, mode, "?none+en", nilPresParams, "", false)
919
920 // Initiate exchange of 'online' status with the other user.
921 // We don't know if the current user is online in the 'me' topic,
922 // so sending an '?unkn' status to user2. His 'me' topic
923 // will reply with user2's status and request an actual status from user1.
924 status := "?unkn"
925 if mode2.IsPresencer() {
926 // If user2 should receive notifications, enable it.
927 status += "+en"
928 }
929 t.presSingleUserOffline(uid2, mode2, status, nilPresParams, "", false)
930
931 // Also send a push notification to the other user.
932 sendPush(t.pushForP2PSub(asUid, uid2, pud2.modeWant, pud2.modeGiven, now))
933 }
934 } else if t.cat == types.TopicCatGrp && !asChan && sreg.Sub.Newsub {
935 // For new group subscriptions, notify other group members.
936 sendPush(t.pushForGroupSub(asUid, now))
937 }
938
939 // newsub could be true only for p2p and group topics, no need to check topic category explicitly.
940 if sreg.Sub.Newsub {
941 // Notify creator's other sessions that the subscription (or the entire topic) was created.
942 t.presSingleUserOffline(asUid, mode, "acs",
943 &presParams{
944 dWant: acs.Want,
945 dGiven: acs.Given,
946 actor: asUid.UserId(),
947 },
948 sreg.sess.sid, false)
949

Callers 1

subscriptionReplyMethod · 0.95

Calls 11

p2pOtherUserMethod · 0.95
presSingleUserOfflineMethod · 0.95
pushForP2PSubMethod · 0.95
pushForGroupSubMethod · 0.95
channelSubUnsubMethod · 0.95
ParseAcsFunction · 0.92
IsChannelFunction · 0.92
sendPushFunction · 0.85
UserIdMethod · 0.80
IsPresencerMethod · 0.80
StringMethod · 0.45

Tested by

no test coverage detected