Skip to content

Commit

Permalink
Merge pull request #866 from nextcloud/bugfix/865/stop-refreshing-par…
Browse files Browse the repository at this point in the history
…ticipant-list-when-a-guest-is-chatting

Stop refreshing participant list when a guest is chatting
  • Loading branch information
Ivansss authored May 9, 2018
2 parents d53f017 + baad12b commit c322163
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 21 deletions.
8 changes: 2 additions & 6 deletions lib/Controller/SignalingController.php
Original file line number Diff line number Diff line change
Expand Up @@ -166,12 +166,8 @@ public function pullMessages($token) {
});

if ($messageCount !== count($data)) {
try {
$room = $this->manager->getRoomForSession($this->userId, $sessionId);
$data[] = ['type' => 'usersInRoom', 'data' => $this->getUsersInRoom($room)];
} catch (RoomNotFoundException $e) {
return new DataResponse([['type' => 'usersInRoom', 'data' => []]], Http::STATUS_NOT_FOUND);
}
// Participant list changed, bail out and deliver the info to the user
break;
}

$this->dbConnection->close();
Expand Down
64 changes: 49 additions & 15 deletions lib/GuestManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
namespace OCA\Spreed;


use OCA\Spreed\Exceptions\ParticipantNotFoundException;
use OCP\DB\QueryBuilder\IQueryBuilder;
use OCP\IDBConnection;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
Expand All @@ -48,23 +49,56 @@ public function __construct(IDBConnection $connection, EventDispatcherInterface
*/
public function updateName(Room $room, $sessionId, $displayName) {
$sessionHash = sha1($sessionId);
$result = $this->connection->insertIfNotExist('*PREFIX*talk_guests', [
'session_hash' => $sessionHash,
'display_name' => $displayName,
], ['session_hash']);

if ($result === 0) {
$query = $this->connection->getQueryBuilder();
$query->update('talk_guests')
->set('display_name', $query->createNamedParameter($displayName))
->where($query->expr()->eq('session_hash', $query->createNamedParameter($sessionHash)));
$query->execute();
$dispatchEvent = true;

try {
$oldName = $this->getNameBySessionHash($sessionHash);

if ($oldName !== $displayName) {
$query = $this->connection->getQueryBuilder();
$query->update('talk_guests')
->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_guests', [
'session_hash' => $sessionHash,
'display_name' => $displayName,
], ['session_hash']);
}


if ($dispatchEvent) {
$this->dispatcher->dispatch(self::class . '::updateName', new GenericEvent($room, [
'sessionId' => $sessionId,
'newName' => $displayName,
]));
}
}

/**
* @param string $sessionHash
* @return string
* @throws ParticipantNotFoundException
*/
public function getNameBySessionHash($sessionHash) {
$query = $this->connection->getQueryBuilder();
$query->select('display_name')
->from('talk_guests')
->where($query->expr()->eq('session_hash', $query->createNamedParameter($sessionHash)));

$result = $query->execute();
$row = $result->fetch();
$result->closeCursor();

if (isset($row['display_name'])) {
return $row['display_name'];
}

$this->dispatcher->dispatch(self::class . '::updateName', new GenericEvent($room, [
'sessionId' => $sessionId,
'newName' => $displayName,
]));
throw new ParticipantNotFoundException();
}

/**
Expand Down

0 comments on commit c322163

Please sign in to comment.