Skip to content

Commit 8fe96ac

Browse files
Merge pull request #7625 from nextcloud/bugfix/server-33314/respect-dnd-and-invisible-when-joining-a-call
Keep DND and Invisible when automatically setting status to "In a call"
2 parents 7876b57 + afec3b2 commit 8fe96ac

File tree

1 file changed

+33
-6
lines changed

1 file changed

+33
-6
lines changed

lib/Status/Listener.php

Lines changed: 33 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,35 +46,62 @@ public function __construct(IManager $statusManager) {
4646
public static function register(IEventDispatcher $dispatcher): void {
4747
$dispatcher->addListener(Room::EVENT_BEFORE_SESSION_JOIN_CALL, [self::class, 'setUserStatus']);
4848

49-
$dispatcher->addListener(Room::EVENT_AFTER_SESSION_LEAVE_CALL, [self::class, 'revertUserStatus']);
49+
$dispatcher->addListener(Room::EVENT_AFTER_SESSION_LEAVE_CALL, [self::class, 'revertUserStatusOnLeaveCall']);
5050

5151
$dispatcher->addListener(Room::EVENT_AFTER_END_CALL_FOR_EVERYONE, [self::class, 'revertUserStatusOnEndCallForEveryone']);
5252
}
5353

5454
public static function setUserStatus(ModifyParticipantEvent $event): void {
55-
$listener = Server::get(self::class);
5655
if ($event->getParticipant()->getAttendee()->getActorType() === Attendee::ACTOR_USERS) {
57-
$listener->statusManager->setUserStatus($event->getParticipant()->getAttendee()->getActorId(), 'call', IUserStatus::AWAY, true);
56+
$status = IUserStatus::AWAY;
57+
58+
$userId = $event->getParticipant()->getAttendee()->getActorId();
59+
60+
/** @var self $listener */
61+
$listener = Server::get(self::class);
62+
$statuses = $listener->statusManager->getUserStatuses([$userId]);
63+
64+
if (isset($statuses[$userId])) {
65+
if ($statuses[$userId]->getStatus() === IUserStatus::INVISIBLE) {
66+
// If the user is invisible we do not overwrite the status
67+
// with "in a call" which would be visible to any user on the
68+
// instance opposed to users in the conversation the call is happening
69+
return;
70+
}
71+
72+
if ($statuses[$userId]->getStatus() === IUserStatus::DND) {
73+
$status = IUserStatus::DND;
74+
}
75+
}
76+
77+
$listener->statusManager->setUserStatus(
78+
$userId,
79+
'call',
80+
$status,
81+
true
82+
);
5883
}
5984
}
6085

61-
public static function revertUserStatus(ModifyParticipantEvent $event): void {
62-
$listener = Server::get(self::class);
86+
public static function revertUserStatusOnLeaveCall(ModifyParticipantEvent $event): void {
6387
if ($event instanceof ModifyEveryoneEvent) {
6488
// Do not revert the status with 3 queries per user.
6589
// We will update it in one go at the end.
6690
return;
6791
}
6892

6993
if ($event->getParticipant()->getAttendee()->getActorType() === Attendee::ACTOR_USERS) {
94+
/** @var self $listener */
95+
$listener = Server::get(self::class);
7096
$listener->statusManager->revertUserStatus($event->getParticipant()->getAttendee()->getActorId(), 'call', IUserStatus::AWAY);
7197
}
7298
}
7399

74100
public static function revertUserStatusOnEndCallForEveryone(EndCallForEveryoneEvent $event): void {
75-
$listener = Server::get(self::class);
76101
$userIds = $event->getUserIds();
77102
if (!empty($userIds)) {
103+
/** @var self $listener */
104+
$listener = Server::get(self::class);
78105
$listener->statusManager->revertMultipleUserStatus($userIds, 'call', IUserStatus::AWAY);
79106
}
80107
}

0 commit comments

Comments
 (0)