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

Method remSession

server/topic.go:3918–3949  ·  view source on GitHub ↗

Disconnects session from topic if either one of the following is true: * 's' is an ordinary session AND ('asUid' is zero OR 'asUid' matches subscribed user). * 's' is a multiplexing session and it's being dropped all together ('asUid' is zero ). If 's' is a multiplexing session and asUid is not zero

(sess *Session, asUid types.Uid)

Source from the content-addressed store, hash-verified

3916// users 'muids'.
3917// Returns perSessionData if it was found and true if session was actually detached from topic.
3918func (t *Topic) remSession(sess *Session, asUid types.Uid) (*perSessionData, bool) {
3919 s := sess
3920 if sess.multi != nil {
3921 s = s.multi
3922 }
3923 pssd, ok := t.sessions[s]
3924 if !ok {
3925 // Session not found at all.
3926 return nil, false
3927 }
3928
3929 if pssd.uid == asUid || asUid.IsZero() {
3930 delete(t.sessions, s)
3931 return &pssd, true
3932 }
3933
3934 for i := range pssd.muids {
3935 if pssd.muids[i] == asUid {
3936 pssd.muids[i] = pssd.muids[len(pssd.muids)-1]
3937 pssd.muids = pssd.muids[:len(pssd.muids)-1]
3938 t.sessions[s] = pssd
3939 if len(pssd.muids) == 0 {
3940 delete(t.sessions, s)
3941 return &pssd, true
3942 }
3943
3944 return &pssd, false
3945 }
3946 }
3947
3948 return nil, false
3949}
3950
3951// Check if topic has any online (non-background) users.
3952func (t *Topic) isOnline() bool {

Callers 5

proxyMasterResponseMethod · 0.95
proxyCtrlBroadcastMethod · 0.95
handleLeaveRequestMethod · 0.95
evictUserMethod · 0.95

Calls 1

IsZeroMethod · 0.45

Tested by

no test coverage detected