summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGary Kim <gary@garykim.dev>2021-07-02 17:11:10 -0400
committerGary Kim <gary@garykim.dev>2021-07-15 13:55:19 -0400
commitc49a1c27544ab0a4014a2ff385285d2bb556e5e6 (patch)
tree4042f64913e3615429e77e9c4cfba848f6ad0ef0
parent5219c0deb24dfccb11794447da52bddfeb3d9cc9 (diff)
Review fixes
Signed-off-by: Gary Kim <gary@garykim.dev>
-rw-r--r--appinfo/routes.php4
-rw-r--r--lib/Federation/CloudFederationProviderTalk.php11
-rw-r--r--lib/Federation/FederationManager.php3
-rw-r--r--lib/Manager.php6
-rw-r--r--lib/Migration/Version13000Date20210625232111.php67
-rw-r--r--lib/Model/Attendee.php2
-rw-r--r--lib/Notification/Notifier.php23
7 files changed, 61 insertions, 55 deletions
diff --git a/appinfo/routes.php b/appinfo/routes.php
index d06380a6c..59143fd5c 100644
--- a/appinfo/routes.php
+++ b/appinfo/routes.php
@@ -529,7 +529,7 @@ return [
[
'name' => 'Federation#acceptShare',
- 'url' => 'api/{apiVersion}/federation/pending/{id}',
+ 'url' => 'api/{apiVersion}/federation/invitation/{id}',
'verb' => 'POST',
'requirements' => [
'apiVersion' => 'v1',
@@ -537,7 +537,7 @@ return [
],
[
'name' => 'Federation#rejectShare',
- 'url' => 'api/{apiVersion}/federation/pending/{id}',
+ 'url' => 'api/{apiVersion}/federation/invitation/{id}',
'verb' => 'DELETE',
'requirements' => [
'apiVersion' => 'v1',
diff --git a/lib/Federation/CloudFederationProviderTalk.php b/lib/Federation/CloudFederationProviderTalk.php
index 909b09e34..1bd555458 100644
--- a/lib/Federation/CloudFederationProviderTalk.php
+++ b/lib/Federation/CloudFederationProviderTalk.php
@@ -26,13 +26,13 @@ declare(strict_types=1);
namespace OCA\Talk\Federation;
use Exception;
-use OC\HintException;
use OCA\FederatedFileSharing\AddressHandler;
use OCA\Talk\AppInfo\Application;
use OCA\Talk\Manager;
use OCA\Talk\Model\Attendee;
use OCA\Talk\Model\AttendeeMapper;
use OCA\Talk\Participant;
+use OCA\Talk\Room;
use OCA\Talk\Service\ParticipantService;
use OCP\AppFramework\Http;
use OCP\DB\Exception as DBException;
@@ -42,6 +42,7 @@ use OCP\Federation\Exceptions\BadRequestException;
use OCP\Federation\Exceptions\ProviderCouldNotAddShareException;
use OCP\Federation\ICloudFederationProvider;
use OCP\Federation\ICloudFederationShare;
+use OCP\HintException;
use OCP\IURLGenerator;
use OCP\IUser;
use OCP\IUserManager;
@@ -110,8 +111,8 @@ class CloudFederationProviderTalk implements ICloudFederationProvider {
if (!$this->federationManager->isEnabled()) {
throw new ProviderCouldNotAddShareException('Server does not support talk federation', '', Http::STATUS_SERVICE_UNAVAILABLE);
}
- if ($share->getShareType() !== 'user') {
- throw new ProviderCouldNotAddShareException('support for sharing with non-users not implemented yet', '', Http::STATUS_NOT_IMPLEMENTED);
+ if (!in_array($share->getShareType(), $this->getSupportedShareTypes(), true)) {
+ throw new ProviderCouldNotAddShareException('Support for sharing with non-users not implemented yet', '', Http::STATUS_NOT_IMPLEMENTED);
// TODO: Implement group shares
}
@@ -199,7 +200,7 @@ class CloudFederationProviderTalk implements ICloudFederationProvider {
$room = $this->manager->getRoomById($attendee->getRoomId());
$participant = new Participant($room, $attendee, null);
- $this->participantService->removeAttendee($room, $participant, 'Left Room');
+ $this->participantService->removeAttendee($room, $participant, Room::PARTICIPANT_LEFT);
return [];
}
@@ -218,7 +219,7 @@ class CloudFederationProviderTalk implements ICloudFederationProvider {
} catch (Exception $ex) {
throw new ShareNotFound();
}
- if ($attendee->getActorType() !== Attendee::ACTOR_FEDERATED_REMOTE_USER) {
+ if ($attendee->getActorType() !== Attendee::ACTOR_FEDERATED_USERS) {
throw new ShareNotFound();
}
if ($attendee->getAccessToken() !== $sharedSecret) {
diff --git a/lib/Federation/FederationManager.php b/lib/Federation/FederationManager.php
index 58336478c..00dbbb7aa 100644
--- a/lib/Federation/FederationManager.php
+++ b/lib/Federation/FederationManager.php
@@ -25,6 +25,7 @@ declare(strict_types=1);
namespace OCA\Talk\Federation;
+use OCA\Talk\AppInfo\Application;
use OCA\Talk\Exceptions\RoomNotFoundException;
use OCA\Talk\Exceptions\UnauthorizedException;
use OCA\Talk\Manager;
@@ -76,7 +77,7 @@ class FederationManager {
*/
public function isEnabled(): bool {
// TODO: Set to default true once implementation is complete
- return $this->config->getSystemValueBool('talk_federation_enabled', false);
+ return $this->config->getAppValue(Application::APP_ID, 'federation_enabled', "false") === "true";
}
/**
diff --git a/lib/Manager.php b/lib/Manager.php
index 044c6d3e3..ecbfdd8cd 100644
--- a/lib/Manager.php
+++ b/lib/Manager.php
@@ -630,7 +630,7 @@ class Manager {
* @return Room
* @throws RoomNotFoundException
*/
- public function getRoomByActor(string $token, string $actorType, string $actorId, ?string $sessionId = null, ?string $server_url = null): Room {
+ public function getRoomByActor(string $token, string $actorType, string $actorId, ?string $sessionId = null, ?string $serverUrl = null): Room {
$query = $this->db->getQueryBuilder();
$helper = new SelectHelper();
$helper->selectRoomsTable($query);
@@ -643,10 +643,10 @@ class Manager {
))
->where($query->expr()->eq('r.token', $query->createNamedParameter($token)));
- if ($server_url === null) {
+ if ($serverUrl === null) {
$query->andWhere($query->expr()->isNull('r.server_url'));
} else {
- $query->andWhere($query->expr()->eq('r.server_url', $query->createNamedParameter($server_url)));
+ $query->andWhere($query->expr()->eq('r.server_url', $query->createNamedParameter($serverUrl)));
}
if ($sessionId !== null) {
diff --git a/lib/Migration/Version13000Date20210625232111.php b/lib/Migration/Version13000Date20210625232111.php
index 437a785d7..fc3514462 100644
--- a/lib/Migration/Version13000Date20210625232111.php
+++ b/lib/Migration/Version13000Date20210625232111.php
@@ -44,44 +44,45 @@ class Version13000Date20210625232111 extends SimpleMigrationStep {
/** @var ISchemaWrapper $schema */
$schema = $schemaClosure();
- if ($schema->hasTable('talk_attendees')) {
- $table = $schema->getTable('talk_attendees');
- if (!$table->hasColumn('access_token')) {
- $table->addColumn('access_token', Types::STRING, [
- 'notnull' => false,
- 'default' => null,
- ]);
- }
+ $table = $schema->getTable('talk_attendees');
+ if (!$table->hasColumn('access_token')) {
+ $table->addColumn('access_token', Types::STRING, [
+ 'notnull' => false,
+ 'default' => null,
+ ]);
}
- if ($schema->hasTable('talk_rooms')) {
- $table = $schema->getTable('talk_rooms');
- if (!$table->hasColumn('server_url')) {
- $table->addColumn('server_url', Types::STRING, [
- 'notnull' => false,
- 'default' => null,
- ]);
- }
+ $table = $schema->getTable('talk_rooms');
+ if (!$table->hasColumn('server_url')) {
+ $table->addColumn('server_url', Types::STRING, [
+ 'notnull' => false,
+ 'default' => null,
+ ]);
}
- $table = $schema->createTable('talk_invitations');
- $table->addColumn('id', Types::BIGINT, [
- 'autoincrement' => true,
- 'notnull' => true,
- ]);
- $table->addColumn('room_id', Types::BIGINT, [
- 'notnull' => true,
- 'unsigned' => true,
- ]);
- $table->addColumn('user_id', Types::STRING, [
- 'notnull' => true,
- 'length' => 255,
- ]);
- $table->addColumn('access_token', Types::STRING, [
- 'notnull' => true,
- ]);
+ if (!$schema->hasTable('talk_invitations')) {
+ $table = $schema->createTable('talk_invitations');
+ $table->addColumn('id', Types::BIGINT, [
+ 'autoincrement' => true,
+ 'notnull' => true,
+ ]);
+ $table->addColumn('room_id', Types::BIGINT, [
+ 'notnull' => true,
+ 'unsigned' => true,
+ ]);
+ $table->addColumn('user_id', Types::STRING, [
+ 'notnull' => true,
+ 'length' => 255,
+ ]);
+ $table->addColumn('access_token', Types::STRING, [
+ 'notnull' => true,
+ ]);
+
+ $table->setPrimaryKey(['id']);
+
+ $table->addIndex(['room_id']);
+ }
- $table->setPrimaryKey(['id']);
return $schema;
}
diff --git a/lib/Model/Attendee.php b/lib/Model/Attendee.php
index 0591d1dac..9d1ccb0f2 100644
--- a/lib/Model/Attendee.php
+++ b/lib/Model/Attendee.php
@@ -61,7 +61,7 @@ class Attendee extends Entity {
public const ACTOR_EMAILS = 'emails';
public const ACTOR_CIRCLES = 'circles';
public const ACTOR_BRIDGED = 'bridged';
- public const ACTOR_FEDERATED_REMOTE_USER = 'federated_remote';
+ public const ACTOR_FEDERATED_USERS = 'federated_users';
public const PUBLISHING_PERMISSIONS_NONE = 0;
public const PUBLISHING_PERMISSIONS_AUDIO = 1;
diff --git a/lib/Notification/Notifier.php b/lib/Notification/Notifier.php
index ab81dcf0f..a1607caad 100644
--- a/lib/Notification/Notifier.php
+++ b/lib/Notification/Notifier.php
@@ -23,7 +23,6 @@ declare(strict_types=1);
namespace OCA\Talk\Notification;
-use OC\HintException;
use OCA\FederatedFileSharing\AddressHandler;
use OCA\Talk\Chat\CommentsManager;
use OCA\Talk\Chat\MessageParser;
@@ -38,6 +37,7 @@ use OCA\Talk\Room;
use OCA\Talk\Service\ParticipantService;
use OCP\Comments\ICommentsManager;
use OCP\Comments\NotFoundException;
+use OCP\HintException;
use OCP\IL10N;
use OCP\IURLGenerator;
use OCP\IUser;
@@ -289,14 +289,8 @@ class Notifier implements INotifier {
[$sharedById, $sharedByServer] = $this->addressHandler->splitUserRemote($subjectParameters['sharedByFederatedId']);
$message = $l->t('{user1} shared room {roomName} on {remoteServer} with you');
- $parsedMessage = $l->t('{user1} shared room {roomName} on {remoteServer} with you', [
- 'user1' => $subjectParameters['sharedByFederatedId'],
- 'roomName' => $subjectParameters['roomName'],
- 'remoteServer' => $subjectParameters['serverUrl'],
- ]);
-
- $notification->setParsedMessage($parsedMessage);
- $notification->setRichMessage($message, [
+
+ $rosParameters = [
'user1' => [
'type' => 'user',
'id' => $sharedById,
@@ -313,7 +307,16 @@ class Notifier implements INotifier {
'id' => $subjectParameters['serverUrl'],
'name' => $subjectParameters['serverUrl'],
]
- ]);
+ ];
+
+ $placeholders = $replacements = [];
+ foreach ($rosParameters as $placeholder => $parameter) {
+ $placeholders[] = '{' . $placeholder .'}';
+ $replacements[] = $parameter['name'];
+ }
+
+ $notification->setParsedMessage(str_replace($placeholders, $replacements, $message));
+ $notification->setRichMessage($message, $rosParameters);
return $notification;
}