diff options
author | Vincent Petry <vincent@nextcloud.com> | 2021-01-19 19:45:13 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-01-19 19:45:13 +0300 |
commit | d068d9bb5ecd05458e2c4fccad0e5ea35d36698d (patch) | |
tree | e77942e30f5ed4224589111c75d45200b3ecd62c /lib | |
parent | 694500b87f16e62762dd200154e2fed90ce09219 (diff) | |
parent | a542d701637578296a85f40f2a8edc89c6d2b1e2 (diff) |
Merge pull request #4956 from nextcloud/bugfix/noid/fix-display-names-with-sip-usres
Fix display names with sip users
Diffstat (limited to 'lib')
-rw-r--r-- | lib/Controller/CallController.php | 42 |
1 files changed, 40 insertions, 2 deletions
diff --git a/lib/Controller/CallController.php b/lib/Controller/CallController.php index 85c85e834..54e06fafe 100644 --- a/lib/Controller/CallController.php +++ b/lib/Controller/CallController.php @@ -27,6 +27,7 @@ declare(strict_types=1); namespace OCA\Talk\Controller; +use OCA\Talk\GuestManager; use OCA\Talk\Model\Attendee; use OCA\Talk\Model\Session; use OCA\Talk\Participant; @@ -35,20 +36,30 @@ use OCP\AppFramework\Http; use OCP\AppFramework\Http\DataResponse; use OCP\AppFramework\Utility\ITimeFactory; use OCP\IRequest; +use OCP\IUser; +use OCP\IUserManager; class CallController extends AEnvironmentAwareController { /** @var ParticipantService */ private $participantService; + /** @var IUserManager */ + private $userManager; + /** @var GuestManager */ + private $guestManager; /** @var ITimeFactory */ private $timeFactory; public function __construct(string $appName, IRequest $request, ParticipantService $participantService, + IUserManager $userManager, + GuestManager $guestManager, ITimeFactory $timeFactory) { parent::__construct($appName, $request); $this->participantService = $participantService; + $this->userManager = $userManager; + $this->guestManager = $guestManager; $this->timeFactory = $timeFactory; } @@ -64,6 +75,24 @@ class CallController extends AEnvironmentAwareController { $timeout = $this->timeFactory->getTime() - 30; $result = []; $participants = $this->participantService->getParticipantsInCall($this->room); + + + $guestSessions = array_filter(array_map(static function (Participant $participant) use ($timeout) { + $session = $participant->getSession(); + if (!$session || $participant->getAttendee()->getActorType() !== Attendee::ACTOR_GUESTS) { + return null; + } + + if ($session->getLastPing() < $timeout) { + // User is not active in call + return null; + } + + return sha1($session->getSessionId()); + }, $participants)); + + $guestNames = $this->guestManager->getNamesBySessionHashes($guestSessions); + foreach ($participants as $participant) { /** @var Session $session */ $session = $participant->getSession(); @@ -73,11 +102,20 @@ class CallController extends AEnvironmentAwareController { } if ($this->getAPIVersion() >= 3) { + $displayName = $participant->getAttendee()->getActorId(); + if ($participant->getAttendee()->getActorType() === Attendee::ACTOR_USERS) { + $user = $this->userManager->get($participant->getAttendee()->getActorId()); + if ($user instanceof IUser) { + $displayName = $user->getDisplayName(); + } + } else { + $displayName = $guestNames[$participant->getAttendee()->getActorId()] ?? $displayName; + } + $result[] = [ 'actorType' => $participant->getAttendee()->getActorType(), 'actorId' => $participant->getAttendee()->getActorId(), - // FIXME 'displayName' => $participant->getAttendee()->getDisplayName(), - 'displayName' => $participant->getAttendee()->getActorId(), + 'displayName' => $displayName, 'token' => $this->room->getToken(), 'lastPing' => $session->getLastPing(), 'sessionId' => $session->getSessionId(), |