Skip to content

Commit

Permalink
feat(federation): Add inviter information to the invitations DB for s…
Browse files Browse the repository at this point in the history
…erving

Signed-off-by: Joas Schilling <coding@schilljs.com>
  • Loading branch information
nickvergessen committed Feb 12, 2024
1 parent 7412cf4 commit 59ae78b
Show file tree
Hide file tree
Showing 8 changed files with 107 additions and 11 deletions.
2 changes: 1 addition & 1 deletion appinfo/info.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ And in the works for the [coming versions](https://github.com/nextcloud/spreed/m
]]></description>

<version>19.0.0-dev.0</version>
<version>19.0.0-dev.1</version>
<licence>agpl</licence>

<author>Daniel Calviño Sánchez</author>
Expand Down
14 changes: 7 additions & 7 deletions lib/Federation/CloudFederationProviderTalk.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,20 +121,20 @@ public function shareReceived(ICloudFederationShare $share): string {
$roomToken = $share->getResourceName();
$roomName = $share->getProtocol()['roomName'];
$roomType = (int) $roomType;
$sharedBy = $share->getSharedByDisplayName();
$sharedByDisplayName = $share->getSharedByDisplayName();
$sharedByFederatedId = $share->getSharedBy();
$owner = $share->getOwnerDisplayName();
$ownerDisplayName = $share->getOwnerDisplayName();
$ownerFederatedId = $share->getOwner();
[, $remote] = $this->addressHandler->splitUserRemote($ownerFederatedId);

// if no explicit information about the person who created the share was send
// if no explicit information about the person who created the share was sent
// we assume that the share comes from the owner
if ($sharedByFederatedId === null) {
$sharedBy = $owner;
$sharedByDisplayName = $ownerDisplayName;
$sharedByFederatedId = $ownerFederatedId;
}

if ($remote && $shareSecret && $shareWith && $roomToken && $remoteId && is_string($roomName) && $roomName && $owner) {
if ($remote && $shareSecret && $shareWith && $roomToken && $remoteId && is_string($roomName) && $roomName && $ownerDisplayName) {
$shareWith = $this->userManager->get($shareWith);
if ($shareWith === null) {
$this->logger->debug('Received a federation invite for user that could not be found');
Expand All @@ -151,9 +151,9 @@ public function shareReceived(ICloudFederationShare $share): string {
throw new ProviderCouldNotAddShareException('User does not exist', '', Http::STATUS_BAD_REQUEST);
}

$invite = $this->federationManager->addRemoteRoom($shareWith, (int) $remoteId, $roomType, $roomName, $roomToken, $remote, $shareSecret);
$invite = $this->federationManager->addRemoteRoom($shareWith, (int) $remoteId, $roomType, $roomName, $roomToken, $remote, $shareSecret, $sharedByFederatedId, $sharedByDisplayName);

$this->notifyAboutNewShare($shareWith, (string) $invite->getId(), $sharedByFederatedId, $sharedBy, $roomName, $roomToken, $remote);
$this->notifyAboutNewShare($shareWith, (string) $invite->getId(), $sharedByFederatedId, $sharedByDisplayName, $roomName, $roomToken, $remote);
return (string) $invite->getId();
}

Expand Down
4 changes: 4 additions & 0 deletions lib/Federation/FederationManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ public function addRemoteRoom(
string $remoteServerUrl,
#[SensitiveParameter]
string $sharedSecret,
string $inviterFederatedId,
string $inviterDisplayName,
): Invitation {
try {
$room = $this->manager->getRoomByToken($remoteToken, null, $remoteServerUrl);
Expand All @@ -92,6 +94,8 @@ public function addRemoteRoom(
$invitation->setRemoteServerUrl($remoteServerUrl);
$invitation->setRemoteToken($remoteToken);
$invitation->setRemoteAttendeeId($remoteAttendeeId);
$invitation->setInviterFederatedId($inviterFederatedId);
$invitation->setInviterDisplayName($inviterDisplayName);
$this->invitationMapper->insert($invitation);

return $invitation;
Expand Down
64 changes: 64 additions & 0 deletions lib/Migration/Version19000Date20240212155937.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<?php

declare(strict_types=1);

/**
* @copyright Copyright (c) Joas Schilling <coding@schilljs.com>
*
* @author Joas Schilling <coding@schilljs.com>
*
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/

namespace OCA\Talk\Migration;

use Closure;
use OCP\DB\ISchemaWrapper;
use OCP\DB\Types;
use OCP\Migration\IOutput;
use OCP\Migration\SimpleMigrationStep;

/**
* Add inviter information to the invites for rendering them outside of notifications later
*/
class Version19000Date20240212155937 extends SimpleMigrationStep {
/**
* @param IOutput $output
* @param Closure(): ISchemaWrapper $schemaClosure
* @param array $options
* @return null|ISchemaWrapper
*/
public function changeSchema(IOutput $output, Closure $schemaClosure, array $options): ?ISchemaWrapper {
/** @var ISchemaWrapper $schema */
$schema = $schemaClosure();

$table = $schema->getTable('talk_invitations');
if (!$table->hasColumn('inviter_user_id')) {
$table->addColumn('inviter_user_id', Types::STRING, [
'notnull' => false,
'length' => 255,
]);
$table->addColumn('inviter_display_name', Types::STRING, [
'notnull' => false,
'length' => 255,
]);
return $schema;
}

return null;
}
}
12 changes: 11 additions & 1 deletion lib/Model/Invitation.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@
* @method string getRemoteToken()
* @method void setRemoteAttendeeId(int $remoteAttendeeId)
* @method int getRemoteAttendeeId()
* @method void setInviterFederatedId(string $inviterFederatedId)
* @method string getInviterFederatedId()
* @method void setInviterDisplayName(string $inviterDisplayName)
* @method string getInviterDisplayName()
*/
class Invitation extends Entity implements \JsonSerializable {
public const STATE_PENDING = 0;
Expand All @@ -55,6 +59,8 @@ class Invitation extends Entity implements \JsonSerializable {
protected string $remoteServerUrl = '';
protected string $remoteToken = '';
protected int $remoteAttendeeId = 0;
protected string $inviterFederatedId = '';
protected string $inviterDisplayName = '';

public function __construct() {
$this->addType('userId', 'string');
Expand All @@ -64,10 +70,12 @@ public function __construct() {
$this->addType('remoteServerUrl', 'string');
$this->addType('remoteToken', 'string');
$this->addType('remoteAttendeeId', 'int');
$this->addType('inviterFederatedId', 'string');
$this->addType('inviterDisplayName', 'string');
}

/**
* @return array{accessToken: string, id: int, localRoomId: int, remoteAttendeeId: int, remoteServerUrl: string, remoteToken: string, state: int, userId: string}
* @return array{accessToken: string, id: int, localRoomId: int, remoteAttendeeId: int, remoteServerUrl: string, remoteToken: string, state: int, userId: string, inviterFederatedId: string, inviterDisplayName: string}
*/
public function jsonSerialize(): array {
return [
Expand All @@ -79,6 +87,8 @@ public function jsonSerialize(): array {
'remoteServerUrl' => $this->getRemoteServerUrl(),
'remoteToken' => $this->getRemoteToken(),
'remoteAttendeeId' => $this->getRemoteAttendeeId(),
'inviterFederatedId' => $this->getInviterFederatedId(),
'inviterDisplayName' => $this->getInviterDisplayName() ?: $this->getInviterFederatedId(),
];
}
}
2 changes: 2 additions & 0 deletions lib/ResponseDefinitions.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,8 @@
* remoteToken: string,
* roomName: string,
* userId: string,
* inviterFederatedId: string,
* inviterDisplayName: string,
* }
*
* @psalm-type TalkMatterbridgeConfigFields = array<array<string, mixed>>
Expand Down
10 changes: 9 additions & 1 deletion openapi-federation.json
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,9 @@
"remoteServerUrl",
"remoteToken",
"roomName",
"userId"
"userId",
"inviterFederatedId",
"inviterDisplayName"
],
"properties": {
"accessToken": {
Expand Down Expand Up @@ -166,6 +168,12 @@
},
"userId": {
"type": "string"
},
"inviterFederatedId": {
"type": "string"
},
"inviterDisplayName": {
"type": "string"
}
}
},
Expand Down
10 changes: 9 additions & 1 deletion openapi-full.json
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,9 @@
"remoteServerUrl",
"remoteToken",
"roomName",
"userId"
"userId",
"inviterFederatedId",
"inviterDisplayName"
],
"properties": {
"accessToken": {
Expand Down Expand Up @@ -363,6 +365,12 @@
},
"userId": {
"type": "string"
},
"inviterFederatedId": {
"type": "string"
},
"inviterDisplayName": {
"type": "string"
}
}
},
Expand Down

0 comments on commit 59ae78b

Please sign in to comment.