Skip to content

Commit

Permalink
fix(API): Move away from deprecated constants
Browse files Browse the repository at this point in the history
Signed-off-by: Joas Schilling <coding@schilljs.com>
  • Loading branch information
nickvergessen committed Nov 22, 2023
1 parent b0faa1f commit 4813069
Show file tree
Hide file tree
Showing 11 changed files with 36 additions and 21 deletions.
3 changes: 2 additions & 1 deletion lib/Command/Room/TRoomCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
namespace OCA\Talk\Command\Room;

use InvalidArgumentException;
use OCA\Talk\Events\AAttendeeRemovedEvent;
use OCA\Talk\Exceptions\ParticipantNotFoundException;
use OCA\Talk\Exceptions\RoomNotFoundException;
use OCA\Talk\Manager;
Expand Down Expand Up @@ -298,7 +299,7 @@ protected function removeRoomParticipants(Room $room, array $userIds): void {
}

foreach ($users as $user) {
$this->participantService->removeUser($room, $user, Room::PARTICIPANT_REMOVED);
$this->participantService->removeUser($room, $user, AAttendeeRemovedEvent::REASON_REMOVED);
}
}

Expand Down
3 changes: 2 additions & 1 deletion lib/Command/User/TransferOwnership.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
namespace OCA\Talk\Command\User;

use OC\Core\Command\Base;
use OCA\Talk\Events\AAttendeeRemovedEvent;
use OCA\Talk\Exceptions\ParticipantNotFoundException;
use OCA\Talk\Manager;
use OCA\Talk\Model\Attendee;
Expand Down Expand Up @@ -136,7 +137,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
}

if ($removeSourceUser) {
$this->participantService->removeAttendee($room, $sourceParticipant, Room::PARTICIPANT_REMOVED);
$this->participantService->removeAttendee($room, $sourceParticipant, AAttendeeRemovedEvent::REASON_REMOVED);
}
}

Expand Down
5 changes: 3 additions & 2 deletions lib/Controller/RoomController.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@

use InvalidArgumentException;
use OCA\Talk\Config;
use OCA\Talk\Events\AAttendeeRemovedEvent;
use OCA\Talk\Events\BeforeRoomsFetchEvent;
use OCA\Talk\Events\UserEvent;
use OCA\Talk\Exceptions\CannotReachRemoteException;
Expand Down Expand Up @@ -1253,7 +1254,7 @@ protected function removeSelfFromRoomLogic(Room $room, Participant $participant)
return new DataResponse([], Http::STATUS_NOT_FOUND);
}

$this->participantService->removeUser($room, $currentUser, Room::PARTICIPANT_LEFT);
$this->participantService->removeUser($room, $currentUser, AAttendeeRemovedEvent::REASON_LEFT);

return new DataResponse();
}
Expand Down Expand Up @@ -1296,7 +1297,7 @@ public function removeAttendeeFromRoom(int $attendeeId): DataResponse {
return new DataResponse([], Http::STATUS_FORBIDDEN);
}

$this->participantService->removeAttendee($this->room, $targetParticipant, Room::PARTICIPANT_REMOVED);
$this->participantService->removeAttendee($this->room, $targetParticipant, AAttendeeRemovedEvent::REASON_REMOVED);
return new DataResponse([]);
}

Expand Down
3 changes: 2 additions & 1 deletion lib/Controller/SignalingController.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@

