* @throws CannotReachRemoteException * * 200: Room avatar returned */ public function getAvatar(Room $room, ?Participant $participant, ?Invitation $invitation, bool $darkTheme): FileDisplayResponse { if ($participant === null && $invitation === null) { throw new CannotReachRemoteException('Must receive either participant or invitation'); } $proxy = $this->proxy->get( $participant ? $participant->getAttendee()->getInvitedCloudId() : $invitation->getLocalCloudId(), $participant ? $participant->getAttendee()->getAccessToken() : $invitation->getAccessToken(), $room->getRemoteServer() . '/ocs/v2.php/apps/spreed/api/v1/room/' . $room->getRemoteToken() . '/avatar' . ($darkTheme ? '/dark' : ''), ); if ($proxy->getStatusCode() !== Http::STATUS_OK) { $this->proxy->logUnexpectedStatusCode(__METHOD__, $proxy->getStatusCode(), (string)$proxy->getBody()); throw new CannotReachRemoteException('Avatar request had unexpected status code'); } $content = $proxy->getBody(); if ($content === '') { throw new CannotReachRemoteException('No avatar content received'); } $file = new InMemoryFile($room->getToken(), $content); $response = new FileDisplayResponse($file, Http::STATUS_OK, ['Content-Type' => $file->getMimeType()]); // Cache for 1 day $response->cacheFor(60 * 60 * 24, false, true); return $response; } /** * @see \OCA\Talk\Controller\AvatarController::getUserProxyAvatar() * * @return FileDisplayResponse * @throws CannotReachRemoteException * * 200: User avatar returned */ public function getUserProxyAvatar(string $remoteServer, string $user, int $size, bool $darkTheme): FileDisplayResponse { $proxy = $this->proxy->get( null, null, $remoteServer . '/index.php/avatar/' . $user . '/' . $size . ($darkTheme ? '/dark' : ''), ); if ($proxy->getStatusCode() !== Http::STATUS_OK) { if ($proxy->getStatusCode() !== Http::STATUS_NOT_FOUND) { $this->proxy->logUnexpectedStatusCode(__METHOD__, $proxy->getStatusCode(), (string)$proxy->getBody()); } throw new CannotReachRemoteException('Avatar request had unexpected status code'); } $content = $proxy->getBody(); if ($content === '') { throw new CannotReachRemoteException('No avatar content received'); } $file = new InMemoryFile($user, $content); $response = new FileDisplayResponse($file, Http::STATUS_OK, ['Content-Type' => $file->getMimeType()]); // Cache for 1 day $response->cacheFor(60 * 60 * 24, false, true); return $response; } }