Skip to content
Open
Changes from all commits
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
12 changes: 9 additions & 3 deletions lib/Service/SessionService.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ class SessionService {
private IAvatarManager $avatarManager;
private ?string $userId;
private ICache $cache;
private EncodingService $encodingService;

/** @var ?Session cache current session in the request */
private ?Session $session = null;
Expand All @@ -46,12 +47,14 @@ public function __construct(
IManager $directManager,
?string $userId,
ICacheFactory $cacheFactory,
EncodingService $encodingService,
) {
$this->sessionMapper = $sessionMapper;
$this->secureRandom = $secureRandom;
$this->timeFactory = $timeFactory;
$this->userManager = $userManager;
$this->avatarManager = $avatarManager;
$this->encodingService = $encodingService;
$this->userId = $userId;

$token = $request->getParam('token');
Expand Down Expand Up @@ -99,7 +102,8 @@ public function getAllSessions(int $documentId): array {
return array_map(function (Session $session) {
$result = $session->jsonSerialize();
if (!$session->isGuest()) {
$result['displayName'] = $this->userManager->getDisplayName($session->getUserId());
$displayName = $this->userManager->getDisplayName($session->getUserId()) ?? '';
$result['displayName'] = $this->encodingService->encodeToUtf8($displayName) ?? $displayName;
}
return $result;
}, $sessions);
Expand All @@ -114,15 +118,17 @@ public function getActiveSessions(int $documentId): array {
return array_map(function (Session $session) {
$result = $session->jsonSerialize();
if (!$session->isGuest()) {
$result['displayName'] = $this->userManager->getDisplayName($session->getUserId());
$displayName = $this->userManager->getDisplayName($session->getUserId()) ?? '';
$result['displayName'] = $this->encodingService->encodeToUtf8($displayName) ?? $displayName;
}
return $result;
}, $sessions);
}

public function getNameForSession(Session $session): ?string {
if (!$session->isGuest()) {
return $this->userManager->getDisplayName($session->getUserId());
$displayName = $this->userManager->getDisplayName($session->getUserId()) ?? '';
return $this->encodingService->encodeToUtf8($displayName) ?? $displayName;
}

return $session->getGuestName();
Expand Down
Loading