Skip to content

Commit 31f4942

Browse files
committed
Add remoteId
Signed-off-by: Gary Kim <[email protected]>
1 parent 994f629 commit 31f4942

8 files changed

+40
-9
lines changed

lib/Federation/CloudFederationProviderTalk.php

+6-5
Original file line numberDiff line numberDiff line change
@@ -117,13 +117,14 @@ public function shareReceived(ICloudFederationShare $share): string {
117117
}
118118

119119
if (!is_numeric($share->getShareType())) {
120-
throw new ProviderCouldNotAddShareException('RoomType is not a number', '', Http::STATUS_BAD_REQUEST);
120+
throw new ProviderCouldNotAddShareException('shareType is not a number', '', Http::STATUS_BAD_REQUEST);
121121
}
122122

123123
$shareSecret = $share->getShareSecret();
124124
$shareWith = $share->getShareWith();
125-
$roomToken = $share->getProviderId();
126-
$roomName = $share->getResourceName();
125+
$remoteId = $share->getProviderId();
126+
$roomToken = $share->getResourceName();
127+
$roomName = $share->getProtocol()['roomName'];
127128
$roomType = (int) $share->getShareType();
128129
$sharedBy = $share->getSharedByDisplayName();
129130
$sharedByFederatedId = $share->getSharedBy();
@@ -138,13 +139,13 @@ public function shareReceived(ICloudFederationShare $share): string {
138139
$sharedByFederatedId = $ownerFederatedId;
139140
}
140141

