Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Simplify getRoomIconUrl method
Signed-off-by: Joas Schilling <[email protected]>
  • Loading branch information
nickvergessen authored and backportbot-nextcloud[bot] committed Sep 29, 2022
commit 87448e3ed2377dbb3dd1eebe140dcb070ef7bd4b
20 changes: 7 additions & 13 deletions lib/Collaboration/Reference/TalkReferenceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -255,19 +255,13 @@ public function getCacheKey(string $referenceId): ?string {

protected function getRoomIconUrl(Room $room, string $userId): string {
if ($room->getType() === Room::TYPE_ONE_TO_ONE) {
$participants = json_decode($room->getName(), true);

foreach ($participants as $p) {
if ($p !== $userId) {
return $this->urlGenerator->linkToRouteAbsolute(
'core.avatar.getAvatar',
[
'userId' => $p,
'size' => 64,
]
);
}
}
return $this->urlGenerator->linkToRouteAbsolute(
'core.avatar.getAvatar',
[
'userId' => $room->getSecondParticipant($userId),
'size' => 64,
]
);
}

return $this->urlGenerator->getAbsoluteURL($this->urlGenerator->imagePath('spreed', 'changelog.svg'));
Expand Down
15 changes: 15 additions & 0 deletions lib/Room.php
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,21 @@ public function getName(): string {
return $this->name;
}

public function getSecondParticipant(string $userId): string {
if ($this->getType() !== self::TYPE_ONE_TO_ONE) {
throw new \InvalidArgumentException('Not a one-to-one room');
}
$participants = json_decode($this->getName(), true);

foreach ($participants as $uid) {
if ($uid !== $userId) {
return $uid;
}
}

return $this->getName();
}

public function getDisplayName(string $userId): string {
return $this->manager->resolveRoomDisplayName($this, $userId);
}
Expand Down