use GuzzleHttp\Exception\ConnectException;
use OCA\Talk\Config;
use OCA\Talk\Events\AAttendeeRemovedEvent;
use OCA\Talk\Events\BeforeSignalingResponseSentEvent;
use OCA\Talk\Events\SignalingEvent;
use OCA\Talk\Exceptions\ParticipantNotFoundException;
Expand Down Expand Up @@ -769,7 +770,7 @@ private function backendRoom(array $roomRequest): DataResponse {
// Emails are retained as their PIN needs to remain and stay
// valid.
if ($participant->getAttendee()->getActorType() === Attendee::ACTOR_GUESTS) {
$this->participantService->removeAttendee($room, $participant, Room::PARTICIPANT_LEFT);
$this->participantService->removeAttendee($room, $participant, AAttendeeRemovedEvent::REASON_LEFT);
} else {
$this->participantService->leaveRoomAsSession($room, $participant);
}
Expand Down
3 changes: 2 additions & 1 deletion lib/Listener/AMembershipListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

use OCA\Circles\CirclesManager;
use OCA\Circles\Model\Member;
use OCA\Talk\Events\AAttendeeRemovedEvent;
use OCA\Talk\Exceptions\ParticipantNotFoundException;
use OCA\Talk\Manager;
use OCA\Talk\Model\Attendee;
Expand Down Expand Up @@ -61,7 +62,7 @@ protected function removeFromRoomsUnlessStillLinked(array $rooms, IUser $user):
$participant = $room->getParticipant($user->getUID());
$participantType = $participant->getAttendee()->getParticipantType();
if ($participantType === Participant::USER) {
$this->participantService->removeUser($room, $user, Room::PARTICIPANT_REMOVED);
$this->participantService->removeUser($room, $user, AAttendeeRemovedEvent::REASON_REMOVED);
}
} catch (ParticipantNotFoundException $e) {
}
Expand Down
4 changes: 2 additions & 2 deletions lib/Listener/CircleDeletedListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@
namespace OCA\Talk\Listener;

use OCA\Circles\Events\CircleDestroyedEvent;
use OCA\Talk\Events\AAttendeeRemovedEvent;
use OCA\Talk\Manager;
use OCA\Talk\Model\Attendee;
use OCA\Talk\Room;
use OCA\Talk\Service\ParticipantService;
use OCP\EventDispatcher\Event;
use OCP\EventDispatcher\IEventListener;
Expand Down Expand Up @@ -54,7 +54,7 @@ public function handle(Event $event): void {
$rooms = $this->manager->getRoomsForActor(Attendee::ACTOR_CIRCLES, $circleId);
foreach ($rooms as $room) {
$participant = $this->participantService->getParticipantByActor($room, Attendee::ACTOR_CIRCLES, $circleId);
$this->participantService->removeAttendee($room, $participant, Room::PARTICIPANT_REMOVED);
$this->participantService->removeAttendee($room, $participant, AAttendeeRemovedEvent::REASON_REMOVED);
}
}
}
4 changes: 2 additions & 2 deletions lib/Listener/GroupDeletedListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@

namespace OCA\Talk\Listener;

use OCA\Talk\Events\AAttendeeRemovedEvent;
use OCA\Talk\Manager;
use OCA\Talk\Model\Attendee;
use OCA\Talk\Room;
use OCA\Talk\Service\ParticipantService;
use OCP\EventDispatcher\Event;
use OCP\EventDispatcher\IEventListener;
Expand Down Expand Up @@ -60,7 +60,7 @@ public function handle(Event $event): void {
$rooms = $this->manager->getRoomsForActor(Attendee::ACTOR_GROUPS, $gid);
foreach ($rooms as $room) {
$participant = $this->participantService->getParticipantByActor($room, Attendee::ACTOR_GROUPS, $gid);
$this->participantService->removeAttendee($room, $participant, Room::PARTICIPANT_REMOVED);
$this->participantService->removeAttendee($room, $participant, AAttendeeRemovedEvent::REASON_REMOVED);
}
}

Expand Down
3 changes: 2 additions & 1 deletion lib/Manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
namespace OCA\Talk;

