User's subscription to a topic has changed, send presence notifications. 1. New subscription 2. Deleted subscription 3. Permissions changed Sending to (a) Topic admins online on topic itself. (b) Topic admins offline on 'me' if approval is needed. (c) If subscription is deleted, 'gone' to target. (d
(uid, actor types.Uid, isChan bool, oldWant, oldGiven, newWant, newGiven types.AccessMode, skip string)
| 3577 | // (d) 'off' to topic members online if deleted or muted. |
| 3578 | // (e) To target user. |
| 3579 | func (t *Topic) notifySubChange(uid, actor types.Uid, isChan bool, |
| 3580 | oldWant, oldGiven, newWant, newGiven types.AccessMode, skip string) { |
| 3581 | |
| 3582 | unsub := newWant == types.ModeUnset || newGiven == types.ModeUnset |
| 3583 | |
| 3584 | target := uid.UserId() |
| 3585 | |
| 3586 | dWant := types.ModeNone.String() |
| 3587 | if newWant.IsDefined() { |
| 3588 | if oldWant.IsDefined() && !oldWant.IsZero() { |
| 3589 | dWant = oldWant.Delta(newWant) |
| 3590 | } else { |
| 3591 | dWant = newWant.String() |
| 3592 | } |
| 3593 | } |
| 3594 | |
| 3595 | dGiven := types.ModeNone.String() |
| 3596 | if newGiven.IsDefined() { |
| 3597 | if oldGiven.IsDefined() && !oldGiven.IsZero() { |
| 3598 | dGiven = oldGiven.Delta(newGiven) |
| 3599 | } else { |
| 3600 | dGiven = newGiven.String() |
| 3601 | } |
| 3602 | } |
| 3603 | params := &presParams{ |
| 3604 | target: target, |
| 3605 | actor: actor.UserId(), |
| 3606 | dWant: dWant, |
| 3607 | dGiven: dGiven, |
| 3608 | } |
| 3609 | |
| 3610 | filterSharers := &presFilters{ |
| 3611 | filterIn: types.ModeCSharer, |
| 3612 | excludeUser: target, |
| 3613 | } |
| 3614 | |
| 3615 | // Announce the change in permissions to the admins who are online in the topic, exclude the target |
| 3616 | // and exclude the actor's session. |
| 3617 | t.presSubsOnline("acs", target, params, filterSharers, skip) |
| 3618 | |
| 3619 | // If it's a new subscription or if the user asked for permissions in excess of what was granted, |
| 3620 | // announce the request to topic admins on 'me' so they can approve the request. The notification |
| 3621 | // is not sent to the target user or the actor's session. |
| 3622 | if newWant.BetterThan(newGiven) || oldWant == types.ModeNone { |
| 3623 | t.presSubsOffline("acs", params, filterSharers, filterSharers, skip, true) |
| 3624 | } |
| 3625 | |
| 3626 | // Handling of muting/unmuting. |
| 3627 | // Case A: subscription deleted. |
| 3628 | // Case B: subscription muted only. |
| 3629 | if unsub { |
| 3630 | // Subscription deleted. |
| 3631 | |
| 3632 | // In case of a P2P topic subscribe/unsubscribe users from each other's notifications. |
| 3633 | if t.cat == types.TopicCatP2P { |
| 3634 | uid2 := t.p2pOtherUser(uid) |
| 3635 | // Remove user1's subscription to user2 and notify user1's other sessions that he is gone. |
| 3636 | t.presSingleUserOffline(uid, newWant&newGiven, "gone", nilPresParams, skip, false) |
no test coverage detected