Browse Source

Review fixes

Signed-off-by: Gary Kim <gary@garykim.dev>
pull/5775/head
Gary Kim 4 years ago
parent
commit
c49a1c2754
  1. 4
      appinfo/routes.php
  2. 11
      lib/Federation/CloudFederationProviderTalk.php
  3. 3
      lib/Federation/FederationManager.php
  4. 6
      lib/Manager.php
  5. 67
      lib/Migration/Version13000Date20210625232111.php
  6. 2
      lib/Model/Attendee.php
  7. 23
      lib/Notification/Notifier.php

4
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',

11
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) {

3
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";
}
/**

6
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) {

67
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;
}

2
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;

23
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;
}

Loading…
Cancel
Save