use OCA\Talk\Chat\CommentsManager;
use OCA\Talk\Events\AAttendeeRemovedEvent;
use OCA\Talk\Events\RoomCreatedEvent;
use OCA\Talk\Events\RoomEvent;
use OCA\Talk\Exceptions\ParticipantNotFoundException;
Expand Down Expand Up @@ -416,7 +417,7 @@ public function removeUserFromAllRooms(IUser $user, bool $privateOnly = false):
if ($this->participantService->getNumberOfUsers($room) === 1) {
Server::get(RoomService::class)->deleteRoom($room);
} else {
$this->participantService->removeUser($room, $user, Room::PARTICIPANT_REMOVED_ALL);
$this->participantService->removeUser($room, $user, AAttendeeRemovedEvent::REASON_REMOVED_ALL);
}
}

Expand Down
3 changes: 2 additions & 1 deletion lib/MatterbridgeManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
use OC\Authentication\Token\IProvider as IAuthTokenProvider;
use OC\Authentication\Token\IToken;
use OCA\Talk\Chat\ChatManager;
use OCA\Talk\Events\AAttendeeRemovedEvent;
use OCA\Talk\Exceptions\ImpossibleToKillException;
use OCA\Talk\Exceptions\ParticipantNotFoundException;
use OCA\Talk\Exceptions\RoomNotFoundException;
Expand Down Expand Up @@ -278,7 +279,7 @@ private function checkBotUser(Room $room, bool $isBridgeEnabled): array {
try {
$this->participantService->getParticipant($room, self::BRIDGE_BOT_USERID, false);
if (!$isBridgeEnabled) {
$this->participantService->removeUser($room, $botUser, Room::PARTICIPANT_REMOVED);
$this->participantService->removeUser($room, $botUser, AAttendeeRemovedEvent::REASON_REMOVED);
}
} catch (ParticipantNotFoundException $e) {
if ($isBridgeEnabled) {
Expand Down
7 changes: 4 additions & 3 deletions lib/Service/BreakoutRoomService.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
use InvalidArgumentException;
use OCA\Talk\Chat\ChatManager;
use OCA\Talk\Config;
use OCA\Talk\Events\AAttendeeRemovedEvent;
use OCA\Talk\Exceptions\ParticipantNotFoundException;
use OCA\Talk\Manager;
use OCA\Talk\Model\Attendee;
Expand Down Expand Up @@ -238,7 +239,7 @@ public function applyAttendeeMap(Room $parent, string $attendeeMap): array {
}

foreach ($removals as $removal) {
$this->participantService->removeAttendee($removal['room'], $removal['participant'], Room::PARTICIPANT_REMOVED);
$this->participantService->removeAttendee($removal['room'], $removal['participant'], AAttendeeRemovedEvent::REASON_REMOVED);
}

$map = [];
Expand Down Expand Up @@ -489,7 +490,7 @@ public function switchBreakoutRoom(Room $parent, Participant $participant, strin
$this->participantService->removeAttendee(
$breakoutRoom,
$removeParticipant,
Room::PARTICIPANT_LEFT
AAttendeeRemovedEvent::REASON_LEFT
);
}
} catch (ParticipantNotFoundException $e) {
Expand Down Expand Up @@ -572,7 +573,7 @@ public function removeAttendeeFromBreakoutRoom(Room $parent, string $actorType,
throw new \InvalidArgumentException('moderator');
}

$this->participantService->removeAttendee($breakoutRoom, $participant, Room::PARTICIPANT_REMOVED);
$this->participantService->removeAttendee($breakoutRoom, $participant, AAttendeeRemovedEvent::REASON_REMOVED);
} catch (ParticipantNotFoundException $e) {
// Skip this room
}
Expand Down
19 changes: 13 additions & 6 deletions lib/Service/ParticipantService.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
use OCA\Circles\Model\Member;
use OCA\Talk\Chat\ChatManager;
use OCA\Talk\Config;
use OCA\Talk\Events\AAttendeeRemovedEvent;
use OCA\Talk\Events\AddParticipantsEvent;
use OCA\Talk\Events\AParticipantModifiedEvent;
use OCA\Talk\Events\AttendeeRemovedEvent;
Expand Down Expand Up @@ -177,7 +178,7 @@ public function updateParticipantType(Room $room, Participant $participant, int

if ($demotedFromModerator) {
// Remove participant from all breakout rooms
$this->removeAttendee($breakoutRoom, $breakoutRoomParticipant, Room::PARTICIPANT_REMOVED);
$this->removeAttendee($breakoutRoom, $breakoutRoomParticipant, AAttendeeRemovedEvent::REASON_REMOVED);
} elseif (!$breakoutRoomParticipant->hasModeratorPermissions()) {
if ($breakoutRoomParticipant->getAttendee()->getParticipantType() === Participant::USER
|| $breakoutRoomParticipant->getAttendee()->getParticipantType() === Participant::USER_SELF_JOINED) {
Expand Down Expand Up @@ -327,7 +328,7 @@ public function joinRoom(RoomService $roomService, Room $room, IUser $user, stri
$this->dispatcher->dispatch(Room::EVENT_BEFORE_ROOM_CONNECT, $legacyEvent);

if ($legacyEvent->getCancelJoin() === true) {
$this->removeUser($room, $user, Room::PARTICIPANT_LEFT);
$this->removeUser($room, $user, AAttendeeRemovedEvent::REASON_LEFT);
throw new UnauthorizedException('Participant is not allowed to join');
}

Expand Down Expand Up @@ -855,10 +856,13 @@ public function leaveRoomAsSession(Room $room, Participant $participant, bool $d
&& empty($this->sessionMapper->findByAttendeeId($participant->getAttendee()->getId()))) {
$user = $this->userManager->get($participant->getAttendee()->getActorId());

$this->removeUser($room, $user, Room::PARTICIPANT_LEFT);
$this->removeUser($room, $user, AAttendeeRemovedEvent::REASON_LEFT);
}
}

/**
* @psalm-param AAttendeeRemovedEvent::REASON_* $reason
*/
public function removeAttendee(Room $room, Participant $participant, string $reason, bool $attendeeEventIsTriggeredAlready = false): void {
$isUser = $participant->getAttendee()->getActorType() === Attendee::ACTOR_USERS;

Expand Down Expand Up @@ -1006,6 +1010,9 @@ public function removeCircleMembers(Room $room, Participant $removedCirclePartic
$this->dispatcher->dispatchTyped($attendeeEvent);
}

/**
* @psalm-param AAttendeeRemovedEvent::REASON_* $reason
*/
public function removeUser(Room $room, IUser $user, string $reason): void {
try {
$participant = $this->getParticipant($room, $user->getUID(), false);
Expand All @@ -1016,7 +1023,7 @@ public function removeUser(Room $room, IUser $user, string $reason): void {
$attendee = $participant->getAttendee();
$sessions = $this->sessionService->getAllSessionsForAttendee($attendee);

if ($reason !== Room::PARTICIPANT_REMOVED_ALL && $room->getBreakoutRoomMode() !== BreakoutRoom::MODE_NOT_CONFIGURED) {
if ($reason !== AAttendeeRemovedEvent::REASON_REMOVED_ALL && $room->getBreakoutRoomMode() !== BreakoutRoom::MODE_NOT_CONFIGURED) {
/** @var BreakoutRoomService $breakoutRoomService */
$breakoutRoomService = Server::get(BreakoutRoomService::class);
$breakoutRoomService->removeAttendeeFromBreakoutRoom(
Expand All @@ -1025,8 +1032,8 @@ public function removeUser(Room $room, IUser $user, string $reason): void {
$attendee->getActorId(),
false
);
} elseif ($reason === Room::PARTICIPANT_REMOVED_ALL) {
$reason = Room::PARTICIPANT_REMOVED;
} elseif ($reason === AAttendeeRemovedEvent::REASON_REMOVED_ALL) {
$reason = AAttendeeRemovedEvent::REASON_REMOVED;
}

$attendeeEvent = new BeforeAttendeeRemovedEvent($room, $attendee, $reason, $sessions);
Expand Down

0 comments on commit 4813069

Please sign in to comment.