diff options
author | Joas Schilling <coding@schilljs.com> | 2021-09-20 17:27:20 +0300 |
---|---|---|
committer | Joas Schilling <coding@schilljs.com> | 2021-11-03 15:10:34 +0300 |
commit | 56d466029506be73782490ed779fe402c7b39c8f (patch) | |
tree | bceec7edc1c36ea0efcf5b1f8933a54a1a0511dc /lib | |
parent | cb2f6e2c18eee8263b3d939d776ea63a9f3504a8 (diff) |
Log dedicated call summary when ending for everyone
Signed-off-by: Joas Schilling <coding@schilljs.com>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/Activity/Listener.php | 25 | ||||
-rw-r--r-- | lib/Controller/CallController.php | 7 | ||||
-rw-r--r-- | lib/Events/ModifyRoomEvent.php | 14 | ||||
-rw-r--r-- | lib/Room.php | 2 | ||||
-rw-r--r-- | lib/Service/ParticipantService.php | 15 |
5 files changed, 49 insertions, 14 deletions
diff --git a/lib/Activity/Listener.php b/lib/Activity/Listener.php index 78f62dad1..d38bda37d 100644 --- a/lib/Activity/Listener.php +++ b/lib/Activity/Listener.php @@ -26,6 +26,7 @@ namespace OCA\Talk\Activity; use OCA\Talk\Chat\ChatManager; use OCA\Talk\Events\AddParticipantsEvent; use OCA\Talk\Events\ModifyParticipantEvent; +use OCA\Talk\Events\ModifyRoomEvent; use OCA\Talk\Events\RoomEvent; use OCA\Talk\Model\Attendee; use OCA\Talk\Participant; @@ -80,6 +81,13 @@ class Listener { }; $dispatcher->addListener(Room::EVENT_AFTER_SESSION_JOIN_CALL, $listener); + $listener = static function (ModifyRoomEvent $event): void { + /** @var self $listener */ + $listener = \OC::$server->query(self::class); + $listener->generateCallActivity($event->getRoom(), true, $event->getActor()); + }; + $dispatcher->addListener(Room::EVENT_BEFORE_END_CALL_FOR_EVERYONE, $listener); + $listener = static function (RoomEvent $event): void { /** @var self $listener */ $listener = \OC::$server->query(self::class); @@ -110,11 +118,13 @@ class Listener { * Call activity: "You attended a call with {user1} and {user2}" * * @param Room $room + * @param bool $endForEveryone + * @param Participant|null $actor * @return bool True if activity was generated, false otherwise */ - public function generateCallActivity(Room $room): bool { + public function generateCallActivity(Room $room, bool $endForEveryone = false, ?Participant $actor = null): bool { $activeSince = $room->getActiveSince(); - if (!$activeSince instanceof \DateTime || $this->participantService->hasActiveSessionsInCall($room)) { + if (!$activeSince instanceof \DateTime || (!$endForEveryone && $this->participantService->hasActiveSessionsInCall($room))) { return false; } @@ -130,6 +140,8 @@ class Listener { return false; } $message = 'call_missed'; + } elseif ($endForEveryone) { + $message = 'call_ended_everyone'; } if (!$room->resetActiveSince()) { @@ -137,8 +149,13 @@ class Listener { return false; } - $actorId = $userIds[0] ?? 'guests-only'; - $actorType = $actorId !== 'guests-only' ? Attendee::ACTOR_USERS : Attendee::ACTOR_GUESTS; + if ($actor instanceof Participant) { + $actorId = $actor->getAttendee()->getActorId(); + $actorType = $actor->getAttendee()->getActorType(); + } else { + $actorId = $userIds[0] ?? 'guests-only'; + $actorType = $actorId !== 'guests-only' ? Attendee::ACTOR_USERS : Attendee::ACTOR_GUESTS; + } $this->chatManager->addSystemMessage($room, $actorType, $actorId, json_encode([ 'message' => $message, 'parameters' => [ diff --git a/lib/Controller/CallController.php b/lib/Controller/CallController.php index 0cca8f991..9b4af7ec1 100644 --- a/lib/Controller/CallController.php +++ b/lib/Controller/CallController.php @@ -167,12 +167,7 @@ class CallController extends AEnvironmentAwareController { } if ($all && $this->participant->hasModeratorPermissions()) { - $participants = $this->participantService->getParticipantsInCall($this->room); - - // kick out all participants out of the call - foreach ($participants as $participant) { - $this->participantService->changeInCall($this->room, $participant, Participant::FLAG_DISCONNECTED); - } + $this->participantService->endCallForEveryone($this->room, $this->participant); } else { $this->participantService->changeInCall($this->room, $this->participant, Participant::FLAG_DISCONNECTED); } diff --git a/lib/Events/ModifyRoomEvent.php b/lib/Events/ModifyRoomEvent.php index 7925fdb56..caaca0699 100644 --- a/lib/Events/ModifyRoomEvent.php +++ b/lib/Events/ModifyRoomEvent.php @@ -23,6 +23,7 @@ declare(strict_types=1); namespace OCA\Talk\Events; +use OCA\Talk\Participant; use OCA\Talk\Room; class ModifyRoomEvent extends RoomEvent { @@ -33,21 +34,22 @@ class ModifyRoomEvent extends RoomEvent { protected $newValue; /** @var int|string|bool|null */ protected $oldValue; + /** @var Participant|null */ + protected $actor; public function __construct(Room $room, string $parameter, $newValue, - $oldValue = null) { + $oldValue = null, + ?Participant $actor = null) { parent::__construct($room); $this->parameter = $parameter; $this->newValue = $newValue; $this->oldValue = $oldValue; + $this->actor = $actor; } - /** - * @return string - */ public function getParameter(): string { return $this->parameter; } @@ -65,4 +67,8 @@ class ModifyRoomEvent extends RoomEvent { public function getOldValue() { return $this->oldValue; } + + public function getActor(): ?Participant { + return $this->actor; + } } diff --git a/lib/Room.php b/lib/Room.php index f79d7aabc..f3f03880a 100644 --- a/lib/Room.php +++ b/lib/Room.php @@ -114,6 +114,8 @@ class Room { public const EVENT_AFTER_LISTABLE_SET = self::class . '::postSetListable'; public const EVENT_BEFORE_LOBBY_STATE_SET = self::class . '::preSetLobbyState'; public const EVENT_AFTER_LOBBY_STATE_SET = self::class . '::postSetLobbyState'; + public const EVENT_BEFORE_END_CALL_FOR_EVERYONE = self::class . '::preEndCallForEveryone'; + public const EVENT_AFTER_END_CALL_FOR_EVERYONE = self::class . '::postEndCallForEveryone'; public const EVENT_BEFORE_SIP_ENABLED_SET = self::class . '::preSetSIPEnabled'; public const EVENT_AFTER_SIP_ENABLED_SET = self::class . '::postSetSIPEnabled'; public const EVENT_BEFORE_PERMISSIONS_SET = self::class . '::preSetPermissions'; diff --git a/lib/Service/ParticipantService.php b/lib/Service/ParticipantService.php index 1d83fd3c2..c9f05f32e 100644 --- a/lib/Service/ParticipantService.php +++ b/lib/Service/ParticipantService.php @@ -33,6 +33,7 @@ use OCA\Talk\Events\AttendeesRemovedEvent; use OCA\Talk\Events\JoinRoomGuestEvent; use OCA\Talk\Events\JoinRoomUserEvent; use OCA\Talk\Events\ModifyParticipantEvent; +use OCA\Talk\Events\ModifyRoomEvent; use OCA\Talk\Events\ParticipantEvent; use OCA\Talk\Events\RemoveParticipantEvent; use OCA\Talk\Events\RemoveUserEvent; @@ -906,6 +907,20 @@ class ParticipantService { $this->dispatcher->dispatch(Room::EVENT_AFTER_GUESTS_CLEAN, $event); } + public function endCallForEveryone(Room $room, Participant $moderator): void { + $event = new ModifyRoomEvent($room, 'in_call', Participant::FLAG_DISCONNECTED, null, $moderator); + $this->dispatcher->dispatch(Room::EVENT_BEFORE_END_CALL_FOR_EVERYONE, $event); + + $participants = $this->getParticipantsInCall($room); + + // kick out all participants out of the call + foreach ($participants as $participant) { + $this->changeInCall($room, $participant, Participant::FLAG_DISCONNECTED); + } + + $this->dispatcher->dispatch(Room::EVENT_AFTER_END_CALL_FOR_EVERYONE, $event); + } + public function changeInCall(Room $room, Participant $participant, int $flags): void { $session = $participant->getSession(); if (!$session instanceof Session) { |