Skip to content

Commit 081d2b9

Browse files
authored
Merge pull request #1 from arawa/task/2919/room_shared_list_for_moderators_and_users
feat: list all shared rooms for users and moderators
2 parents 5935c09 + 9538c35 commit 081d2b9

File tree

2 files changed

+18
-16
lines changed

2 files changed

+18
-16
lines changed

lib/Db/Room.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ class Room extends Entity implements JsonSerializable {
7474
public $cleanLayout;
7575
public $joinMuted;
7676
public $running;
77+
public $permission;
7778

7879
public function __construct() {
7980
$this->addType('maxParticipants', 'integer');
@@ -86,6 +87,7 @@ public function __construct() {
8687
$this->addType('cleanLayout', 'boolean');
8788
$this->addType('joinMuted', 'boolean');
8889
$this->addType('running', 'boolean');
90+
$this->addType('permission', 'integer');
8991
}
9092

9193
public function jsonSerialize(): array {
@@ -102,6 +104,7 @@ public function jsonSerialize(): array {
102104
'everyoneIsModerator' => boolval($this->everyoneIsModerator),
103105
'requireModerator' => boolval($this->requireModerator),
104106
'shared' => boolval($this->shared),
107+
'permission' => $this->permission,
105108
'moderatorToken' => $this->moderatorToken,
106109
'listenOnly' => boolval($this->listenOnly),
107110
'mediaCheck' => boolval($this->mediaCheck),

lib/Db/RoomMapper.php

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,24 @@ public function __construct(IDBConnection $db) {
1212
parent::__construct($db, 'bbb_rooms', Room::class);
1313
}
1414

15+
private function joinShares(IQueryBuilder $qb): IQueryBuilder {
16+
$qb->select('r.*')
17+
->from($this->tableName, 'r')
18+
->leftJoin('r', 'bbb_room_shares', 's', $qb->expr()->eq('r.id', 's.room_id'))
19+
->addSelect($qb->createFunction('count(case when `s`.`permission` IN ('.
20+
RoomShare::PERMISSION_ADMIN.','.RoomShare::PERMISSION_MODERATOR.','.RoomShare::PERMISSION_USER
21+
.') then 1 else null end) as shared'));
22+
return $qb;
23+
}
24+
1525
/**
1626
* @throws \OCP\AppFramework\Db\MultipleObjectsReturnedException
1727
* @throws DoesNotExistException
1828
*/
1929
public function find(int $id): Room {
2030
/* @var $qb IQueryBuilder */
2131
$qb = $this->db->getQueryBuilder();
22-
$qb->select('r.*')
23-
->from($this->tableName, 'r')
24-
->leftJoin('r', 'bbb_room_shares', 's', $qb->expr()->eq('r.id', 's.room_id'))
25-
->addSelect($qb->createFunction('count(case when `s`.`permission` = 0 then 1 else null end) as shared'))
32+
$this->joinShares($qb)
2633
->where($qb->expr()->eq('r.id', $qb->createNamedParameter($id, IQueryBuilder::PARAM_INT)))
2734
->groupBy('r.id');
2835
;
@@ -38,10 +45,7 @@ public function find(int $id): Room {
3845
public function findByUid(string $uid): Room {
3946
/* @var $qb IQueryBuilder */
4047
$qb = $this->db->getQueryBuilder();
41-
$qb->select('r.*')
42-
->from($this->tableName, 'r')
43-
->leftJoin('r', 'bbb_room_shares', 's', $qb->expr()->eq('r.id', 's.room_id'))
44-
->addSelect($qb->createFunction('count(case when `s`.`permission` = 0 then 1 else null end) as shared'))
48+
$this->joinShares($qb)
4549
->where($qb->expr()->eq('r.uid', $qb->createNamedParameter($uid)))
4650
->groupBy('r.id');
4751
;
@@ -70,25 +74,20 @@ public function findByUserId(string $userId): array {
7074
public function findAll(string $userId, array $groupIds, array $circleIds): array {
7175
/* @var $qb IQueryBuilder */
7276
$qb = $this->db->getQueryBuilder();
73-
$qb->select('r.*')
74-
->from($this->tableName, 'r')
75-
->leftJoin('r', 'bbb_room_shares', 's', $qb->expr()->eq('r.id', 's.room_id'))
76-
->addSelect($qb->createFunction('count(case when `s`.`permission` = 0 then 1 else null end) as shared'))
77+
$this->joinShares($qb)
78+
->addSelect($qb->createFunction('min(case when '.$qb->expr()->eq('r.user_id', $qb->createNamedParameter($userId)).' then '.RoomShare::PERMISSION_ADMIN.' else `s`.`permission` end) as permission'))
7779
->where(
7880
$qb->expr()->orX(
7981
$qb->expr()->eq('r.user_id', $qb->createNamedParameter($userId)),
8082
$qb->expr()->andX(
81-
$qb->expr()->eq('s.permission', $qb->createNamedParameter(RoomShare::PERMISSION_ADMIN, IQueryBuilder::PARAM_INT)),
8283
$qb->expr()->eq('s.share_type', $qb->createNamedParameter(RoomShare::SHARE_TYPE_USER, IQueryBuilder::PARAM_INT)),
8384
$qb->expr()->eq('s.share_with', $qb->createNamedParameter($userId))
8485
),
8586
$qb->expr()->andX(
86-
$qb->expr()->eq('s.permission', $qb->createNamedParameter(RoomShare::PERMISSION_ADMIN, IQueryBuilder::PARAM_INT)),
8787
$qb->expr()->eq('s.share_type', $qb->createNamedParameter(RoomShare::SHARE_TYPE_GROUP, IQueryBuilder::PARAM_INT)),
8888
$qb->expr()->in('s.share_with', $qb->createNamedParameter($groupIds, IQueryBuilder::PARAM_STR_ARRAY))
8989
),
9090
$qb->expr()->andX(
91-
$qb->expr()->eq('s.permission', $qb->createNamedParameter(RoomShare::PERMISSION_ADMIN, IQueryBuilder::PARAM_INT)),
9291
$qb->expr()->eq('s.share_type', $qb->createNamedParameter(RoomShare::SHARE_TYPE_CIRCLE, IQueryBuilder::PARAM_INT)),
9392
$qb->expr()->in('s.share_with', $qb->createNamedParameter($circleIds, IQueryBuilder::PARAM_STR_ARRAY))
9493
)
@@ -99,7 +98,7 @@ public function findAll(string $userId, array $groupIds, array $circleIds): arra
9998
/** @var array<Room> */
10099
return $this->findEntities($qb);
101100
}
102-
101+
103102
/**
104103
* @return array<Room>
105104
*/

0 commit comments

Comments
 (0)