Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stop refreshing participant list when a guest is chatting #866

Merged
Show file tree
Hide file tree
Changes from 2 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
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
63 changes: 48 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,55 @@ 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;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is never set to false.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

right, changed the logic of the code and broke this.


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();
$dispatchEvent = true;
}
} catch (ParticipantNotFoundException $e) {
$this->connection->insertIfNotExist('*PREFIX*talk_guests', [
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMHO inserting an initial name should also dispatch an event.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It does, because of the $dispatchEvent = true;

'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