Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/spreed.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/lib/Model
diff options
context:
space:
mode:
authorGary Kim <gary@garykim.dev>2021-06-11 06:35:54 +0300
committerGary Kim <gary@garykim.dev>2021-07-15 20:54:35 +0300
commita35b98f8c15e19bde6098081b41e544e95e4b532 (patch)
treea9af9784cd16ae1c4321c8c29e1ab8996db57196 /lib/Model
parentddda9be34bd14f8ccf14521a6e100870493cd4b3 (diff)
Implement CloudFederationProvider for Talk
Signed-off-by: Gary Kim <gary@garykim.dev>
Diffstat (limited to 'lib/Model')
-rw-r--r--lib/Model/Attendee.php10
-rw-r--r--lib/Model/AttendeeMapper.php24
-rw-r--r--lib/Model/Invitation.php66
-rw-r--r--lib/Model/InvitationMapper.php105
-rw-r--r--lib/Model/SelectHelper.php2
5 files changed, 205 insertions, 2 deletions
diff --git a/lib/Model/Attendee.php b/lib/Model/Attendee.php
index 6f7b083a5..0591d1dac 100644
--- a/lib/Model/Attendee.php
+++ b/lib/Model/Attendee.php
@@ -27,7 +27,7 @@ use OCP\AppFramework\Db\Entity;
/**
* @method void setRoomId(int $roomId)
- * @method string getRoomId()
+ * @method int getRoomId()
* @method void setActorType(string $actorType)
* @method string getActorType()
* @method void setActorId(string $actorId)
@@ -51,6 +51,8 @@ use OCP\AppFramework\Db\Entity;
* @method int getReadPrivacy()
* @method void setPublishingPermissions(int $publishingPermissions)
* @method int getPublishingPermissions()
+ * @method void setAccessToken(string $accessToken)
+ * @method null|string getAccessToken()
*/
class Attendee extends Entity {
public const ACTOR_USERS = 'users';
@@ -59,6 +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 PUBLISHING_PERMISSIONS_NONE = 0;
public const PUBLISHING_PERMISSIONS_AUDIO = 1;
@@ -105,6 +108,9 @@ class Attendee extends Entity {
/** @var int */
protected $publishingPermissions;
+ /** @var string */
+ protected $accessToken;
+
public function __construct() {
$this->addType('roomId', 'int');
$this->addType('actorType', 'string');
@@ -119,6 +125,7 @@ class Attendee extends Entity {
$this->addType('lastMentionMessage', 'int');
$this->addType('readPrivacy', 'int');
$this->addType('publishingPermissions', 'int');
+ $this->addType('accessToken', 'string');
}
public function getDisplayName(): string {
@@ -144,6 +151,7 @@ class Attendee extends Entity {
'last_mention_message' => $this->getLastMentionMessage(),
'read_privacy' => $this->getReadPrivacy(),
'publishing_permissions' => $this->getPublishingPermissions(),
+ 'access_token' => $this->getAccessToken(),
];
}
}
diff --git a/lib/Model/AttendeeMapper.php b/lib/Model/AttendeeMapper.php
index 3e8586389..cbf6f0393 100644
--- a/lib/Model/AttendeeMapper.php
+++ b/lib/Model/AttendeeMapper.php
@@ -23,12 +23,17 @@ declare(strict_types=1);
namespace OCA\Talk\Model;
+use OCP\AppFramework\Db\DoesNotExistException;
+use OCP\AppFramework\Db\MultipleObjectsReturnedException;
use OCP\AppFramework\Db\QBMapper;
+use OCP\DB\Exception as DBException;
use OCP\DB\QueryBuilder\IQueryBuilder;
use OCP\IDBConnection;
/**
* @method Attendee mapRowToEntity(array $row)
+ * @method Attendee findEntity(IQueryBuilder $query)
+ * @method Attendee[] findEntities(IQueryBuilder $query)
*/
class AttendeeMapper extends QBMapper {
@@ -44,7 +49,7 @@ class AttendeeMapper extends QBMapper {
* @param string $actorType
* @param string $actorId
* @return Attendee
- * @throws \OCP\AppFramework\Db\DoesNotExistException
+ * @throws DoesNotExistException
*/
public function findByActor(int $roomId, string $actorType, string $actorId): Attendee {
$query = $this->db->getQueryBuilder();
@@ -58,6 +63,22 @@ class AttendeeMapper extends QBMapper {
}
/**
+ * @param int $id
+ * @return Attendee
+ * @throws DoesNotExistException
+ * @throws MultipleObjectsReturnedException
+ * @throws DBException
+ */
+ public function getById(int $id): Attendee {
+ $query = $this->db->getQueryBuilder();
+ $query->select('*')
+ ->from($this->getTableName())
+ ->where($query->expr()->eq('id', $query->createNamedParameter($id)));
+
+ return $this->findEntity($query);
+ }
+
+ /**
* @param int $roomId
* @param string $actorType
* @param int|null $lastJoinedCall
@@ -153,6 +174,7 @@ class AttendeeMapper extends QBMapper {
'last_mention_message' => (int) $row['last_mention_message'],
'read_privacy' => (int) $row['read_privacy'],
'publishing_permissions' => (int) $row['publishing_permissions'],
+ 'access_token' => (string) $row['access_token'],
]);
}
}
diff --git a/lib/Model/Invitation.php b/lib/Model/Invitation.php
new file mode 100644
index 000000000..cf2a591e0
--- /dev/null
+++ b/lib/Model/Invitation.php
@@ -0,0 +1,66 @@
+<?php
+
+declare(strict_types=1);
+/**
+ * @copyright Copyright (c) 2021 Gary Kim <gary@garykim.dev>
+ *
+ * @author Gary Kim <gary@garykim.dev>
+ *
+ * @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\Model;
+
+use OCP\AppFramework\Db\Entity;
+
+/**
+ * Class Invitation
+ *
+ * @package OCA\Talk\Model
+ *
+ * @method void setRoomId(int $roomId)
+ * @method int getRoomId()
+ * @method void setUserId(string $userId)
+ * @method string getUserId()
+ * @method void setAccessToken(string $accessToken)
+ * @method string getAccessToken()
+ */
+class Invitation extends Entity {
+ /** @var int */
+ protected $roomId;
+
+ /** @var string */
+ protected $userId;
+
+ /** @var string */
+ protected $accessToken;
+
+ public function __construct() {
+ $this->addType('roomId', 'int');
+ $this->addType('userId', 'string');
+ $this->addType('accessToken', 'string');
+ }
+
+ public function asArray(): array {
+ return [
+ 'id' => $this->getId(),
+ 'room_id' => $this->getRoomId(),
+ 'user_id' => $this->getUserId(),
+ 'access_token' => $this->getAccessToken(),
+ ];
+ }
+}
diff --git a/lib/Model/InvitationMapper.php b/lib/Model/InvitationMapper.php
new file mode 100644
index 000000000..2a453a2a0
--- /dev/null
+++ b/lib/Model/InvitationMapper.php
@@ -0,0 +1,105 @@
+<?php
+
+declare(strict_types=1);
+/**
+ * @copyright Copyright (c) 2021 Gary Kim <gary@garykim.dev>
+ *
+ * @author Gary Kim <gary@garykim.dev>
+ *
+ * @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\Model;
+
+use OCA\Talk\Room;
+use OCP\AppFramework\Db\DoesNotExistException;
+use OCP\AppFramework\Db\MultipleObjectsReturnedException;
+use OCP\AppFramework\Db\QBMapper;
+use OCP\DB\Exception as DBException;
+use OCP\DB\QueryBuilder\IQueryBuilder;
+use OCP\IDBConnection;
+
+/**
+ * Class InvitationMapper
+ *
+ * @package OCA\Talk\Model
+ *
+ * @method Invitation mapRowToEntity(array $row)
+ * @method Invitation findEntity(IQueryBuilder $query)
+ * @method Invitation[] findEntities(IQueryBuilder $query)
+ */
+class InvitationMapper extends QBMapper {
+ public function __construct(IDBConnection $db) {
+ parent::__construct($db, 'talk_invitations', Invitation::class);
+ }
+
+ /**
+ * @throws DBException
+ * @throws MultipleObjectsReturnedException
+ * @throws DoesNotExistException
+ */
+ public function getInvitationById(int $id): Invitation {
+ $qb = $this->db->getQueryBuilder();
+
+ $qb->select('*')
+ ->from($this->getTableName())
+ ->where($qb->expr()->eq('id', $qb->createNamedParameter($id)));
+
+ return $this->findEntity($qb);
+ }
+
+ /**
+ * @param Room $room
+ * @return Invitation[]
+ * @throws DBException
+ */
+ public function getInvitationsForRoom(Room $room): array {
+ $qb = $this->db->getQueryBuilder();
+
+ $qb->select('*')
+ ->from($this->getTableName())
+ ->where($qb->expr()->eq('room_id', $qb->createNamedParameter($room->getId())));
+
+ return $this->findEntities($qb);
+ }
+
+ /**
+ * @throws DBException
+ */
+ public function countInvitationsForRoom(Room $room): int {
+ $qb = $this->db->getQueryBuilder();
+
+ $qb->select($qb->func()->count('*', 'num_invitations'))
+ ->from($this->getTableName())
+ ->where($qb->expr()->eq('room_id', $qb->createNamedParameter($room->getId())));
+
+ $result = $qb->executeQuery();
+ $row = $result->fetch();
+ $result->closeCursor();
+
+ return (int) ($row['num_invitations' ?? 0]);
+ }
+
+ 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'],
+ ]);
+ }
+}
diff --git a/lib/Model/SelectHelper.php b/lib/Model/SelectHelper.php
index dfcab988a..0730329fd 100644
--- a/lib/Model/SelectHelper.php
+++ b/lib/Model/SelectHelper.php
@@ -49,6 +49,7 @@ class SelectHelper {
->addSelect($alias . 'object_type')
->addSelect($alias . 'object_id')
->addSelect($alias . 'listable')
+ ->addSelect($alias . 'server_url')
->selectAlias($alias . 'id', 'r_id');
}
@@ -70,6 +71,7 @@ class SelectHelper {
->addSelect($alias . 'last_mention_message')
->addSelect($alias . 'read_privacy')
->addSelect($alias . 'publishing_permissions')
+ ->addSelect($alias . 'access_token')
->selectAlias($alias . 'id', 'a_id');
}