Browse Source

Make it possible to join listed group conversations

Signed-off-by: Vincent Petry <vincent@nextcloud.com>
pull/4706/head
Vincent Petry 5 years ago
parent
commit
6f8d1e6529
No known key found for this signature in database GPG Key ID: E055D6A4D513575C
  1. 29
      lib/Manager.php
  2. 32
      lib/Service/ParticipantService.php

29
lib/Manager.php

@ -442,8 +442,13 @@ class Manager {
}
/**
* Also returns public rooms for participants that have not been invited,
* so they can join.
* Returns room object for a user by token.
*
* Also returns:
* - public rooms for participants that have not been invited
* - listable rooms for participants that have not been invited
*
* This is useful so they can join.
*
* @param string $token
* @param string|null $userId
@ -501,8 +506,24 @@ class Manager {
return $room;
}
if ($userId !== null && $row['actor_id'] === $userId) {
return $room;
if ($userId !== null) {
// user already joined that room before
if ($row['actor_id'] === $userId) {
return $room;
}
// never joined before but found in listing
$listable = null;
if (isset($row['listable'])) {
$listable = (int)$row['listable'];
}
if (
$listable === Room::LISTABLE_ALL || (
$listable === Room::LISTABLE_USERS && !$this->isGuestUser($userId)
)
) {
return $room;
}
}
throw new RoomNotFoundException();

32
lib/Service/ParticipantService.php

@ -166,12 +166,32 @@ class ParticipantService {
throw new InvalidPasswordException('Provided password is invalid');
}
// User joining a public room, without being invited
$this->addUsers($room, [[
'actorType' => Attendee::ACTOR_USERS,
'actorId' => $user->getUID(),
'participantType' => Participant::USER_SELF_JOINED,
]]);
// User joining a group call through listing
if (
$room->getType() === Room::GROUP_CALL && (
// this check should have happened earlier already but let's stay defensive
$room->getListable() === Room::LISTABLE_ALL || (
$room->getListable() === Room::LISTABLE_USERS && !$this->manager->isGuestUser()
)
)
) {
$this->addUsers($room, [[
'actorType' => Attendee::ACTOR_USERS,
'actorId' => $user->getUID(),
// need to use "USER" here, because "USER_SELF_JOINED" only works for public calls
'participantType' => Participant::USER,
]]);
} elseif ($room->getType() === Room::PUBLIC_CALL) {
// User joining a public room, without being invited
$this->addUsers($room, [[
'actorType' => Attendee::ACTOR_USERS,
'actorId' => $user->getUID(),
'participantType' => Participant::USER_SELF_JOINED,
]]);
} else {
// shouldn't happen unless some code called joinRoom without previous checks
throw new UnauthorizedException('Participant is not allowed to join');
}
$attendee = $this->attendeeMapper->findByActor($room->getId(), Attendee::ACTOR_USERS, $user->getUID());
}

Loading…
Cancel
Save