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

Method sendSubNotifications

server/topic.go:958–995  ·  view source on GitHub ↗

Send immediate or deferred presence notification in response to a subscription. Not used by channels.

(asUid types.Uid, sid, userAgent string)

Source from the content-addressed store, hash-verified

956// Send immediate or deferred presence notification in response to a subscription.
957// Not used by channels.
958func (t *Topic) sendSubNotifications(asUid types.Uid, sid, userAgent string) {
959 switch t.cat {
960 case types.TopicCatMe:
961 // Notify user's contact that the given user is online now.
962 if !t.isLoaded() {
963 t.markLoaded()
964 if err := t.loadContacts(asUid); err != nil {
965 logs.Err.Println("topic: failed to load contacts", t.name, err.Error())
966 }
967 // User online: notify users of interest without forcing response (no +en here).
968 t.presUsersOfInterest("on", userAgent)
969 }
970
971 case types.TopicCatGrp:
972 pud := t.perUser[asUid]
973 if pud.isChan {
974 // Not sendng notifications for channel readers.
975 return
976 }
977
978 // Enable notifications for a new group topic, if appropriate.
979 if !t.isLoaded() {
980 t.markLoaded()
981 status := "on"
982 if (pud.modeGiven & pud.modeWant).IsPresencer() {
983 status += "+en"
984 }
985
986 // Notify topic subscribers that the topic is online now.
987 t.presSubsOffline(status, nilPresParams, nilPresFilters, nilPresFilters, "", false)
988 } else if pud.online == 1 {
989 // If this is the first session of the user in the topic.
990 // Notify other online group members that the user is online now.
991 t.presSubsOnline("on", asUid.UserId(), nilPresParams,
992 &presFilters{filterIn: types.ModeRead}, sid)
993 }
994 }
995}
996
997// Saves a new message (defined by head, content and attachments) in the topic
998// in response to a client request (msg, asUid) and broadcasts it to the attached sessions.

Callers 2

sessToForegroundMethod · 0.95
subscriptionReplyMethod · 0.95

Calls 10

isLoadedMethod · 0.95
markLoadedMethod · 0.95
loadContactsMethod · 0.95
presUsersOfInterestMethod · 0.95
presSubsOfflineMethod · 0.95
presSubsOnlineMethod · 0.95
PrintlnMethod · 0.80
ErrorMethod · 0.80
IsPresencerMethod · 0.80
UserIdMethod · 0.80

Tested by

no test coverage detected