141-
if ($remote && $shareSecret && $shareWith && $roomToken && $roomName && $owner) {
142+
if ($remote && $shareSecret && $shareWith && $roomToken && $remoteId && is_string($roomName) && $roomName && $owner) {
142143
$shareWith = $this->userManager->get($shareWith);
143144
if ($shareWith === null) {
144145
throw new ProviderCouldNotAddShareException('User does not exist', '',Http::STATUS_BAD_REQUEST);
145146
}
146147

147-
$shareId = (string) $this->federationManager->addRemoteRoom($shareWith, $roomType, $roomName, $roomToken, $remote, $shareSecret);
148+
$shareId = (string) $this->federationManager->addRemoteRoom($shareWith, $remoteId, $roomType, $roomName, $roomToken, $remote, $shareSecret);
148149

149150
$this->notifyAboutNewShare($shareWith, $shareId, $sharedByFederatedId, $sharedBy, $roomName, $roomToken, $remote);
150151
return $shareId;

lib/Federation/FederationManager.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ public function isEnabled(): bool {
9090
* @return int share id for this specific remote room share
9191
* @throws DBException
9292
*/
93-
public function addRemoteRoom(IUser $user, int $roomType, string $roomName, string $roomToken, string $remoteUrl, string $sharedSecret): int {
93+
public function addRemoteRoom(IUser $user, string $remoteId, int $roomType, string $roomName, string $roomToken, string $remoteUrl, string $sharedSecret): int {
9494
try {
9595
$room = $this->manager->getRoomByToken($roomToken, null, $remoteUrl);
9696
} catch (RoomNotFoundException $ex) {
@@ -100,6 +100,7 @@ public function addRemoteRoom(IUser $user, int $roomType, string $roomName, stri
100100
$invitation->setUserId($user->getUID());
101101
$invitation->setRoomId($room->getId());
102102
$invitation->setAccessToken($sharedSecret);
103+
$invitation->setRemoteId($remoteId);
103104
$invitation = $this->invitationMapper->insert($invitation);
104105

105106
return $invitation->getId();
@@ -124,6 +125,7 @@ public function acceptRemoteRoomShare(IUser $user, int $shareId) {
124125
'actorId' => $user->getUID(),
125126
'displayName' => $user->getDisplayName(),
126127
'accessToken' => $invitation->getAccessToken(),
128+
'remoteId' => $invitation->getRemoteId(),
127129
]
128130
];
129131
$this->participantService->addUsers($room, $participant);

lib/Migration/Version13000Date20210625232111.php

+9
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,12 @@ public function changeSchema(IOutput $output, Closure $schemaClosure, array $opt
5151
'default' => null,
5252
]);
5353
}
54+
if (!$table->hasColumn('remote_id')) {
55+
$table->addColumn('remote_id', Types::STRING, [
56+
'notnull' => false,
57+
'default' => null,
58+
]);
59+
}
5460

5561
$table = $schema->getTable('talk_rooms');
5662
if (!$table->hasColumn('server_url')) {
@@ -77,6 +83,9 @@ public function changeSchema(IOutput $output, Closure $schemaClosure, array $opt
7783
$table->addColumn('access_token', Types::STRING, [
7884
'notnull' => true,
7985
]);
86+
$table->addColumn('remote_id', Types::STRING, [
87+
'notnull' => true,
88+
]);
8089

8190
$table->setPrimaryKey(['id']);
8291

lib/Model/Attendee.php

+7
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@
5353
* @method int getPublishingPermissions()
5454
* @method void setAccessToken(string $accessToken)
5555
* @method null|string getAccessToken()
56+
* @method void setRemoteId(string $remoteId)
57+
* @method string getRemoteId()
5658
*/
5759
class Attendee extends Entity {
5860
public const ACTOR_USERS = 'users';
@@ -110,6 +112,9 @@ class Attendee extends Entity {
110112
/** @var string */
111113
protected $accessToken;
112114

115+
/** @var string */
116+
protected $remoteId;
117+
113118
public function __construct() {
114119
$this->addType('roomId', 'int');
115120
$this->addType('actorType', 'string');
@@ -125,6 +130,7 @@ public function __construct() {
125130
$this->addType('readPrivacy', 'int');
126131
$this->addType('publishingPermissions', 'int');
127132
$this->addType('accessToken', 'string');
133+
$this->addType('remote_id', 'string');
128134
}
129135

130136
public function getDisplayName(): string {
@@ -151,6 +157,7 @@ public function asArray(): array {
151157
'read_privacy' => $this->getReadPrivacy(),
152158
'publishing_permissions' => $this->getPublishingPermissions(),
153159
'access_token' => $this->getAccessToken(),
160+
'remote_id' => $this->getRemoteId(),
154161
];
155162
}
156163
}

lib/Model/AttendeeMapper.php

+1
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,7 @@ public function createAttendeeFromRow(array $row): Attendee {
175175
'read_privacy' => (int) $row['read_privacy'],
176176
'publishing_permissions' => (int) $row['publishing_permissions'],
177177
'access_token' => (string) $row['access_token'],
178+
'remote_id' => (string) $row['remote_id'],
178179
]);
179180
}
180181
}

lib/Model/Invitation.php

+7
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@
3838
* @method string getUserId()
3939
* @method void setAccessToken(string $accessToken)
4040
* @method string getAccessToken()
41+
* @method void setRemoteId(string $remoteId)
42+
* @method string getRemoteId()
4143
*/
4244
class Invitation extends Entity {
4345
/** @var int */
@@ -49,10 +51,14 @@ class Invitation extends Entity {
4951
/** @var string */
5052
protected $accessToken;
5153

54+
/** @var string */
55+
protected $remoteId;
56+
5257
public function __construct() {
5358
$this->addType('roomId', 'int');
5459
$this->addType('userId', 'string');
5560
$this->addType('accessToken', 'string');
61+
$this->addType('remoteId', 'string');
5662
}
5763

5864
public function asArray(): array {
@@ -61,6 +67,7 @@ public function asArray(): array {
6167
'room_id' => $this->getRoomId(),
6268
'user_id' => $this->getUserId(),
6369
'access_token' => $this->getAccessToken(),
70+
'remote_id' => $this->getRemoteId(),
6471
];
6572
}
6673
}

lib/Model/InvitationMapper.php

+4-3
Original file line numberDiff line numberDiff line change
@@ -97,9 +97,10 @@ public function countInvitationsForRoom(Room $room): int {
9797
public function createInvitationFromRow(array $row): Invitation {
9898
return $this->mapRowToEntity([
9999
'id' => $row['id'],
100-
'room_id' => $row['room_id'],
101-
'user_id' => $row['user_id'],
102-
'access_token' => $row['access_token'],
100+
'room_id' => (int) $row['room_id'],
101+
'user_id' => (string) $row['user_id'],
102+
'access_token' => (string) $row['access_token'],
103+
'remote_id' => (string) $row['remote_id'],
103104
]);
104105
}
105106
}

lib/Service/ParticipantService.php

+3
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,9 @@ public function addUsers(Room $room, array $participants): void {
328328
if (isset($participant['accessToken'])) {
329329
$attendee->setAccessToken($participant['accessToken']);
330330
}
331+
if (isset($participant['remoteId'])) {
332+
$attendee->setRemoteId($participant['remoteId']);
333+
}
331334
$attendee->setParticipantType($participant['participantType'] ?? Participant::USER);
332335
$attendee->setLastReadMessage($lastMessage);
333336
$attendee->setReadPrivacy($readPrivacy);

0 commit comments

Comments
 (0)