feat: show room shared icon

pull/82/head
sualko 2020-09-08 17:01:50 +02:00
parent b5f03b5981
commit 4203ee3987
5 changed files with 29 additions and 7 deletions

View File

@ -54,12 +54,14 @@ class Room extends Entity implements JsonSerializable {
public $password; public $password;
public $everyoneIsModerator; public $everyoneIsModerator;
public $requireModerator = false; public $requireModerator = false;
public $shared = false;
public function __construct() { public function __construct() {
$this->addType('maxParticipants', 'integer'); $this->addType('maxParticipants', 'integer');
$this->addType('record', 'boolean'); $this->addType('record', 'boolean');
$this->addType('everyoneIsModerator', 'boolean'); $this->addType('everyoneIsModerator', 'boolean');
$this->addType('requireModerator', 'boolean'); $this->addType('requireModerator', 'boolean');
$this->addType('shared', 'boolean');
} }
public function jsonSerialize(): array { public function jsonSerialize(): array {
@ -74,7 +76,8 @@ class Room extends Entity implements JsonSerializable {
'access' => $this->access, 'access' => $this->access,
'password' => $this->password, 'password' => $this->password,
'everyoneIsModerator' => boolval($this->everyoneIsModerator), 'everyoneIsModerator' => boolval($this->everyoneIsModerator),
'requireModerator' => boolval($this->requireModerator), 'requireModerator' => boolval($this->requireModerator),
'shared' => boolval($this->shared),
]; ];
} }
} }

View File

@ -19,9 +19,13 @@ class RoomMapper extends QBMapper {
public function find(int $id): Room { public function find(int $id): Room {
/* @var $qb IQueryBuilder */ /* @var $qb IQueryBuilder */
$qb = $this->db->getQueryBuilder(); $qb = $this->db->getQueryBuilder();
$qb->select('*') $qb->select('r.*')
->from($this->tableName) ->from($this->tableName, 'r')
->where($qb->expr()->eq('id', $qb->createNamedParameter($id, IQueryBuilder::PARAM_INT))); ->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 */ /** @var Room */
return $this->findEntity($qb); return $this->findEntity($qb);
@ -34,9 +38,13 @@ class RoomMapper extends QBMapper {
public function findByUid(string $uid): Room { public function findByUid(string $uid): Room {
/* @var $qb IQueryBuilder */ /* @var $qb IQueryBuilder */
$qb = $this->db->getQueryBuilder(); $qb = $this->db->getQueryBuilder();
$qb->select('*') $qb->select('r.*')
->from($this->tableName) ->from($this->tableName, 'r')
->where($qb->expr()->eq('uid', $qb->createNamedParameter($uid))); ->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 */ /** @var Room */
return $this->findEntity($qb); return $this->findEntity($qb);
@ -51,6 +59,7 @@ class RoomMapper extends QBMapper {
$qb->select('r.*') $qb->select('r.*')
->from($this->tableName, 'r') ->from($this->tableName, 'r')
->leftJoin('r', 'bbb_room_shares', 's', $qb->expr()->eq('r.id', 's.room_id')) ->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( ->where(
$qb->expr()->orX( $qb->expr()->orX(
$qb->expr()->eq('r.user_id', $qb->createNamedParameter($userId)), $qb->expr()->eq('r.user_id', $qb->createNamedParameter($userId)),

View File

@ -37,6 +37,7 @@ export interface Room {
password?: string; password?: string;
everyoneIsModerator: boolean; everyoneIsModerator: boolean;
requireModerator: boolean; requireModerator: boolean;
shared: boolean;
} }
export interface RoomShare { export interface RoomShare {

View File

@ -44,6 +44,14 @@ const EditRoomDialog: React.FC<Props> = ({ room, restriction, updateProperty, op
}); });
}, [room.id, open]); }, [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') { function inputElement(label: string, field: string, type: 'text' | 'number' = 'text') {
return ( return (
<div className="bbb-form-element"> <div className="bbb-form-element">

View File

@ -187,6 +187,7 @@ const RoomRow: React.FC<Props> = (props) => {
</td> </td>
<td className="bbb-shrink"> <td className="bbb-shrink">
{room.userId !== OC.currentUser && <img src={avatarUrl} alt="Avatar" className="bbb-avatar" />} {room.userId !== OC.currentUser && <img src={avatarUrl} alt="Avatar" className="bbb-avatar" />}
{(room.userId === OC.currentUser && room.shared) && <span className="icon icon-shared icon-visible"/>}
</td> </td>
<td className="max-participants bbb-shrink"> <td className="max-participants bbb-shrink">
{edit('maxParticipants', 'number', {min: minParticipantsLimit, max: maxParticipantsLimit < 0 ? undefined : maxParticipantsLimit})} {edit('maxParticipants', 'number', {min: minParticipantsLimit, max: maxParticipantsLimit < 0 ? undefined : maxParticipantsLimit})}