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

Method evictUser

server/topic.go:3519–3567  ·  view source on GitHub ↗

evictUser evicts all given user's sessions from the topic and clears user's cached data, if appropriate.

(uid types.Uid, unsub bool, skip string)

Source from the content-addressed store, hash-verified

3517
3518// evictUser evicts all given user's sessions from the topic and clears user's cached data, if appropriate.
3519func (t *Topic) evictUser(uid types.Uid, unsub bool, skip string) {
3520 now := types.TimeNow()
3521 pud, ok := t.perUser[uid]
3522
3523 // Detach user from topic
3524 if unsub {
3525 if t.cat == types.TopicCatP2P {
3526 // P2P: mark user as deleted
3527 pud.online = 0
3528 pud.deleted = true
3529 t.perUser[uid] = pud
3530 } else if ok {
3531 // Grp: delete per-user data
3532 delete(t.perUser, uid)
3533 t.computePerUserAcsUnion()
3534
3535 if !pud.isChan {
3536 usersRegisterUser(uid, false)
3537 }
3538 }
3539 } else if ok {
3540 if pud.isChan {
3541 delete(t.perUser, uid)
3542 // No need to call computePerUserAcsUnion because removal of a channel reader does not change union permissions.
3543 // No need to unregister user as we ignore unread channel messages.
3544 } else {
3545 // Clear online status
3546 pud.online = 0
3547 t.perUser[uid] = pud
3548 }
3549 }
3550
3551 // Detach all user's sessions
3552 msg := NoErrEvicted("", t.original(uid), now)
3553 msg.Ctrl.Params = map[string]any{"unsub": unsub}
3554 msg.SkipSid = skip
3555 msg.uid = uid
3556 msg.AsUser = uid.UserId()
3557 for s := range t.sessions {
3558 if pssd, removed := t.remSession(s, uid); pssd != nil {
3559 if removed {
3560 s.detachSession(t.name)
3561 }
3562 if s.sid != skip {
3563 s.queueOut(msg)
3564 }
3565 }
3566 }
3567}
3568
3569// User's subscription to a topic has changed, send presence notifications.
3570// 1. New subscription

Callers 4

thisUserSubMethod · 0.95
anotherUserSubMethod · 0.95
replyDelSubMethod · 0.95
replyLeaveUnsubMethod · 0.95

Calls 9

originalMethod · 0.95
remSessionMethod · 0.95
TimeNowFunction · 0.92
usersRegisterUserFunction · 0.85
NoErrEvictedFunction · 0.85
UserIdMethod · 0.80
detachSessionMethod · 0.80
queueOutMethod · 0.80

Tested by

no test coverage detected