summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGary Kim <gary@garykim.dev>2021-07-13 23:45:54 -0400
committerGary Kim <gary@garykim.dev>2021-07-15 13:55:21 -0400
commitcf85ac6c9f8c90341cf9f35a20886d6c3a5db8fd (patch)
tree9912317776dc262d475cea979a8eb95c635f8b49
parentc49a1c27544ab0a4014a2ff385285d2bb556e5e6 (diff)
Add remoteId
Signed-off-by: Gary Kim <gary@garykim.dev>
-rw-r--r--lib/Federation/CloudFederationProviderTalk.php11
-rw-r--r--lib/Federation/FederationManager.php4
-rw-r--r--lib/Migration/Version13000Date20210625232111.php13
-rw-r--r--lib/Model/Attendee.php7
-rw-r--r--lib/Model/AttendeeMapper.php1
-rw-r--r--lib/Model/Invitation.php7
-rw-r--r--lib/Model/InvitationMapper.php7
-rw-r--r--lib/Service/ParticipantService.php3
8 files changed, 44 insertions, 9 deletions
diff --git a/lib/Federation/CloudFederationProviderTalk.php b/lib/Federation/CloudFederationProviderTalk.php
index 1bd555458..3e89bda07 100644
--- a/lib/Federation/CloudFederationProviderTalk.php
+++ b/lib/Federation/CloudFederationProviderTalk.php
@@ -117,13 +117,14 @@ class CloudFederationProviderTalk implements ICloudFederationProvider {
}
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 @@ class CloudFederationProviderTalk implements ICloudFederationProvider {
$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 00dbbb7aa..691d83a6c 100644
--- a/lib/Federation/FederationManager.php
+++ b/lib/Federation/FederationManager.php
@@ -90,7 +90,7 @@ class FederationManager {
* @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 @@ class FederationManager {
$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 @@ class FederationManager {
'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 fc3514462..3f19a546c 100644
--- a/lib/Migration/Version13000Date20210625232111.php
+++ b/lib/Migration/Version13000Date20210625232111.php
@@ -49,6 +49,14 @@ class Version13000Date20210625232111 extends SimpleMigrationStep {
$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 @@ class Version13000Date20210625232111 extends SimpleMigrationStep {
]);
$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 9d1ccb0f2..e0de04da1 100644
--- a/lib/Model/Attendee.php
+++ b/lib/Model/Attendee.php
@@ -53,6 +53,8 @@ use OCP\AppFramework\Db\Entity;
* @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';
@@ -111,6 +113,9 @@ class Attendee extends Entity {
/** @var string */
protected $accessToken;
+ /** @var string */
+ protected $remoteId;
+
public function __construct() {
$this->addType('roomId', 'int');
$this->addType('actorType', 'string');
@@ -126,6 +131,7 @@ class Attendee extends Entity {
$this->addType('readPrivacy', 'int');
$this->addType('publishingPermissions', 'int');
$this->addType('accessToken', 'string');
+ $this->addType('remote_id', 'string');
}
public function getDisplayName(): string {
@@ -152,6 +158,7 @@ class Attendee extends Entity {
'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 cbf6f0393..9a57c7887 100644
--- a/lib/Model/AttendeeMapper.php
+++ b/lib/Model/AttendeeMapper.php
@@ -175,6 +175,7 @@ class AttendeeMapper extends QBMapper {
'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 cf2a591e0..8ba075615 100644
--- a/lib/Model/Invitation.php
+++ b/lib/Model/Invitation.php
@@ -38,6 +38,8 @@ use OCP\AppFramework\Db\Entity;
* @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 @@ class Invitation extends Entity {
'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 2a453a2a0..f54cbafd8 100644
--- a/lib/Model/InvitationMapper.php
+++ b/lib/Model/InvitationMapper.php
@@ -97,9 +97,10 @@ class InvitationMapper extends QBMapper {
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 18e2698f1..673c1f157 100644
--- a/lib/Service/ParticipantService.php
+++ b/lib/Service/ParticipantService.php
@@ -329,6 +329,9 @@ class ParticipantService {
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);