Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(API): Use Room::isFederatedConversation() consistantly #11843

Merged
merged 1 commit into from
Mar 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/BackgroundJob/RemoveEmptyRooms.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ private function deleteIfIsEmpty(Room $room): bool {
return false;
}

if ($room->getRemoteServer() && $room->getRemoteToken()
if ($room->isFederatedConversation()
&& $this->federationManager->getNumberOfInvitations($room) !== 0) {
return false;
}
Expand Down
4 changes: 2 additions & 2 deletions lib/Chat/ChatManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ public function addSystemMessage(
bool $shouldSkipLastMessageUpdate = false,
bool $silent = false,
): IComment {
if ($chat->getRemoteServer() !== '') {
if ($chat->isFederatedConversation()) {
$e = new MessagingNotAllowedException();
$this->logger->error('Attempt to post system message into proxy conversation', ['exception' => $e]);
throw $e;
Expand Down Expand Up @@ -286,7 +286,7 @@ public function addChangelogMessage(Room $chat, string $message): IComment {
* @throws MessagingNotAllowedException
*/
public function sendMessage(Room $chat, ?Participant $participant, string $actorType, string $actorId, string $message, \DateTime $creationDateTime, ?IComment $replyTo = null, string $referenceId = '', bool $silent = false, bool $rateLimitGuestMentions = true): IComment {
if ($chat->getRemoteServer() !== '') {
if ($chat->isFederatedConversation()) {
$e = new MessagingNotAllowedException();
$this->logger->error('Attempt to post system message into proxy conversation', ['exception' => $e]);
throw $e;
Expand Down
23 changes: 11 additions & 12 deletions lib/Chat/SystemMessage/Listener.php
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ protected function sendSystemMessageAboutCallLeft(ParticipantModifiedEvent $even
}

protected function sendSystemMessageAboutConversationCreated(RoomCreatedEvent $event): void {
if ($event->getRoom()->getRemoteServer() !== '') {
if ($event->getRoom()->isFederatedConversation()) {
return;
}

Expand All @@ -182,7 +182,7 @@ protected function sendSystemMessageAboutConversationRenamed(RoomModifiedEvent $
return;
}

if ($event->getRoom()->getRemoteServer() !== '') {
if ($event->getRoom()->isFederatedConversation()) {
return;
}

Expand All @@ -194,7 +194,7 @@ protected function sendSystemMessageAboutConversationRenamed(RoomModifiedEvent $
}

protected function sendSystemMessageAboutRoomDescriptionChanges(RoomModifiedEvent $event): void {
if ($event->getRoom()->getRemoteServer() !== '') {
if ($event->getRoom()->isFederatedConversation()) {
return;
}

Expand All @@ -212,7 +212,7 @@ protected function sendSystemMessageAboutRoomDescriptionChanges(RoomModifiedEven
}

protected function sendSystemMessageAboutRoomPassword(RoomModifiedEvent $event): void {
if ($event->getRoom()->getRemoteServer() !== '') {
if ($event->getRoom()->isFederatedConversation()) {
return;
}

Expand Down Expand Up @@ -242,7 +242,7 @@ protected function sendSystemReadOnlyMessage(RoomModifiedEvent $event): void {
return;
}

if ($room->getRemoteServer() !== '') {
if ($room->isFederatedConversation()) {
return;
}

Expand Down Expand Up @@ -294,7 +294,7 @@ protected function addSystemMessageUserAdded(AttendeesAddedEvent $event, Attende
return;
}

if ($room->getRemoteServer() !== '') {
if ($room->isFederatedConversation()) {
return;
}

Expand Down Expand Up @@ -331,7 +331,7 @@ protected function sendSystemMessageUserRemoved(AttendeeRemovedEvent $event): vo
return;
}

if ($room->getRemoteServer() !== '') {
if ($room->isFederatedConversation()) {
return;
}

Expand All @@ -352,7 +352,7 @@ public function sendSystemMessageAboutPromoteOrDemoteModerator(ParticipantModifi
return;
}

if ($event->getRoom()->getRemoteServer() !== '') {
if ($event->getRoom()->isFederatedConversation()) {
return;
}

Expand Down Expand Up @@ -401,8 +401,7 @@ protected function fixMimeTypeOfVoiceMessage(ShareCreatedEvent|BeforeDuplicateSh
return;
}
$room = $this->manager->getRoomByToken($share->getSharedWith());
if ($room->getRemoteServer() !== '') {
// FIXME this should be blocked up front
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here is the unequal line count of the diff

if ($room->isFederatedConversation()) {
return;
}

Expand Down Expand Up @@ -436,7 +435,7 @@ protected function fixMimeTypeOfVoiceMessage(ShareCreatedEvent|BeforeDuplicateSh
}

protected function attendeesAddedEvent(AttendeesAddedEvent $event): void {
if ($event->getRoom()->getRemoteServer() !== '') {
if ($event->getRoom()->isFederatedConversation()) {
return;
}

Expand All @@ -456,7 +455,7 @@ protected function attendeesAddedEvent(AttendeesAddedEvent $event): void {
}

protected function attendeesRemovedEvent(AttendeesRemovedEvent $event): void {
if ($event->getRoom()->getRemoteServer() !== '') {
if ($event->getRoom()->isFederatedConversation()) {
return;
}

Expand Down
2 changes: 1 addition & 1 deletion lib/Collaboration/Collaborators/Listener.php
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ protected function filterExistingParticipants(string $token, array $results): ar
return $results;
}

if ($this->room->getRemoteServer() !== '') {
if ($this->room->isFederatedConversation()) {
return $results;
}

Expand Down
2 changes: 1 addition & 1 deletion lib/Collaboration/Collaborators/RoomPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public function search($search, $limit, $offset, ISearchResult $searchResult): b
continue;
}

if ($room->getRemoteServer() !== '') {
if ($room->isFederatedConversation()) {
continue;
}

Expand Down
2 changes: 1 addition & 1 deletion lib/Command/Bot/Setup.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
try {
$room = $this->roomManager->getRoomByToken($token);

if ($room->getRemoteServer() !== '') {
if ($room->isFederatedConversation()) {
$output->writeln('<error>Federated conversations can not have bots: ' . $token . '</error>');
$returnCode = 2;
}
Expand Down
2 changes: 1 addition & 1 deletion lib/Controller/AvatarController.php
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ public function emojiAvatar(string $emoji, ?string $color): DataResponse {
public function getAvatar(bool $darkTheme = false): FileDisplayResponse {
// Cache for 1 day
$cacheDuration = 60 * 60 * 24;
if ($this->room->getRemoteServer() !== '') {
if ($this->room->isFederatedConversation()) {
/** @var \OCA\Talk\Federation\Proxy\TalkV1\Controller\AvatarController $proxy */
$proxy = \OCP\Server::get(\OCA\Talk\Federation\Proxy\TalkV1\Controller\AvatarController::class);
try {
Expand Down
2 changes: 1 addition & 1 deletion lib/Controller/BotController.php
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ public function listBots(): DataResponse {
#[NoAdminRequired]
#[RequireLoggedInModeratorParticipant]
public function enableBot(int $botId): DataResponse {
if ($this->room->getRemoteServer() !== '') {
if ($this->room->isFederatedConversation()) {
return new DataResponse([
'error' => 'room',
], Http::STATUS_BAD_REQUEST);
Expand Down
16 changes: 8 additions & 8 deletions lib/Controller/ChatController.php
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ protected function parseCommentToResponse(IComment $comment, ?Message $parentMes
#[RequirePermission(permission: RequirePermission::CHAT)]
#[RequireReadWriteConversation]
public function sendMessage(string $message, string $actorDisplayName = '', string $referenceId = '', int $replyTo = 0, bool $silent = false): DataResponse {
if ($this->room->getRemoteServer()) {
if ($this->room->isFederatedConversation()) {
/** @var \OCA\Talk\Federation\Proxy\TalkV1\Controller\ChatController $proxy */
$proxy = \OCP\Server::get(\OCA\Talk\Federation\Proxy\TalkV1\Controller\ChatController::class);
return $proxy->sendMessage($this->room, $this->participant, $message, $referenceId, $replyTo, $silent);
Expand Down Expand Up @@ -433,7 +433,7 @@ public function receiveMessages(int $lookIntoFuture,
$limit = min(200, $limit);
$timeout = min(30, $timeout);

if ($this->room->getRemoteServer() !== '') {
if ($this->room->isFederatedConversation()) {
/** @var \OCA\Talk\Federation\Proxy\TalkV1\Controller\ChatController $proxy */
$proxy = \OCP\Server::get(\OCA\Talk\Federation\Proxy\TalkV1\Controller\ChatController::class);
return $proxy->receiveMessages(
Expand Down Expand Up @@ -656,7 +656,7 @@ public function getMessageContext(
int $limit = 50): DataResponse {
$limit = min(100, $limit);

if ($this->room->getRemoteServer() !== '') {
if ($this->room->isFederatedConversation()) {
/** @var \OCA\Talk\Federation\Proxy\TalkV1\Controller\ChatController $proxy */
$proxy = \OCP\Server::get(\OCA\Talk\Federation\Proxy\TalkV1\Controller\ChatController::class);
return $proxy->getMessageContext($this->room, $this->participant, $messageId, $limit);
Expand Down Expand Up @@ -735,7 +735,7 @@ protected function loadSelfReactions(array $messages, array $commentIdToIndex):
#[RequirePermission(permission: RequirePermission::CHAT)]
#[RequireReadWriteConversation]
public function deleteMessage(int $messageId): DataResponse {
if ($this->room->getRemoteServer() !== '') {
if ($this->room->isFederatedConversation()) {
/** @var \OCA\Talk\Federation\Proxy\TalkV1\Controller\ChatController $proxy */
$proxy = \OCP\Server::get(\OCA\Talk\Federation\Proxy\TalkV1\Controller\ChatController::class);
return $proxy->deleteMessage(
Expand Down Expand Up @@ -827,7 +827,7 @@ public function deleteMessage(int $messageId): DataResponse {
#[RequirePermission(permission: RequirePermission::CHAT)]
#[RequireReadWriteConversation]
public function editMessage(int $messageId, string $message): DataResponse {
if ($this->room->getRemoteServer() !== '') {
if ($this->room->isFederatedConversation()) {
/** @var \OCA\Talk\Federation\Proxy\TalkV1\Controller\ChatController $proxy */
$proxy = \OCP\Server::get(\OCA\Talk\Federation\Proxy\TalkV1\Controller\ChatController::class);
return $proxy->editMessage(
Expand Down Expand Up @@ -1086,7 +1086,7 @@ public function clearHistory(): DataResponse {
#[PublicPage]
#[RequireAuthenticatedParticipant]
public function setReadMarker(?int $lastReadMessage = null): DataResponse {
if ($this->room->getRemoteServer() !== '') {
if ($this->room->isFederatedConversation()) {
/** @var \OCA\Talk\Federation\Proxy\TalkV1\Controller\ChatController $proxy */
$proxy = \OCP\Server::get(\OCA\Talk\Federation\Proxy\TalkV1\Controller\ChatController::class);
return $proxy->setReadMarker($this->room, $this->participant, $this->getResponseFormat(), $lastReadMessage);
Expand Down Expand Up @@ -1121,7 +1121,7 @@ public function setReadMarker(?int $lastReadMessage = null): DataResponse {
#[PublicPage]
#[RequireAuthenticatedParticipant]
public function markUnread(): DataResponse {
if ($this->room->getRemoteServer() !== '') {
if ($this->room->isFederatedConversation()) {
/** @var \OCA\Talk\Federation\Proxy\TalkV1\Controller\ChatController $proxy */
$proxy = \OCP\Server::get(\OCA\Talk\Federation\Proxy\TalkV1\Controller\ChatController::class);
return $proxy->markUnread($this->room, $this->participant, $this->getResponseFormat());
Expand Down Expand Up @@ -1280,7 +1280,7 @@ protected function getMessagesForRoom(array $messageIds): array {
#[RequirePermission(permission: RequirePermission::CHAT)]
#[RequireReadWriteConversation]
public function mentions(string $search, int $limit = 20, bool $includeStatus = false): DataResponse {
if ($this->room->getRemoteServer()) {
if ($this->room->isFederatedConversation()) {
/** @var \OCA\Talk\Federation\Proxy\TalkV1\Controller\ChatController $proxy */
$proxy = \OCP\Server::get(\OCA\Talk\Federation\Proxy\TalkV1\Controller\ChatController::class);
return $proxy->mentions($this->room, $this->participant, $search, $limit, $includeStatus);
Expand Down
8 changes: 4 additions & 4 deletions lib/Controller/PollController.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public function __construct(
#[RequirePermission(permission: RequirePermission::CHAT)]
#[RequireReadWriteConversation]
public function createPoll(string $question, array $options, int $resultMode, int $maxVotes): DataResponse {
if ($this->room->getRemoteServer() !== '') {
if ($this->room->isFederatedConversation()) {
/** @var \OCA\Talk\Federation\Proxy\TalkV1\Controller\PollController $proxy */
$proxy = \OCP\Server::get(\OCA\Talk\Federation\Proxy\TalkV1\Controller\PollController::class);
return $proxy->createPoll($this->room, $this->participant, $question, $options, $resultMode, $maxVotes);
Expand Down Expand Up @@ -153,7 +153,7 @@ public function createPoll(string $question, array $options, int $resultMode, in
#[RequireModeratorOrNoLobby]
#[RequireParticipant]
public function showPoll(int $pollId): DataResponse {
if ($this->room->getRemoteServer() !== '') {
if ($this->room->isFederatedConversation()) {
/** @var \OCA\Talk\Federation\Proxy\TalkV1\Controller\PollController $proxy */
$proxy = \OCP\Server::get(\OCA\Talk\Federation\Proxy\TalkV1\Controller\PollController::class);
return $proxy->showPoll($this->room, $this->participant, $pollId);
Expand Down Expand Up @@ -191,7 +191,7 @@ public function showPoll(int $pollId): DataResponse {
#[RequireModeratorOrNoLobby]
#[RequireParticipant]
public function votePoll(int $pollId, array $optionIds = []): DataResponse {
if ($this->room->getRemoteServer() !== '') {
if ($this->room->isFederatedConversation()) {
/** @var \OCA\Talk\Federation\Proxy\TalkV1\Controller\PollController $proxy */
$proxy = \OCP\Server::get(\OCA\Talk\Federation\Proxy\TalkV1\Controller\PollController::class);
return $proxy->votePoll($this->room, $this->participant, $pollId, $optionIds);
Expand Down Expand Up @@ -252,7 +252,7 @@ public function votePoll(int $pollId, array $optionIds = []): DataResponse {
#[RequireModeratorOrNoLobby]
#[RequireParticipant]
public function closePoll(int $pollId): DataResponse {
if ($this->room->getRemoteServer() !== '') {
if ($this->room->isFederatedConversation()) {
/** @var \OCA\Talk\Federation\Proxy\TalkV1\Controller\PollController $proxy */
$proxy = \OCP\Server::get(\OCA\Talk\Federation\Proxy\TalkV1\Controller\PollController::class);
return $proxy->closePoll($this->room, $this->participant, $pollId);
Expand Down
8 changes: 4 additions & 4 deletions lib/Controller/RoomController.php
Original file line number Diff line number Diff line change
Expand Up @@ -847,7 +847,7 @@ public function deleteRoom(): DataResponse {
#[RequireModeratorOrNoLobby]
#[RequireParticipant]
public function getParticipants(bool $includeStatus = false): DataResponse {
if ($this->room->getRemoteServer()) {
if ($this->room->isFederatedConversation()) {
/** @var \OCA\Talk\Federation\Proxy\TalkV1\Controller\RoomController $proxy */
$proxy = \OCP\Server::get(\OCA\Talk\Federation\Proxy\TalkV1\Controller\RoomController::class);
return $proxy->getParticipants($this->room, $this->participant);
Expand Down Expand Up @@ -1268,7 +1268,7 @@ public function removeSelfFromRoom(): DataResponse {
* @return DataResponse<Http::STATUS_OK|Http::STATUS_BAD_REQUEST|Http::STATUS_NOT_FOUND, array<empty>, array{}>
*/
protected function removeSelfFromRoomLogic(Room $room, Participant $participant): DataResponse {
if ($room->getRemoteServer() !== '') {
if ($room->isFederatedConversation()) {
$this->federationManager->rejectByRemoveSelf($room, $this->userId);
}

Expand Down Expand Up @@ -1538,7 +1538,7 @@ public function joinRoom(string $token, string $password = '', bool $force = tru
}

$headers = [];
if ($room->getRemoteServer() !== '') {
if ($room->isFederatedConversation()) {
$participant = $this->participantService->getParticipant($room, $this->userId);

/** @var \OCA\Talk\Federation\Proxy\TalkV1\Controller\RoomController $proxy */
Expand Down Expand Up @@ -2248,7 +2248,7 @@ public function setMessageExpiration(int $seconds): DataResponse {
#[RequireParticipant]
public function getCapabilities(): DataResponse {
$headers = [];
if ($this->room->getRemoteServer()) {
if ($this->room->isFederatedConversation()) {
/** @var \OCA\Talk\Federation\Proxy\TalkV1\Controller\RoomController $proxy */
$proxy = \OCP\Server::get(\OCA\Talk\Federation\Proxy\TalkV1\Controller\RoomController::class);
$response = $proxy->getCapabilities($this->room, $this->participant);
Expand Down
4 changes: 2 additions & 2 deletions lib/Flow/Operation.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ public function onEvent(string $eventName, Event $event, IRuleMatcher $ruleMatch
continue;
}

if ($room->getRemoteServer() !== '') {
if ($room->isFederatedConversation()) {
// Ignore conversation because it is a proxy conversation
continue;
}
Expand Down Expand Up @@ -202,7 +202,7 @@ protected function validateOperationConfig(int $mode, string $token, string $uid
throw new UnexpectedValueException('Room not found', $e->getCode(), $e);
}

if ($room->getRemoteServer() !== '') {
if ($room->isFederatedConversation()) {
throw new UnexpectedValueException('Room is a proxy conversation');
}

Expand Down
2 changes: 1 addition & 1 deletion lib/Middleware/InjectionMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ protected function getRoomByInvite(AEnvironmentAwareController $controller): voi
*/
protected function checkFederationSupport(AEnvironmentAwareController $controller): void {
$room = $controller->getRoom();
if ($room instanceof Room && $room->getRemoteServer() !== '') {
if ($room instanceof Room && $room->isFederatedConversation()) {
throw new FederationUnsupportedFeatureException();
}
}
Expand Down
2 changes: 1 addition & 1 deletion lib/Room.php
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ public function setLastMessageId(int $lastMessageId): void {
}

public function getLastMessage(): ?IComment {
if ($this->lastMessageId && $this->lastMessage === null && $this->getRemoteServer() === '') {
if ($this->lastMessageId && $this->lastMessage === null && !$this->isFederatedConversation()) {
$this->lastMessage = $this->manager->loadLastCommentInfo($this->lastMessageId);
if ($this->lastMessage === null) {
$this->lastMessageId = 0;
Expand Down
2 changes: 1 addition & 1 deletion lib/Search/CurrentMessageSearch.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public function search(IUser $user, ISearchQuery $query): SearchResult {
return SearchResult::complete($title, []);
}

if ($room->getRemoteServer() !== '') {
if ($room->isFederatedConversation()) {
return SearchResult::complete($title, []);
}

Expand Down
2 changes: 1 addition & 1 deletion lib/Search/MessageSearch.php
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ public function performSearch(IUser $user, ISearchQuery $query, string $title, a
}
}

if ($room->getRemoteServer() !== '') {
if ($room->isFederatedConversation()) {
continue;
}

Expand Down
2 changes: 1 addition & 1 deletion lib/Service/AvatarService.php
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ private function getAvatarPath(Room $room, bool $darkTheme = false): string {
if ($room->getObjectType() === Room::OBJECT_TYPE_PHONE) {
return __DIR__ . '/../../img/icon-conversation-phone-' . $colorTone . '.svg';
}
if ($room->getRemoteServer() !== '') {
if ($room->isFederatedConversation()) {
return __DIR__ . '/../../img/icon-conversation-federation-' . $colorTone . '.svg';
}
if ($room->getType() === Room::TYPE_PUBLIC) {
Expand Down
Loading
Loading