Browse Source

Store the guest display name into the attendees table

Signed-off-by: Joas Schilling <coding@schilljs.com>
pull/5146/head
Joas Schilling 5 years ago
parent
commit
6934b5ba1c
No known key found for this signature in database GPG Key ID: 7076EA9751AACDDA
  1. 7
      lib/Controller/GuestController.php
  2. 36
      lib/GuestManager.php

7
lib/Controller/GuestController.php

@ -24,7 +24,6 @@ declare(strict_types=1);
namespace OCA\Talk\Controller;
use Doctrine\DBAL\Exception;
use OCA\Talk\GuestManager;
use OCA\Talk\Participant;
use OCP\AppFramework\Http;
@ -61,11 +60,7 @@ class GuestController extends AEnvironmentAwareController {
return new DataResponse([], Http::STATUS_FORBIDDEN);
}
try {
$this->guestManager->updateName($this->getRoom(), $participant, $displayName);
} catch (Exception $e) {
return new DataResponse([], Http::STATUS_INTERNAL_SERVER_ERROR);
}
$this->guestManager->updateName($this->getRoom(), $participant, $displayName);
return new DataResponse();
}

36
lib/GuestManager.php

@ -28,6 +28,7 @@ use OCA\Talk\Events\AddEmailEvent;
use OCA\Talk\Events\ModifyParticipantEvent;
use OCA\Talk\Model\Attendee;
use OCA\Talk\Exceptions\ParticipantNotFoundException;
use OCA\Talk\Service\ParticipantService;
use OCP\DB\QueryBuilder\IQueryBuilder;
use OCP\Defaults;
use OCP\EventDispatcher\IEventDispatcher;
@ -59,6 +60,9 @@ class GuestManager {
/** @var IUserSession */
protected $userSession;
/** @var ParticipantService */
private $participantService;
/** @var IURLGenerator */
protected $url;
@ -73,6 +77,7 @@ class GuestManager {
IMailer $mailer,
Defaults $defaults,
IUserSession $userSession,
ParticipantService $participantService,
IURLGenerator $url,
IL10N $l,
IEventDispatcher $dispatcher) {
@ -81,6 +86,7 @@ class GuestManager {
$this->mailer = $mailer;
$this->defaults = $defaults;
$this->userSession = $userSession;
$this->participantService = $participantService;
$this->url = $url;
$this->l = $l;
$this->dispatcher = $dispatcher;
@ -90,32 +96,16 @@ class GuestManager {
* @param Room $room
* @param Participant $participant
* @param string $displayName
* @throws Exception
*/
public function updateName(Room $room, Participant $participant, string $displayName): void {
$sessionHash = $participant->getAttendee()->getActorId();
$dispatchEvent = true;
try {
$oldName = $this->getNameBySessionHash($sessionHash, true);
if ($oldName !== $displayName) {
$query = $this->connection->getQueryBuilder();
$query->update('talk_guestnames')
->set('display_name', $query->createNamedParameter($displayName))
->where($query->expr()->eq('session_hash', $query->createNamedParameter($sessionHash)));
$query->execute();
} else {
$dispatchEvent = false;
}
} catch (ParticipantNotFoundException $e) {
$this->connection->insertIfNotExist('*PREFIX*talk_guestnames', [
'session_hash' => $sessionHash,
'display_name' => $displayName,
], ['session_hash']);
}
$attendee = $participant->getAttendee();
if ($attendee->getDisplayName() !== $displayName) {
$this->participantService->updateDisplayNameForActor(
$attendee->getActorType(),
$attendee->getActorId(),
$displayName
);
if ($dispatchEvent) {
$event = new ModifyParticipantEvent($room, $participant, 'name', $displayName);
$this->dispatcher->dispatch(self::EVENT_AFTER_NAME_UPDATE, $event);
}

Loading…
Cancel
Save