diff --git a/lib/Federation/CloudFederationProviderTalk.php b/lib/Federation/CloudFederationProviderTalk.php index 1bd55545870..3e89bda0721 100644 --- a/lib/Federation/CloudFederationProviderTalk.php +++ b/lib/Federation/CloudFederationProviderTalk.php @@ -117,13 +117,14 @@ public function shareReceived(ICloudFederationShare $share): string { } if (!is_numeric($share->getShareType())) { - throw new ProviderCouldNotAddShareException('RoomType is not a number', '', Http::STATUS_BAD_REQUEST); + throw new ProviderCouldNotAddShareException('shareType is not a number', '', Http::STATUS_BAD_REQUEST); } $shareSecret = $share->getShareSecret(); $shareWith = $share->getShareWith(); - $roomToken = $share->getProviderId(); - $roomName = $share->getResourceName(); + $remoteId = $share->getProviderId(); + $roomToken = $share->getResourceName(); + $roomName = $share->getProtocol()['roomName']; $roomType = (int) $share->getShareType(); $sharedBy = $share->getSharedByDisplayName(); $sharedByFederatedId = $share->getSharedBy(); @@ -138,13 +139,13 @@ public function shareReceived(ICloudFederationShare $share): string { $sharedByFederatedId = $ownerFederatedId; } - if ($remote && $shareSecret && $shareWith && $roomToken && $roomName && $owner) { + if ($remote && $shareSecret && $shareWith && $roomToken && $remoteId && is_string($roomName) && $roomName && $owner) { $shareWith = $this->userManager->get($shareWith); if ($shareWith === null) { throw new ProviderCouldNotAddShareException('User does not exist', '',Http::STATUS_BAD_REQUEST); } - $shareId = (string) $this->federationManager->addRemoteRoom($shareWith, $roomType, $roomName, $roomToken, $remote, $shareSecret); + $shareId = (string) $this->federationManager->addRemoteRoom($shareWith, $remoteId, $roomType, $roomName, $roomToken, $remote, $shareSecret); $this->notifyAboutNewShare($shareWith, $shareId, $sharedByFederatedId, $sharedBy, $roomName, $roomToken, $remote); return $shareId; diff --git a/lib/Federation/FederationManager.php b/lib/Federation/FederationManager.php index 00dbbb7aae3..691d83a6ce5 100644 --- a/lib/Federation/FederationManager.php +++ b/lib/Federation/FederationManager.php @@ -90,7 +90,7 @@ public function isEnabled(): bool { * @return int share id for this specific remote room share * @throws DBException */ - public function addRemoteRoom(IUser $user, int $roomType, string $roomName, string $roomToken, string $remoteUrl, string $sharedSecret): int { + public function addRemoteRoom(IUser $user, string $remoteId, int $roomType, string $roomName, string $roomToken, string $remoteUrl, string $sharedSecret): int { try { $room = $this->manager->getRoomByToken($roomToken, null, $remoteUrl); } catch (RoomNotFoundException $ex) { @@ -100,6 +100,7 @@ public function addRemoteRoom(IUser $user, int $roomType, string $roomName, stri $invitation->setUserId($user->getUID()); $invitation->setRoomId($room->getId()); $invitation->setAccessToken($sharedSecret); + $invitation->setRemoteId($remoteId); $invitation = $this->invitationMapper->insert($invitation); return $invitation->getId(); @@ -124,6 +125,7 @@ public function acceptRemoteRoomShare(IUser $user, int $shareId) { 'actorId' => $user->getUID(), 'displayName' => $user->getDisplayName(), 'accessToken' => $invitation->getAccessToken(), + 'remoteId' => $invitation->getRemoteId(), ] ]; $this->participantService->addUsers($room, $participant); diff --git a/lib/Migration/Version13000Date20210625232111.php b/lib/Migration/Version13000Date20210625232111.php index fc351446298..3f19a546c44 100644 --- a/lib/Migration/Version13000Date20210625232111.php +++ b/lib/Migration/Version13000Date20210625232111.php @@ -49,6 +49,14 @@ public function changeSchema(IOutput $output, Closure $schemaClosure, array $opt $table->addColumn('access_token', Types::STRING, [ 'notnull' => false, 'default' => null, + 'length' => 64 + ]); + } + if (!$table->hasColumn('remote_id')) { + $table->addColumn('remote_id', Types::STRING, [ + 'notnull' => false, + 'default' => null, + 'length' => 255, ]); } @@ -76,6 +84,11 @@ public function changeSchema(IOutput $output, Closure $schemaClosure, array $opt ]); $table->addColumn('access_token', Types::STRING, [ 'notnull' => true, + 'length' => 64, + ]); + $table->addColumn('remote_id', Types::STRING, [ + 'notnull' => true, + 'length' => 255, ]); $table->setPrimaryKey(['id']); diff --git a/lib/Model/Attendee.php b/lib/Model/Attendee.php index c1eb7d9fb17..58424a554b3 100644 --- a/lib/Model/Attendee.php +++ b/lib/Model/Attendee.php @@ -53,6 +53,8 @@ * @method int getPublishingPermissions() * @method void setAccessToken(string $accessToken) * @method null|string getAccessToken() + * @method void setRemoteId(string $remoteId) + * @method string getRemoteId() */ class Attendee extends Entity { public const ACTOR_USERS = 'users'; @@ -110,6 +112,9 @@ class Attendee extends Entity { /** @var string */ protected $accessToken; + /** @var string */ + protected $remoteId; + public function __construct() { $this->addType('roomId', 'int'); $this->addType('actorType', 'string'); @@ -125,6 +130,7 @@ public function __construct() { $this->addType('readPrivacy', 'int'); $this->addType('publishingPermissions', 'int'); $this->addType('accessToken', 'string'); + $this->addType('remote_id', 'string'); } public function getDisplayName(): string { @@ -151,6 +157,7 @@ public function asArray(): array { 'read_privacy' => $this->getReadPrivacy(), 'publishing_permissions' => $this->getPublishingPermissions(), 'access_token' => $this->getAccessToken(), + 'remote_id' => $this->getRemoteId(), ]; } } diff --git a/lib/Model/AttendeeMapper.php b/lib/Model/AttendeeMapper.php index cbf6f039306..9a57c7887a1 100644 --- a/lib/Model/AttendeeMapper.php +++ b/lib/Model/AttendeeMapper.php @@ -175,6 +175,7 @@ public function createAttendeeFromRow(array $row): Attendee { 'read_privacy' => (int) $row['read_privacy'], 'publishing_permissions' => (int) $row['publishing_permissions'], 'access_token' => (string) $row['access_token'], + 'remote_id' => (string) $row['remote_id'], ]); } } diff --git a/lib/Model/Invitation.php b/lib/Model/Invitation.php index cf2a591e043..8ba07561554 100644 --- a/lib/Model/Invitation.php +++ b/lib/Model/Invitation.php @@ -38,6 +38,8 @@ * @method string getUserId() * @method void setAccessToken(string $accessToken) * @method string getAccessToken() + * @method void setRemoteId(string $remoteId) + * @method string getRemoteId() */ class Invitation extends Entity { /** @var int */ @@ -49,10 +51,14 @@ class Invitation extends Entity { /** @var string */ protected $accessToken; + /** @var string */ + protected $remoteId; + public function __construct() { $this->addType('roomId', 'int'); $this->addType('userId', 'string'); $this->addType('accessToken', 'string'); + $this->addType('remoteId', 'string'); } public function asArray(): array { @@ -61,6 +67,7 @@ public function asArray(): array { 'room_id' => $this->getRoomId(), 'user_id' => $this->getUserId(), 'access_token' => $this->getAccessToken(), + 'remote_id' => $this->getRemoteId(), ]; } } diff --git a/lib/Model/InvitationMapper.php b/lib/Model/InvitationMapper.php index 2a453a2a001..f54cbafd8cf 100644 --- a/lib/Model/InvitationMapper.php +++ b/lib/Model/InvitationMapper.php @@ -97,9 +97,10 @@ public function countInvitationsForRoom(Room $room): int { public function createInvitationFromRow(array $row): Invitation { return $this->mapRowToEntity([ 'id' => $row['id'], - 'room_id' => $row['room_id'], - 'user_id' => $row['user_id'], - 'access_token' => $row['access_token'], + 'room_id' => (int) $row['room_id'], + 'user_id' => (string) $row['user_id'], + 'access_token' => (string) $row['access_token'], + 'remote_id' => (string) $row['remote_id'], ]); } } diff --git a/lib/Service/ParticipantService.php b/lib/Service/ParticipantService.php index e876515454f..a2386948815 100644 --- a/lib/Service/ParticipantService.php +++ b/lib/Service/ParticipantService.php @@ -328,6 +328,9 @@ public function addUsers(Room $room, array $participants): void { if (isset($participant['accessToken'])) { $attendee->setAccessToken($participant['accessToken']); } + if (isset($participant['remoteId'])) { + $attendee->setRemoteId($participant['remoteId']); + } $attendee->setParticipantType($participant['participantType'] ?? Participant::USER); $attendee->setLastReadMessage($lastMessage); $attendee->setReadPrivacy($readPrivacy);