Return room URL in activities and references

Signed-off-by: Vitor Mattos <vitor@php.rio>
This commit is contained in:
Vitor Mattos 2022-11-21 01:53:12 -03:00 committed by Joas Schilling
parent aabd71b11b
commit b34192e937
No known key found for this signature in database
GPG key ID: 74434EFE0D2E2205
7 changed files with 25 additions and 46 deletions

View file

@ -175,6 +175,7 @@ class Listener {
->setTimestamp($this->timeFactory->getTime())
->setSubject('call', [
'room' => $room->getId(),
'avatar' => $room->getAvatar(),
'users' => $userIds,
'guests' => $numGuests,
'duration' => $duration,
@ -221,6 +222,7 @@ class Listener {
->setSubject('invitation', [
'user' => $actor->getUID(),
'room' => $room->getId(),
'avatar' => $room->getAvatar(),
]);
} catch (\InvalidArgumentException $e) {
$this->logger->error($e->getMessage(), ['exception' => $e]);
@ -253,6 +255,7 @@ class Listener {
->setSubject('invitation', [
'user' => $actor->getUID(),
'room' => $room->getId(),
'avatar' => $room->getAvatar(),
'name' => $roomName,
])
->setAffectedUser($participant['actorId']);

View file

@ -33,6 +33,7 @@ use OCA\Talk\Manager;
use OCA\Talk\Model\Attendee;
use OCA\Talk\Participant;
use OCA\Talk\Room;
use OCA\Talk\Service\AvatarService;
use OCA\Talk\Service\ParticipantService;
use OCP\Collaboration\Reference\IReference;
use OCP\Collaboration\Reference\IReferenceProvider;
@ -48,6 +49,7 @@ class TalkReferenceProvider implements IReferenceProvider {
protected Manager $roomManager;
protected ParticipantService $participantService;
protected ChatManager $chatManager;
protected AvatarService $avatarService;
protected MessageParser $messageParser;
protected IL10N $l;
protected ?string $userId;
@ -56,6 +58,7 @@ class TalkReferenceProvider implements IReferenceProvider {
Manager $manager,
ParticipantService $participantService,
ChatManager $chatManager,
AvatarService $avatarService,
MessageParser $messageParser,
IL10N $l,
?string $userId) {
@ -63,6 +66,7 @@ class TalkReferenceProvider implements IReferenceProvider {
$this->roomManager = $manager;
$this->participantService = $participantService;
$this->chatManager = $chatManager;
$this->avatarService = $avatarService;
$this->messageParser = $messageParser;
$this->l = $l;
$this->userId = $userId;
@ -223,7 +227,7 @@ class TalkReferenceProvider implements IReferenceProvider {
$reference->setTitle($title);
$reference->setDescription($description);
$reference->setUrl($this->urlGenerator->linkToRouteAbsolute('spreed.Page.showCall', ['token' => $room->getToken()]));
$reference->setImageUrl($this->getRoomIconUrl($room, $this->userId));
$reference->setImageUrl($this->getRoomIconUrl($room));
$reference->setRichObject('call', [
'id' => $room->getToken(),
@ -257,18 +261,8 @@ class TalkReferenceProvider implements IReferenceProvider {
return ($this->userId ?? '') . '#' . ($referenceMatch['message'] ?? 0);
}
protected function getRoomIconUrl(Room $room, string $userId): string {
if ($room->getType() === Room::TYPE_ONE_TO_ONE) {
return $this->urlGenerator->linkToRouteAbsolute(
'core.avatar.getAvatar',
[
'userId' => $room->getSecondParticipant($userId),
'size' => 64,
]
);
}
return $this->urlGenerator->getAbsoluteURL($this->urlGenerator->imagePath('spreed', 'changelog.svg'));
protected function getRoomIconUrl(Room $room): string {
return $this->avatarService->getAvatarUrl($room);
}
protected function getRoomType(Room $room): string {

View file

@ -67,7 +67,7 @@ class AvatarController extends AEnvironmentAwareController {
$file = $this->request->getUploadedFile('file');
$this->avatarService->setAvatarFromRequest($this->getRoom(), $file);
return new DataResponse([
'avatar' => $this->avatarService->getAvatarUrl($this->getRoom(), $this->userSession->getUser()->getUID()),
'avatar' => $this->avatarService->getAvatarUrl($this->getRoom()),
]);
} catch (InvalidArgumentException $e) {
return new DataResponse(['message' => $e->getMessage()], Http::STATUS_BAD_REQUEST);

View file

@ -485,7 +485,7 @@ class RoomController extends AEnvironmentAwareController {
'description' => $room->getDescription(),
'listable' => $room->getListable(),
'messageExpiration' => $room->getMessageExpiration(),
'avatar' => $this->avatarService->getAvatarUrl($room, $userId),
'avatar' => $this->avatarService->getAvatarUrl($room),
]);
if ($currentParticipant->getAttendee()->getReadPrivacy() === Participant::PRIVACY_PUBLIC) {

View file

@ -30,6 +30,7 @@ use OCA\Talk\Config;
use OCA\Talk\Manager;
use OCA\Talk\Participant;
use OCA\Talk\Room;
use OCA\Talk\Service\AvatarService;
use OCA\Talk\Service\ParticipantService;
use OCP\Comments\IComment;
use OCP\Dashboard\IAPIWidget;
@ -52,6 +53,7 @@ class TalkWidget implements IAPIWidget, IIconWidget, IButtonWidget, IOptionWidge
protected IURLGenerator $url;
protected IL10N $l10n;
protected Manager $manager;
protected AvatarService $avatarService;
protected ParticipantService $participantService;
protected MessageParser $messageParser;
@ -61,6 +63,7 @@ class TalkWidget implements IAPIWidget, IIconWidget, IButtonWidget, IOptionWidge
IURLGenerator $url,
IL10N $l10n,
Manager $manager,
AvatarService $avatarService,
ParticipantService $participantService,
MessageParser $messageParser
) {
@ -69,6 +72,7 @@ class TalkWidget implements IAPIWidget, IIconWidget, IButtonWidget, IOptionWidge
$this->url = $url;
$this->l10n = $l10n;
$this->manager = $manager;
$this->avatarService = $avatarService;
$this->participantService = $participantService;
$this->messageParser = $messageParser;
}
@ -205,36 +209,12 @@ class TalkWidget implements IAPIWidget, IIconWidget, IButtonWidget, IOptionWidge
$room->getDisplayName($userId),
$subtitle,
$this->url->linkToRouteAbsolute('spreed.Page.showCall', ['token' => $room->getToken()]),
$this->getRoomIconUrl($room, $userId)
$this->getRoomIconUrl($room)
);
}
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->url->linkToRouteAbsolute(
'core.avatar.getAvatar',
[
'userId' => $p,
'size' => 64,
]
);
}
}
} elseif ($room->getObjectType() === 'file') {
return $this->url->getAbsoluteURL($this->url->imagePath('core', 'filetypes/file.svg'));
} elseif ($room->getObjectType() === 'share:password') {
return $this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/password.svg'));
} elseif ($room->getObjectType() === 'emails') {
return $this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/mail.svg'));
} elseif ($room->getType() === Room::TYPE_PUBLIC) {
return $this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/public.svg'));
}
return $this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/group.svg'));
protected function getRoomIconUrl(Room $room): string {
return $this->avatarService->getAvatarUrl($room);
}
protected function sortRooms(Room $roomA, Room $roomB): int {

View file

@ -201,10 +201,7 @@ class AvatarService {
return (string) ($this->cache->get($room->getToken() . '.avatarVersion') ?? 0);
}
public function getAvatarUrl(Room $room, ?string $userId = null): string {
if (!$this->roomHasAvatar($room)) {
return '';
}
public function getAvatarUrl(Room $room): string {
return $this->url->linkToRouteAbsolute('ocs.spreed.Avatar.getAvatar', [
'token' => $room->getToken(),
'apiVersion' => 'v1',

View file

@ -28,6 +28,7 @@ use OCA\Talk\Chat\ChatManager;
use OCA\Talk\Chat\MessageParser;
use OCA\Talk\Collaboration\Reference\TalkReferenceProvider;
use OCA\Talk\Manager;
use OCA\Talk\Service\AvatarService;
use OCA\Talk\Service\ParticipantService;
use OCP\IL10N;
use OCP\IURLGenerator;
@ -43,6 +44,8 @@ class TalkReferenceProviderTest extends TestCase {
protected $participantService;
/** @var ChatManager|MockObject */
protected $chatManager;
/** @var AvatarService|MockObject */
protected $avatarService;
/** @var MessageParser|MockObject */
protected $messageParser;
/** @var IL10N|MockObject */
@ -56,6 +59,7 @@ class TalkReferenceProviderTest extends TestCase {
$this->roomManager = $this->createMock(Manager::class);
$this->participantService = $this->createMock(ParticipantService::class);
$this->chatManager = $this->createMock(ChatManager::class);
$this->avatarService = $this->createMock(AvatarService::class);
$this->messageParser = $this->createMock(MessageParser::class);
$this->l = $this->createMock(IL10N::class);
@ -64,6 +68,7 @@ class TalkReferenceProviderTest extends TestCase {
$this->roomManager,
$this->participantService,
$this->chatManager,
$this->avatarService,
$this->messageParser,
$this->l,
'test'