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)
| 3517 | |
| 3518 | // evictUser evicts all given user's sessions from the topic and clears user's cached data, if appropriate. |
| 3519 | func (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 |
no test coverage detected