Skip to content

Commit

Permalink
Add remoteId
Browse files Browse the repository at this point in the history
Signed-off-by: Gary Kim <[email protected]>
  • Loading branch information
gary-kim committed Jul 15, 2021
1 parent 994f629 commit 9ffc8e6
Show file tree
Hide file tree
Showing 8 changed files with 44 additions and 9 deletions.
11 changes: 6 additions & 5 deletions lib/Federation/CloudFederationProviderTalk.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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;
Expand Down
4 changes: 3 additions & 1 deletion lib/Federation/FederationManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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();
Expand All @@ -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);
Expand Down
13 changes: 13 additions & 0 deletions lib/Migration/Version13000Date20210625232111.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
]);
}

Expand Down Expand Up @@ -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']);
Expand Down
7 changes: 7 additions & 0 deletions lib/Model/Attendee.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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');
Expand All @@ -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 {
Expand All @@ -151,6 +157,7 @@ public function asArray(): array {
'read_privacy' => $this->getReadPrivacy(),
'publishing_permissions' => $this->getPublishingPermissions(),
'access_token' => $this->getAccessToken(),
'remote_id' => $this->getRemoteId(),
];
}
}
1 change: 1 addition & 0 deletions lib/Model/AttendeeMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'],
]);
}
}
7 changes: 7 additions & 0 deletions lib/Model/Invitation.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand All @@ -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 {
Expand All @@ -61,6 +67,7 @@ public function asArray(): array {
'room_id' => $this->getRoomId(),
'user_id' => $this->getUserId(),
'access_token' => $this->getAccessToken(),
'remote_id' => $this->getRemoteId(),
];
}
}
7 changes: 4 additions & 3 deletions lib/Model/InvitationMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'],
]);
}
}
3 changes: 3 additions & 0 deletions lib/Service/ParticipantService.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 9ffc8e6

Please sign in to comment.