Commit 68ce70b0 authored by Ghislain MARY's avatar Ghislain MARY

Allow storage of participant device state in database.

parent 790b9486
......@@ -26,6 +26,7 @@
#include "chat-room-p.h"
#include "server-group-chat-room.h"
#include "conference/participant-device.h"
// =============================================================================
......@@ -41,6 +42,9 @@ public:
std::shared_ptr<Participant> findFilteredParticipant (const std::shared_ptr<const CallSession> &session) const;
std::shared_ptr<Participant> findFilteredParticipant (const IdentityAddress &participantAddress) const;
ParticipantDevice::State getParticipantDeviceState (const std::shared_ptr<const ParticipantDevice> &device) const;
void setParticipantDeviceState (const std::shared_ptr<ParticipantDevice> &device, ParticipantDevice::State state);
void confirmCreation ();
void confirmJoining (SalCallOp *op);
void confirmRecreation (SalCallOp *op);
......
......@@ -42,6 +42,14 @@ shared_ptr<Participant> ServerGroupChatRoomPrivate::findFilteredParticipant (con
return nullptr;
}
ParticipantDevice::State ServerGroupChatRoomPrivate::getParticipantDeviceState (const std::shared_ptr<const ParticipantDevice> &device) const {
return device->getState();
}
void ServerGroupChatRoomPrivate::setParticipantDeviceState (const std::shared_ptr<ParticipantDevice> &device, ParticipantDevice::State state) {
device->setState(state);
}
// -----------------------------------------------------------------------------
void ServerGroupChatRoomPrivate::confirmCreation () {}
......
......@@ -156,6 +156,7 @@ private:
unsigned int getModuleVersion (const std::string &name);
void updateModuleVersion (const std::string &name, unsigned int version);
void updateSchema ();
// ---------------------------------------------------------------------------
// Import.
......
......@@ -36,7 +36,7 @@
#include "main-db-key-p.h"
#include "main-db-p.h"
#define DB_MODULE_VERSION_EVENTS L_VERSION(1, 0, 0)
#define DB_MODULE_VERSION_EVENTS L_VERSION(1, 0, 1)
#define DB_MODULE_VERSION_FRIENDS L_VERSION(1, 0, 0)
#define DB_MODULE_VERSION_LEGACY_FRIENDS_IMPORT L_VERSION(1, 0, 0)
#define DB_MODULE_VERSION_LEGACY_HISTORY_IMPORT L_VERSION(1, 0, 0)
......@@ -1133,6 +1133,15 @@ void MainDbPrivate::updateModuleVersion (const string &name, unsigned int versio
soci::use(name), soci::use(version);
}
void MainDbPrivate::updateSchema () {
soci::session *session = dbSession.getBackendSession();
unsigned int version = getModuleVersion("events");
if (version < L_VERSION(1, 0, 1)) {
*session << "ALTER TABLE chat_room_participant_device ADD COLUMN state TINYINT UNSIGNED DEFAULT 0";
}
}
// -----------------------------------------------------------------------------
#define CHECK_LEGACY_TABLE_EXISTS(SESSION, NAME) \
......@@ -1752,6 +1761,8 @@ void MainDb::init () {
" version INT UNSIGNED NOT NULL"
") " + charset;
d->updateSchema();
d->updateModuleVersion("events", DB_MODULE_VERSION_EVENTS);
d->updateModuleVersion("friends", DB_MODULE_VERSION_FRIENDS);
}
......@@ -2696,6 +2707,28 @@ void MainDb::enableChatRoomMigration (const ChatRoomId &chatRoomId, bool enable)
};
}
void MainDb::updateChatRoomParticipantDevice (const shared_ptr<AbstractChatRoom> &chatRoom, const shared_ptr<ParticipantDevice> &device) {
L_SAFE_TRANSACTION {
L_D();
soci::session *session = d->dbSession.getBackendSession();
soci::transaction tr(*session);
const long long &dbChatRoomId = d->selectChatRoomId(chatRoom->getChatRoomId());
const long long &participantSipAddressId = d->selectSipAddressId(device->getParticipant()->getAddress().asString());
const long long &participantId = d->selectChatRoomParticipantId(dbChatRoomId, participantSipAddressId);
const long long &participantSipDeviceAddressId = d->selectSipAddressId(device->getAddress().asString());
unsigned int stateInt = static_cast<unsigned int>(device->getState());
*session << "UPDATE chat_room_participant_device SET state = :state"
" WHERE chat_room_participant_id = :participantId AND participant_device_sip_address_id = :participantSipDeviceAddressId",
soci::use(stateInt), soci::use(participantId), soci::use(participantSipDeviceAddressId);
tr.commit();
return true;
};
}
// -----------------------------------------------------------------------------
bool MainDb::import (Backend, const string &parameters) {
......
......@@ -38,6 +38,7 @@ class Core;
class EventLog;
class MainDbKey;
class MainDbPrivate;
class ParticipantDevice;
class MainDb : public AbstractDb, public CoreAccessor {
friend class MainDbChatMessageKey;
......@@ -135,6 +136,8 @@ public:
) const;
void insertOneToOneConferenceChatRoom (const std::shared_ptr<AbstractChatRoom> &chatRoom);
void updateChatRoomParticipantDevice (const std::shared_ptr<AbstractChatRoom> &chatRoom, const std::shared_ptr<ParticipantDevice> &device);
// ---------------------------------------------------------------------------
// Other.
// ---------------------------------------------------------------------------
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment