Change tables to talk_*

Signed-off-by: Joas Schilling <coding@schilljs.com>
This commit is contained in:
Joas Schilling 2017-10-27 10:16:04 +02:00
parent 5f11a47da0
commit f65d6f27a5
No known key found for this signature in database
GPG key ID: 7076EA9751AACDDA
6 changed files with 480 additions and 52 deletions

View file

@ -89,8 +89,8 @@ class Manager {
public function getRoomsForParticipant($participant) {
$query = $this->db->getQueryBuilder();
$query->select('*')
->from('spreedme_rooms', 'r')
->leftJoin('r', 'spreedme_room_participants', 'p', $query->expr()->andX(
->from('talk_rooms', 'r')
->leftJoin('r', 'talk_participants', 'p', $query->expr()->andX(
$query->expr()->eq('p.userId', $query->createNamedParameter($participant)),
$query->expr()->eq('p.roomId', 'r.id')
))
@ -121,12 +121,12 @@ class Manager {
public function getRoomForParticipant($roomId, $participant) {
$query = $this->db->getQueryBuilder();
$query->select('*')
->from('spreedme_rooms', 'r')
->from('talk_rooms', 'r')
->where($query->expr()->eq('id', $query->createNamedParameter($roomId, IQueryBuilder::PARAM_INT)));
if ($participant !== null) {
// Non guest user
$query->leftJoin('r', 'spreedme_room_participants', 'p', $query->expr()->andX(
$query->leftJoin('r', 'talk_participants', 'p', $query->expr()->andX(
$query->expr()->eq('p.userId', $query->createNamedParameter($participant)),
$query->expr()->eq('p.roomId', 'r.id')
))
@ -165,13 +165,13 @@ class Manager {
public function getRoomForParticipantByToken($token, $participant) {
$query = $this->db->getQueryBuilder();
$query->select('*')
->from('spreedme_rooms', 'r')
->from('talk_rooms', 'r')
->where($query->expr()->eq('token', $query->createNamedParameter($token)))
->setMaxResults(1);
if ($participant !== null) {
// Non guest user
$query->leftJoin('r', 'spreedme_room_participants', 'p', $query->expr()->andX(
$query->leftJoin('r', 'talk_participants', 'p', $query->expr()->andX(
$query->expr()->eq('p.userId', $query->createNamedParameter($participant)),
$query->expr()->eq('p.roomId', 'r.id')
));
@ -209,7 +209,7 @@ class Manager {
public function getRoomById($roomId) {
$query = $this->db->getQueryBuilder();
$query->select('*')
->from('spreedme_rooms')
->from('talk_rooms')
->where($query->expr()->eq('id', $query->createNamedParameter($roomId, IQueryBuilder::PARAM_INT)));
$result = $query->execute();
@ -231,7 +231,7 @@ class Manager {
public function getRoomByToken($token) {
$query = $this->db->getQueryBuilder();
$query->select('*')
->from('spreedme_rooms')
->from('talk_rooms')
->where($query->expr()->eq('token', $query->createNamedParameter($token)));
$result = $query->execute();
@ -258,8 +258,8 @@ class Manager {
$query = $this->db->getQueryBuilder();
$query->select('*')
->from('spreedme_rooms', 'r')
->leftJoin('r', 'spreedme_room_participants', 'p', $query->expr()->andX(
->from('talk_rooms', 'r')
->leftJoin('r', 'talk_participants', 'p', $query->expr()->andX(
$query->expr()->eq('p.sessionId', $query->createNamedParameter($sessionId)),
$query->expr()->eq('p.roomId', 'r.id')
))
@ -297,12 +297,12 @@ class Manager {
public function getOne2OneRoom($participant1, $participant2) {
$query = $this->db->getQueryBuilder();
$query->select('*')
->from('spreedme_rooms', 'r1')
->leftJoin('r1', 'spreedme_room_participants', 'p1', $query->expr()->andX(
->from('talk_rooms', 'r1')
->leftJoin('r1', 'talk_participants', 'p1', $query->expr()->andX(
$query->expr()->eq('p1.userId', $query->createNamedParameter($participant1)),
$query->expr()->eq('p1.roomId', 'r1.id')
))
->leftJoin('r1', 'spreedme_room_participants', 'p2', $query->expr()->andX(
->leftJoin('r1', 'talk_participants', 'p2', $query->expr()->andX(
$query->expr()->eq('p2.userId', $query->createNamedParameter($participant2)),
$query->expr()->eq('p2.roomId', 'r1.id')
))
@ -352,7 +352,7 @@ class Manager {
$token = $this->getNewToken();
$query = $this->db->getQueryBuilder();
$query->insert('spreedme_rooms')
$query->insert('talk_rooms')
->values(
[
'name' => $query->createNamedParameter($name),
@ -377,7 +377,7 @@ class Manager {
$query = $this->db->getQueryBuilder();
$query->select('*')
->from('spreedme_room_participants')
->from('talk_participants')
->where($query->expr()->eq('userId', $query->createNamedParameter($userId)))
->andWhere($query->expr()->neq('sessionId', $query->createNamedParameter('0')))
->orderBy('lastPing', 'DESC')
@ -406,7 +406,7 @@ class Manager {
// Delete all messages from or to the current user
$query = $this->db->getQueryBuilder();
$query->select('sessionId')
->from('spreedme_room_participants')
->from('talk_participants')
->where($query->expr()->eq('userId', $query->createNamedParameter($userId)));
$result = $query->execute();
@ -431,7 +431,7 @@ class Manager {
$query = $this->db->getQueryBuilder();
$query->select('id')
->from('spreedme_rooms')
->from('talk_rooms')
->where($query->expr()->eq('token', $query->createParameter('token')));
$i = 0;

View file

@ -0,0 +1,371 @@
<?php
/**
* @copyright Copyright (c) 2017 Joas Schilling <coding@schilljs.com>
*
* @author Joas Schilling <coding@schilljs.com>
*
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
namespace OCA\Spreed\Migration;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\DBAL\Types\Type;
use OCP\DB\QueryBuilder\IQueryBuilder;
use OCP\IDBConnection;
use OCP\Migration\SimpleMigrationStep;
use OCP\Migration\IOutput;
class Version2001Date20171026134605 extends SimpleMigrationStep {
/** @var IDBConnection */
protected $connection;
/**
* @param IDBConnection $connection
*/
public function __construct(IDBConnection $connection) {
$this->connection = $connection;
}
/**
* @param IOutput $output
* @param \Closure $schemaClosure The `\Closure` returns a `Schema`
* @param array $options
* @return null|Schema
* @since 13.0.0
*/
public function changeSchema(IOutput $output, \Closure $schemaClosure, array $options) {
/** @var Schema $schema */
$schema = $schemaClosure();
if (!$schema->hasTable('talk_signaling')) {
$table = $schema->createTable('talk_signaling');
$table->addColumn('sender', Type::STRING, [
'notnull' => true,
'length' => 255,
]);
$table->addColumn('recipient', Type::STRING, [
'notnull' => true,
'length' => 255,
]);
$table->addColumn('message', Type::TEXT, [
'notnull' => true,
]);
$table->addColumn('timestamp', Type::INTEGER, [
'notnull' => true,
'length' => 11,
]);
$table->addIndex(['recipient', 'timestamp'], 'vcsig_recipient');
}
if (!$schema->hasTable('talk_rooms')) {
$table = $schema->createTable('talk_rooms');
$table->addColumn('id', Type::INTEGER, [
'autoincrement' => true,
'notnull' => true,
'length' => 11,
]);
$table->addColumn('name', Type::STRING, [
'notnull' => false,
'length' => 255,
'default' => '',
]);
$table->addColumn('token', Type::STRING, [
'notnull' => false,
'length' => 32,
'default' => '',
]);
$table->addColumn('type', Type::INTEGER, [
'notnull' => true,
'length' => 11,
]);
$table->addColumn('password', Type::STRING, [
'notnull' => false,
'length' => 255,
'default' => '',
]);
$table->addColumn('activeSince', Type::DATETIME, [
'notnull' => false,
]);
$table->addColumn('activeGuests', Type::INTEGER, [
'notnull' => true,
'length' => 4,
'default' => 0,
'unsigned' => true,
]);
$table->setPrimaryKey(['id']);
$table->addUniqueIndex(['token'], 'unique_token');
}
if (!$schema->hasTable('talk_participants')) {
$table = $schema->createTable('talk_participants');
$table->addColumn('userId', Type::STRING, [
'notnull' => false,
'length' => 255,
]);
$table->addColumn('roomId', Type::INTEGER, [
'notnull' => true,
'length' => 11,
]);
$table->addColumn('lastPing', Type::INTEGER, [
'notnull' => true,
'length' => 11,
]);
$table->addColumn('sessionId', Type::STRING, [
'notnull' => true,
'length' => 255,
]);
$table->addColumn('participantType', Type::SMALLINT, [
'notnull' => true,
'length' => 6,
'default' => 0,
]);
}
return $schema;
}
/**
* @param IOutput $output
* @param \Closure $schemaClosure The `\Closure` returns a `Schema`
* @param array $options
* @since 13.0.0
*/
public function postSchemaChange(IOutput $output, \Closure $schemaClosure, array $options) {
$roomIdMap = $this->copyRooms();
$this->copyParticipants($roomIdMap);
$this->fixNotifications($roomIdMap);
$this->fixActivities($roomIdMap);
$this->fixActivityMails($roomIdMap);
}
/**
* @return int[]
*/
protected function copyRooms() {
$roomIdMap = [];
$insert = $this->connection->getQueryBuilder();
$insert->insert('talk_rooms')
->values([
'name' => $insert->createParameter('name'),
'token' => $insert->createParameter('token'),
'type' => $insert->createParameter('type'),
'password' => $insert->createParameter('password'),
]);
$query = $this->connection->getQueryBuilder();
$query->select('*')
->from('spreedme_rooms');
$result = $query->execute();
while ($row = $result->fetch()) {
$insert
->setParameter('name', $row['name'])
->setParameter('token', $row['token'])
->setParameter('type', (int) $row['type'], IQueryBuilder::PARAM_INT)
->setParameter('password', $row['password']);
$insert->execute();
$roomIdMap[(int)$row['id']] = $insert->getLastInsertId();
}
$result->closeCursor();
return $roomIdMap;
}
/**
* @param int[] $roomIdMap
*/
protected function copyParticipants(array $roomIdMap) {
$insert = $this->connection->getQueryBuilder();
$insert->insert('talk_participants')
->values([
'userId' => $insert->createParameter('userId'),
'roomId' => $insert->createParameter('roomId'),
'lastPing' => $insert->createParameter('lastPing'),
'sessionId' => $insert->createParameter('sessionId'),
'participantType' => $insert->createParameter('participantType'),
]);
$query = $this->connection->getQueryBuilder();
$query->select('*')
->from('spreedme_room_participants');
$result = $query->execute();
while ($row = $result->fetch()) {
if (!isset($roomIdMap[(int) $row['roomId']])) {
continue;
}
$insert
->setParameter('userId', $row['userId'])
->setParameter('roomId', $roomIdMap[(int) $row['roomId']], IQueryBuilder::PARAM_INT)
->setParameter('lastPing', (int) $row['lastPing'], IQueryBuilder::PARAM_INT)
->setParameter('sessionId', $row['sessionId'])
->setParameter('participantType', (int) $row['participantType'], IQueryBuilder::PARAM_INT)
;
$insert->execute();
}
$result->closeCursor();
}
/**
* @param int[] $roomIdMap
*/
protected function fixNotifications(array $roomIdMap) {
$update = $this->connection->getQueryBuilder();
$update->update('notifications')
->set('object_id', $update->createParameter('newId'))
->where($update->expr()->eq('notification_id', $update->createParameter('id')));
$delete = $this->connection->getQueryBuilder();
$delete->delete('notifications')
->where($delete->expr()->eq('notification_id', $delete->createParameter('id')));
$query = $this->connection->getQueryBuilder();
$query->select(['notification_id', 'object_id'])
->from('notifications')
->where($query->expr()->eq('app', $query->createNamedParameter('spreed')))
->andWhere($query->expr()->eq('object_type', $query->createNamedParameter('room')));
$result = $query->execute();
while ($row = $result->fetch()) {
if (!isset($roomIdMap[(int) $row['object_id']])) {
$delete
->setParameter('id', (int) $row['notification_id'])
;
$delete->execute();
continue;
}
$update
->setParameter('id', (int) $row['notification_id'])
->setParameter('newId', $roomIdMap[(int) $row['object_id']])
;
$update->execute();
}
$result->closeCursor();
}
/**
* @param int[] $roomIdMap
*/
protected function fixActivities(array $roomIdMap) {
$update = $this->connection->getQueryBuilder();
$update->update('activity')
->set('object_id', $update->createParameter('newId'))
->set('subjectparams', $update->createParameter('subjectParams'))
->where($update->expr()->eq('activity_id', $update->createParameter('id')));
$delete = $this->connection->getQueryBuilder();
$delete->delete('activity')
->where($delete->expr()->eq('activity_id', $delete->createParameter('id')));
$query = $this->connection->getQueryBuilder();
$query->select(['activity_id', 'object_id', 'subjectparams'])
->from('activity')
->where($query->expr()->eq('app', $query->createNamedParameter('spreed')))
->andWhere($query->expr()->eq('type', $query->createNamedParameter('spreed')))
->andWhere($query->expr()->eq('object_type', $query->createNamedParameter('room')));
$result = $query->execute();
while ($row = $result->fetch()) {
if (!isset($roomIdMap[(int) $row['object_id']])) {
$delete
->setParameter('id', (int) $row['activity_id'])
;
$delete->execute();
continue;
}
$params = json_decode($row['subjectparams'], true);
if (!isset($params['room'])) {
$delete
->setParameter('id', (int) $row['activity_id'])
;
$delete->execute();
continue;
}
$params['room'] = $roomIdMap[(int) $row['object_id']];
$update
->setParameter('id', (int) $row['activity_id'])
->setParameter('newId', $roomIdMap[(int) $row['object_id']])
->setParameter('subjectParams', json_encode($params))
;
$update->execute();
}
$result->closeCursor();
}
/**
* @param int[] $roomIdMap
*/
protected function fixActivityMails(array $roomIdMap) {
$update = $this->connection->getQueryBuilder();
$update->update('activity_mq')
->set('amq_subjectparams', $update->createParameter('subjectParams'))
->where($update->expr()->eq('mail_id', $update->createParameter('id')));
$delete = $this->connection->getQueryBuilder();
$delete->delete('activity_mq')
->where($delete->expr()->eq('mail_id', $delete->createParameter('id')));
$query = $this->connection->getQueryBuilder();
$query->select(['mail_id', 'amq_subjectparams'])
->from('activity_mq')
->where($query->expr()->eq('amq_appid', $query->createNamedParameter('spreed')))
->andWhere($query->expr()->eq('amq_type', $query->createNamedParameter('spreed')));
$result = $query->execute();
while ($row = $result->fetch()) {
$params = json_decode($row['subjectparams'], true);
if (!isset($params['room']) || !isset($roomIdMap[(int) $params['room']])) {
$delete
->setParameter('id', (int) $row['mail_id'])
;
$delete->execute();
continue;
}
$params['room'] = $roomIdMap[(int) $params['room']];
$update
->setParameter('id', (int) $row['mail_id'])
->setParameter('subjectParams', json_encode($params))
;
$update->execute();
}
$result->closeCursor();
}
}

View file

@ -0,0 +1,57 @@
<?php
/**
* @copyright Copyright (c) 2017 Joas Schilling <coding@schilljs.com>
*
* @author Joas Schilling <coding@schilljs.com>
*
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
namespace OCA\Spreed\Migration;
use Doctrine\DBAL\Schema\Schema;
use OCP\Migration\SimpleMigrationStep;
use OCP\Migration\IOutput;
class Version2001Date20171026141336 extends SimpleMigrationStep {
/**
* @param IOutput $output
* @param \Closure $schemaClosure The `\Closure` returns a `Schema`
* @param array $options
* @return null|Schema
* @since 13.0.0
*/
public function changeSchema(IOutput $output, \Closure $schemaClosure, array $options) {
/** @var Schema $schema */
$schema = $schemaClosure();
if ($schema->hasTable('videocalls_signaling')) {
$schema->dropTable('videocalls_signaling');
}
if ($schema->hasTable('spreedme_rooms')) {
$schema->dropTable('spreedme_rooms');
}
if ($schema->hasTable('spreedme_room_participants')) {
$schema->dropTable('spreedme_room_participants');
}
return $schema;
}
}

View file

@ -173,7 +173,7 @@ class Room {
$query = $this->db->getQueryBuilder();
$query->select('*')
->from('spreedme_room_participants')
->from('talk_participants')
->where($query->expr()->eq('userId', $query->createNamedParameter($userId)))
->andWhere($query->expr()->eq('roomId', $query->createNamedParameter($this->getId())));
$result = $query->execute();
@ -204,7 +204,7 @@ class Room {
$query = $this->db->getQueryBuilder();
$query->select('*')
->from('spreedme_room_participants')
->from('talk_participants')
->where($query->expr()->eq('sessionId', $query->createNamedParameter($sessionId)))
->andWhere($query->expr()->eq('roomId', $query->createNamedParameter($this->getId())));
$result = $query->execute();
@ -226,12 +226,12 @@ class Room {
$query = $this->db->getQueryBuilder();
// Delete all participants
$query->delete('spreedme_room_participants')
$query->delete('talk_participants')
->where($query->expr()->eq('roomId', $query->createNamedParameter($this->getId(), IQueryBuilder::PARAM_INT)));
$query->execute();
// Delete room
$query->delete('spreedme_rooms')
$query->delete('talk_rooms')
->where($query->expr()->eq('id', $query->createNamedParameter($this->getId(), IQueryBuilder::PARAM_INT)));
$query->execute();
@ -262,7 +262,7 @@ class Room {
]));
$query = $this->db->getQueryBuilder();
$query->update('spreedme_rooms')
$query->update('talk_rooms')
->set('name', $query->createNamedParameter($newName))
->where($query->expr()->eq('id', $query->createNamedParameter($this->getId(), IQueryBuilder::PARAM_INT)));
$query->execute();
@ -292,7 +292,7 @@ class Room {
]));
$query = $this->db->getQueryBuilder();
$query->update('spreedme_rooms')
$query->update('talk_rooms')
->set('password', $query->createNamedParameter($hash))
->where($query->expr()->eq('id', $query->createNamedParameter($this->getId(), IQueryBuilder::PARAM_INT)));
$query->execute();
@ -314,7 +314,7 @@ class Room {
if ($isGuest && $this->getType() === self::PUBLIC_CALL) {
$query = $this->db->getQueryBuilder();
$query->update('spreedme_rooms')
$query->update('talk_rooms')
->set('activeGuests', $query->createFunction($query->getColumnName('activeGuests') . ' + 1'))
->where($query->expr()->eq('id', $query->createNamedParameter($this->getId(), IQueryBuilder::PARAM_INT)));
$query->execute();
@ -327,7 +327,7 @@ class Room {
}
$query = $this->db->getQueryBuilder();
$query->update('spreedme_rooms')
$query->update('talk_rooms')
->set('activeSince', $query->createNamedParameter($since, 'datetime'))
->where($query->expr()->eq('id', $query->createNamedParameter($this->getId(), IQueryBuilder::PARAM_INT)))
->andWhere($query->expr()->isNull('activeSince'));
@ -343,7 +343,7 @@ class Room {
*/
public function resetActiveSince() {
$query = $this->db->getQueryBuilder();
$query->update('spreedme_rooms')
$query->update('talk_rooms')
->set('activeGuests', $query->createNamedParameter(0))
->set('activeSince', $query->createNamedParameter(null, 'datetime'))
->where($query->expr()->eq('id', $query->createNamedParameter($this->getId(), IQueryBuilder::PARAM_INT)));
@ -373,7 +373,7 @@ class Room {
]));
$query = $this->db->getQueryBuilder();
$query->update('spreedme_rooms')
$query->update('talk_rooms')
->set('type', $query->createNamedParameter($newType, IQueryBuilder::PARAM_INT))
->where($query->expr()->eq('id', $query->createNamedParameter($this->getId(), IQueryBuilder::PARAM_INT)));
$query->execute();
@ -383,7 +383,7 @@ class Room {
if ($oldType === self::PUBLIC_CALL) {
// Kick all guests and users that were not invited
$query = $this->db->getQueryBuilder();
$query->delete('spreedme_room_participants')
$query->delete('talk_participants')
->where($query->expr()->eq('roomId', $query->createNamedParameter($this->getId(), IQueryBuilder::PARAM_INT)))
->andWhere($query->expr()->in('participantType', $query->createNamedParameter([Participant::GUEST, Participant::USER_SELF_JOINED], IQueryBuilder::PARAM_INT_ARRAY)));
$query->execute();
@ -406,7 +406,7 @@ class Room {
]));
$query = $this->db->getQueryBuilder();
$query->insert('spreedme_room_participants')
$query->insert('talk_participants')
->values(
[
'userId' => $query->createParameter('userId'),
@ -441,7 +441,7 @@ class Room {
]));
$query = $this->db->getQueryBuilder();
$query->update('spreedme_room_participants')
$query->update('talk_participants')
->set('participantType', $query->createNamedParameter($participantType, IQueryBuilder::PARAM_INT))
->where($query->expr()->eq('roomId', $query->createNamedParameter($this->getId(), IQueryBuilder::PARAM_INT)))
->andWhere($query->expr()->eq('userId', $query->createNamedParameter($participant)));
@ -462,7 +462,7 @@ class Room {
]));
$query = $this->db->getQueryBuilder();
$query->delete('spreedme_room_participants')
$query->delete('talk_participants')
->where($query->expr()->eq('roomId', $query->createNamedParameter($this->getId(), IQueryBuilder::PARAM_INT)))
->andWhere($query->expr()->eq('userId', $query->createNamedParameter($user->getUID())));
$query->execute();
@ -481,7 +481,7 @@ class Room {
]));
$query = $this->db->getQueryBuilder();
$query->delete('spreedme_room_participants')
$query->delete('talk_participants')
->where($query->expr()->eq('roomId', $query->createNamedParameter($this->getId(), IQueryBuilder::PARAM_INT)))
->andWhere($query->expr()->eq('sessionId', $query->createNamedParameter($participant->getSessionId())));
$query->execute();
@ -504,7 +504,7 @@ class Room {
$this->disconnectUserFromAllRooms($userId);
$query = $this->db->getQueryBuilder();
$query->update('spreedme_room_participants')
$query->update('talk_participants')
->set('sessionId', $query->createParameter('sessionId'))
->where($query->expr()->eq('roomId', $query->createNamedParameter($this->getId(), IQueryBuilder::PARAM_INT)))
->andWhere($query->expr()->eq('userId', $query->createNamedParameter($userId)));
@ -545,7 +545,7 @@ class Room {
// Reset sessions on all normal rooms
$query = $this->db->getQueryBuilder();
$query->update('spreedme_room_participants')
$query->update('talk_participants')
->set('sessionId', $query->createNamedParameter('0'))
->where($query->expr()->eq('userId', $query->createNamedParameter($userId)))
->andWhere($query->expr()->neq('participantType', $query->createNamedParameter(Participant::USER_SELF_JOINED, IQueryBuilder::PARAM_INT)));
@ -553,7 +553,7 @@ class Room {
// And kill session on all self joined rooms
$query = $this->db->getQueryBuilder();
$query->delete('spreedme_room_participants')
$query->delete('talk_participants')
->where($query->expr()->eq('userId', $query->createNamedParameter($userId)))
->andWhere($query->expr()->eq('participantType', $query->createNamedParameter(Participant::USER_SELF_JOINED, IQueryBuilder::PARAM_INT)));
$query->execute();
@ -575,7 +575,7 @@ class Room {
}
$sessionId = $this->secureRandom->generate(255);
while (!$this->db->insertIfNotExist('*PREFIX*spreedme_room_participants', [
while (!$this->db->insertIfNotExist('*PREFIX*talk_participants', [
'userId' => '',
'roomId' => $this->getId(),
'lastPing' => 0,
@ -605,7 +605,7 @@ class Room {
protected function isSessionUnique($sessionId) {
$query = $this->db->getQueryBuilder();
$query->selectAlias($query->createFunction('COUNT(*)'), 'num_sessions')
->from('spreedme_room_participants')
->from('talk_participants')
->where($query->expr()->eq('sessionId', $query->createNamedParameter($sessionId)));
$result = $query->execute();
$numSessions = (int) $result->fetchColumn();
@ -618,7 +618,7 @@ class Room {
$this->dispatcher->dispatch(self::class . '::preCleanGuests', new GenericEvent($this));
$query = $this->db->getQueryBuilder();
$query->delete('spreedme_room_participants')
$query->delete('talk_participants')
->where($query->expr()->eq('roomId', $query->createNamedParameter($this->getId(), IQueryBuilder::PARAM_INT)))
->andWhere($query->expr()->emptyString('userId'))
->andWhere($query->expr()->lte('lastPing', $query->createNamedParameter(time() - 30, IQueryBuilder::PARAM_INT)));
@ -634,7 +634,7 @@ class Room {
public function getParticipants($lastPing = 0) {
$query = $this->db->getQueryBuilder();
$query->select('*')
->from('spreedme_room_participants')
->from('talk_participants')
->where($query->expr()->eq('roomId', $query->createNamedParameter($this->getId(), IQueryBuilder::PARAM_INT)));
if ($lastPing > 0) {
@ -672,7 +672,7 @@ class Room {
public function getActiveSessions() {
$query = $this->db->getQueryBuilder();
$query->select('sessionId')
->from('spreedme_room_participants')
->from('talk_participants')
->where($query->expr()->eq('roomId', $query->createNamedParameter($this->getId(), IQueryBuilder::PARAM_INT)))
->andWhere($query->expr()->neq('sessionId', $query->createNamedParameter('0')));
$result = $query->execute();
@ -692,7 +692,7 @@ class Room {
public function hasActiveSessions() {
$query = $this->db->getQueryBuilder();
$query->select('sessionId')
->from('spreedme_room_participants')
->from('talk_participants')
->where($query->expr()->eq('roomId', $query->createNamedParameter($this->getId(), IQueryBuilder::PARAM_INT)))
->andWhere($query->expr()->neq('sessionId', $query->createNamedParameter('0')))
->setMaxResults(1);
@ -710,7 +710,7 @@ class Room {
public function getNumberOfParticipants($lastPing = 0) {
$query = $this->db->getQueryBuilder();
$query->selectAlias($query->createFunction('COUNT(*)'), 'num_participants')
->from('spreedme_room_participants')
->from('talk_participants')
->where($query->expr()->eq('roomId', $query->createNamedParameter($this->getId(), IQueryBuilder::PARAM_INT)));
if ($lastPing > 0) {
@ -731,7 +731,7 @@ class Room {
*/
public function ping($userId, $sessionId, $timestamp) {
$query = $this->db->getQueryBuilder();
$query->update('spreedme_room_participants')
$query->update('talk_participants')
->set('lastPing', $query->createNamedParameter($timestamp, IQueryBuilder::PARAM_INT))
->where($query->expr()->eq('userId', $query->createNamedParameter((string) $userId)))
->andWhere($query->expr()->eq('sessionId', $query->createNamedParameter($sessionId)))

View file

@ -49,7 +49,7 @@ class Messages {
*/
public function deleteMessages(array $sessionIds) {
$query = $this->db->getQueryBuilder();
$query->delete('videocalls_signaling')
$query->delete('talk_signaling')
->where($query->expr()->in('recipient', $query->createNamedParameter($sessionIds, IQueryBuilder::PARAM_STR_ARRAY)))
->orWhere($query->expr()->in('sender', $query->createNamedParameter($sessionIds, IQueryBuilder::PARAM_STR_ARRAY)));
$query->execute();
@ -62,7 +62,7 @@ class Messages {
*/
public function addMessage($senderSessionId, $recipientSessionId, $message) {
$query = $this->db->getQueryBuilder();
$query->insert('videocalls_signaling')
$query->insert('talk_signaling')
->values(
[
'sender' => $query->createNamedParameter($senderSessionId),
@ -80,7 +80,7 @@ class Messages {
*/
public function addMessageForAllParticipants(Room $room, $message) {
$query = $this->db->getQueryBuilder();
$query->insert('videocalls_signaling')
$query->insert('talk_signaling')
->values(
[
'sender' => $query->createParameter('sender'),
@ -114,7 +114,7 @@ class Messages {
$query = $this->db->getQueryBuilder();
$query->select('*')
->from('videocalls_signaling')
->from('talk_signaling')
->where($query->expr()->eq('recipient', $query->createNamedParameter($sessionId)))
->andWhere($query->expr()->lte('timestamp', $query->createNamedParameter($time)));
$result = $query->execute();
@ -125,7 +125,7 @@ class Messages {
$result->closeCursor();
$query = $this->db->getQueryBuilder();
$query->delete('videocalls_signaling')
$query->delete('talk_signaling')
->where($query->expr()->eq('recipient', $query->createNamedParameter($sessionId)))
->andWhere($query->expr()->lte('timestamp', $query->createNamedParameter($time)));
$query->execute();
@ -142,7 +142,7 @@ class Messages {
$time = $this->time->getTime() - $olderThan;
$query = $this->db->getQueryBuilder();
$query->delete('videocalls_signaling')
$query->delete('talk_signaling')
->where($query->expr()->lt('timestamp', $query->createNamedParameter($time)));
$query->execute();
}

View file

@ -51,13 +51,13 @@ class ApiController extends OCSController {
public function resetSpreed() {
$query = $this->db->getQueryBuilder();
$query->delete('videocalls_signaling')->execute();
$query->delete('talk_signaling')->execute();
$query = $this->db->getQueryBuilder();
$query->delete('spreedme_rooms')->execute();
$query->delete('talk_rooms')->execute();
$query = $this->db->getQueryBuilder();
$query->delete('spreedme_room_participants')->execute();
$query->delete('talk_participants')->execute();
return new DataResponse();
}