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
diff options
context:
space:
mode:
authorJoas Schilling <coding@schilljs.com>2020-09-15 15:58:40 +0300
committerJoas Schilling <coding@schilljs.com>2020-09-15 17:33:58 +0300
commitbbe65e5b82d1e8cf0641e793689e745df8e6cdad (patch)
treed9a41b41283b21119c1016f640d2e40a42e4001a /lib/Room.php
parentadd7d0aa09d12b8d16d4a7097e626910a86fc383 (diff)
Store the one-to-one users in the "name" column so we can reuse the data
Signed-off-by: Joas Schilling <coding@schilljs.com>
Diffstat (limited to 'lib/Room.php')
-rw-r--r--lib/Room.php45
1 files changed, 29 insertions, 16 deletions
diff --git a/lib/Room.php b/lib/Room.php
index ca02918e8..1f827bf69 100644
--- a/lib/Room.php
+++ b/lib/Room.php
@@ -238,6 +238,22 @@ class Room {
}
public function getName(): string {
+ if ($this->type === self::ONE_TO_ONE_CALL) {
+ if ($this->name === '') {
+ // Fill the room name with the participants for 1-to-1 conversations
+ $users = $this->getParticipantUserIds();
+ sort($users);
+ $this->setName(json_encode($users), '');
+ } elseif (strpos($this->name, '["') !== 0) {
+ // Not the json array, but the old fallback when someone left
+ $users = $this->getParticipantUserIds();
+ if (count($users) !== 2) {
+ $users[] = $this->name;
+ }
+ sort($users);
+ $this->setName(json_encode($users), '');
+ }
+ }
return $this->name;
}
@@ -391,10 +407,11 @@ class Room {
/**
* @param string $newName Currently it is only allowed to rename: self::GROUP_CALL, self::PUBLIC_CALL
+ * @param string|null $oldName
* @return bool True when the change was valid, false otherwise
*/
- public function setName(string $newName): bool {
- $oldName = $this->getName();
+ public function setName(string $newName, ?string $oldName = null): bool {
+ $oldName = $oldName !== null ? $oldName : $this->getName();
if ($newName === $oldName) {
return false;
}
@@ -660,18 +677,18 @@ class Room {
return;
}
- if ($this->getName() === '') {
- return;
- }
+ $users = json_decode($this->getName(), true);
+ $participants = $this->getParticipantUserIds();
+ $missingUsers = array_diff($users, $participants);
- if ($this->manager->isValidParticipant($this->getName())) {
- $this->addUsers([
- 'userId' => $this->getName(),
- 'participantType' => Participant::OWNER,
- ]);
+ foreach ($missingUsers as $userId) {
+ if ($this->manager->isValidParticipant($userId)) {
+ $this->addUsers([
+ 'userId' => $userId,
+ 'participantType' => Participant::OWNER,
+ ]);
+ }
}
-
- $this->setName('');
}
/**
@@ -747,10 +764,6 @@ class Room {
$event = new RemoveUserEvent($this, $participant, $user, $reason);
$this->dispatcher->dispatch(self::EVENT_BEFORE_USER_REMOVE, $event);
- if ($this->getType() === self::ONE_TO_ONE_CALL) {
- $this->setName($user->getUID());
- }
-
$query = $this->db->getQueryBuilder();
$query->delete('talk_participants')
->where($query->expr()->eq('room_id', $query->createNamedParameter($this->getId(), IQueryBuilder::PARAM_INT)))