From 4203ee39872f6e713a29abc4cf45113cff9f0a00 Mon Sep 17 00:00:00 2001 From: sualko Date: Tue, 8 Sep 2020 17:01:50 +0200 Subject: [PATCH] feat: show room shared icon --- lib/Db/Room.php | 5 ++++- lib/Db/RoomMapper.php | 21 +++++++++++++++------ ts/Common/Api.ts | 1 + ts/Manager/EditRoomDialog.tsx | 8 ++++++++ ts/Manager/RoomRow.tsx | 1 + 5 files changed, 29 insertions(+), 7 deletions(-) diff --git a/lib/Db/Room.php b/lib/Db/Room.php index c4321e4..01141fe 100644 --- a/lib/Db/Room.php +++ b/lib/Db/Room.php @@ -54,12 +54,14 @@ class Room extends Entity implements JsonSerializable { public $password; public $everyoneIsModerator; public $requireModerator = false; + public $shared = false; public function __construct() { $this->addType('maxParticipants', 'integer'); $this->addType('record', 'boolean'); $this->addType('everyoneIsModerator', 'boolean'); $this->addType('requireModerator', 'boolean'); + $this->addType('shared', 'boolean'); } public function jsonSerialize(): array { @@ -74,7 +76,8 @@ class Room extends Entity implements JsonSerializable { 'access' => $this->access, 'password' => $this->password, 'everyoneIsModerator' => boolval($this->everyoneIsModerator), - 'requireModerator' => boolval($this->requireModerator), + 'requireModerator' => boolval($this->requireModerator), + 'shared' => boolval($this->shared), ]; } } diff --git a/lib/Db/RoomMapper.php b/lib/Db/RoomMapper.php index e2f6551..cac261e 100644 --- a/lib/Db/RoomMapper.php +++ b/lib/Db/RoomMapper.php @@ -19,9 +19,13 @@ class RoomMapper extends QBMapper { public function find(int $id): Room { /* @var $qb IQueryBuilder */ $qb = $this->db->getQueryBuilder(); - $qb->select('*') - ->from($this->tableName) - ->where($qb->expr()->eq('id', $qb->createNamedParameter($id, IQueryBuilder::PARAM_INT))); + $qb->select('r.*') + ->from($this->tableName, 'r') + ->leftJoin('r', 'bbb_room_shares', 's', $qb->expr()->eq('r.id', 's.room_id')) + ->addSelect($qb->createFunction('count(case when "s"."permission" = 0 then 1 else null end) as shared')) + ->where($qb->expr()->eq('r.id', $qb->createNamedParameter($id, IQueryBuilder::PARAM_INT))) + ->groupBy('r.id'); + ; /** @var Room */ return $this->findEntity($qb); @@ -34,9 +38,13 @@ class RoomMapper extends QBMapper { public function findByUid(string $uid): Room { /* @var $qb IQueryBuilder */ $qb = $this->db->getQueryBuilder(); - $qb->select('*') - ->from($this->tableName) - ->where($qb->expr()->eq('uid', $qb->createNamedParameter($uid))); + $qb->select('r.*') + ->from($this->tableName, 'r') + ->leftJoin('r', 'bbb_room_shares', 's', $qb->expr()->eq('r.id', 's.room_id')) + ->addSelect($qb->createFunction('count(case when "s"."permission" = 0 then 1 else null end) as shared')) + ->where($qb->expr()->eq('r.uid', $qb->createNamedParameter($uid))) + ->groupBy('r.id'); + ; /** @var Room */ return $this->findEntity($qb); @@ -51,6 +59,7 @@ class RoomMapper extends QBMapper { $qb->select('r.*') ->from($this->tableName, 'r') ->leftJoin('r', 'bbb_room_shares', 's', $qb->expr()->eq('r.id', 's.room_id')) + ->addSelect($qb->createFunction('count(case when "s"."permission" = 0 then 1 else null end) as shared')) ->where( $qb->expr()->orX( $qb->expr()->eq('r.user_id', $qb->createNamedParameter($userId)), diff --git a/ts/Common/Api.ts b/ts/Common/Api.ts index b223aec..f37ee18 100644 --- a/ts/Common/Api.ts +++ b/ts/Common/Api.ts @@ -37,6 +37,7 @@ export interface Room { password?: string; everyoneIsModerator: boolean; requireModerator: boolean; + shared: boolean; } export interface RoomShare { diff --git a/ts/Manager/EditRoomDialog.tsx b/ts/Manager/EditRoomDialog.tsx index c8ddb85..15b1a72 100644 --- a/ts/Manager/EditRoomDialog.tsx +++ b/ts/Manager/EditRoomDialog.tsx @@ -44,6 +44,14 @@ const EditRoomDialog: React.FC = ({ room, restriction, updateProperty, op }); }, [room.id, open]); + useEffect(() => { + if (!shares) { + return; + } + + updateProperty('shared', shares.filter(share => share.permission === Permission.Admin).length > 0); + }, [shares]); + function inputElement(label: string, field: string, type: 'text' | 'number' = 'text') { return (
diff --git a/ts/Manager/RoomRow.tsx b/ts/Manager/RoomRow.tsx index 9d77d72..30532f7 100644 --- a/ts/Manager/RoomRow.tsx +++ b/ts/Manager/RoomRow.tsx @@ -187,6 +187,7 @@ const RoomRow: React.FC = (props) => { {room.userId !== OC.currentUser && Avatar} + {(room.userId === OC.currentUser && room.shared) && } {edit('maxParticipants', 'number', {min: minParticipantsLimit, max: maxParticipantsLimit < 0 ? undefined : maxParticipantsLimit})}