This commit is contained in:
Robin Appelman 2016-10-25 16:29:12 +02:00
Родитель 05fb17ea6a
Коммит 8a257c130f
1 изменённых файлов: 13 добавлений и 16 удалений

Просмотреть файл

@ -110,22 +110,20 @@ class SignallingController extends Controller {
while(true) { while(true) {
// Check if the connection is still active, if not: Kill all existing // Check if the connection is still active, if not: Kill all existing
// messages and end the event source // messages and end the event source
$currentRoom = $this->dbConnection->getQueryBuilder()->select('*') $qb = $this->dbConnection->getQueryBuilder();
$currentRoom = $qb->select('*')
->from('spreedme_room_participants') ->from('spreedme_room_participants')
->where('userId = :userId') ->where($qb->expr()->eq('userId', $qb->createNamedParameter($this->userId)))
->andWhere('lastPing > :lastPing') ->andWhere($qb->expr()->gt('lastPing', $qb->createNamedParameter(time() - 10)))
->setParameter(':userId', $this->userId)
->setParameter(':lastPing', time() - 10)
->execute() ->execute()
->fetchAll(); ->fetchAll();
if ($currentRoom === []) { if ($currentRoom === []) {
$eventSource->close(); $eventSource->close();
// Delete all messages for the recipient // Delete all messages for the recipient
$this->dbConnection->getQueryBuilder() $qb = $this->dbConnection->getQueryBuilder();
->delete('spreedme_messages') $qb->delete('spreedme_messages')
->where('recipient = :recipient') ->where($qb->expr()->eq('recipient', $qb->createNamedParameter($this->userId)))
->setParameter(':recipient', $this->userId)
->execute(); ->execute();
break; break;
} }
@ -141,18 +139,17 @@ class SignallingController extends Controller {
$eventSource->send('usersInRoom', $usersInRoom); $eventSource->send('usersInRoom', $usersInRoom);
// Query all messages and send them to the user // Query all messages and send them to the user
$results = $this->dbConnection->getQueryBuilder() $qb = $this->dbConnection->getQueryBuilder();
->select('*') $results = $qb->select('*')
->from('spreedme_messages') ->from('spreedme_messages')
->where('recipient = :recipient') ->where('recipient = :recipient')
->setParameter(':recipient', $this->userId) ->where($qb->expr()->eq('recipient', $qb->createNamedParameter($this->userId)))
->execute() ->execute()
->fetchAll(); ->fetchAll();
foreach($results as $result) { foreach($results as $result) {
$this->dbConnection->getQueryBuilder() $qb = $this->dbConnection->getQueryBuilder();
->delete('spreedme_messages') $qb->delete('spreedme_messages')
->where('id = :id') ->where($qb->expr()->eq('id', $qb->createNamedParameter($result['id'])))
->setParameter(':id', $result['id'])
->execute(); ->execute();
$eventSource->send('message', $result['object']); $eventSource->send('message', $result['object']);
} }