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

Method addSession

server/topic.go:3883–3910  ·  view source on GitHub ↗

Add session record. 'user' may be different from sess.uid.

(sess *Session, asUid types.Uid, isChanSub bool)

Source from the content-addressed store, hash-verified

3881
3882// Add session record. 'user' may be different from sess.uid.
3883func (t *Topic) addSession(sess *Session, asUid types.Uid, isChanSub bool) {
3884 s := sess
3885 if sess.multi != nil {
3886 s = s.multi
3887 }
3888
3889 if pssd, ok := t.sessions[s]; ok {
3890 // Subscription already exists.
3891 if s.isMultiplex() && !sess.background {
3892 // This slice is expected to be relatively short.
3893 // Not doing anything fancy here like maps or sorting.
3894 pssd.muids = append(pssd.muids, asUid)
3895 t.sessions[s] = pssd
3896 }
3897 // Maybe panic here.
3898 return
3899 }
3900
3901 if s.isMultiplex() {
3902 if sess.background {
3903 t.sessions[s] = perSessionData{}
3904 } else {
3905 t.sessions[s] = perSessionData{muids: []types.Uid{asUid}, isChanSub: isChanSub}
3906 }
3907 } else {
3908 t.sessions[s] = perSessionData{uid: asUid, isChanSub: isChanSub}
3909 }
3910}
3911
3912// Disconnects session from topic if either one of the following is true:
3913// * 's' is an ordinary session AND ('asUid' is zero OR 'asUid' matches subscribed user).

Callers 2

proxyMasterResponseMethod · 0.95
subscriptionReplyMethod · 0.95

Calls 1

isMultiplexMethod · 0.80

Tested by

no test coverage detected