Commit 7f3dfc26 authored by Matthieu Tanon's avatar Matthieu Tanon

Fix chatRoomId refactoring, selectGenericConferenceEvent and selectGenericConferenceNotifiedEvent

parent f566cb70
...@@ -60,18 +60,18 @@ private: ...@@ -60,18 +60,18 @@ private:
const tm &creationTime const tm &creationTime
); );
long long insertChatRoom (const std::shared_ptr<AbstractChatRoom> &chatRoom, unsigned int notifyId = 0); long long insertChatRoom (const std::shared_ptr<AbstractChatRoom> &chatRoom, unsigned int notifyId = 0);
long long insertChatRoomParticipant (long long conferenceId, long long participantSipAddressId, bool isAdmin); long long insertChatRoomParticipant (long long chatRoomId, long long participantSipAddressId, bool isAdmin);
void insertChatRoomParticipantDevice (long long participantId, long long participantDeviceSipAddressId); void insertChatRoomParticipantDevice (long long participantId, long long participantDeviceSipAddressId);
void insertChatMessageParticipant (long long chatMessageId, long long sipAddressId, int state, time_t stateChangeTime); void insertChatMessageParticipant (long long chatMessageId, long long sipAddressId, int state, time_t stateChangeTime);
long long selectSipAddressId (const std::string &sipAddress) const; long long selectSipAddressId (const std::string &sipAddress) const;
long long selectChatRoomId (long long peerSipAddressId, long long localSipAddressId) const; long long selectChatRoomId (long long peerSipAddressId, long long localSipAddressId) const;
long long selectChatRoomId (const ConferenceId &conferenceId) const; long long selectChatRoomId (const ConferenceId &conferenceId) const;
long long selectChatRoomParticipantId (long long conferenceId, long long participantSipAddressId) const; long long selectChatRoomParticipantId (long long chatRoomId, long long participantSipAddressId) const;
long long selectOneToOneChatRoomId (long long sipAddressIdA, long long sipAddressIdB, bool encrypted) const; long long selectOneToOneChatRoomId (long long sipAddressIdA, long long sipAddressIdB, bool encrypted) const;
void deleteContents (long long chatMessageId); void deleteContents (long long chatMessageId);
void deleteChatRoomParticipant (long long conferenceId, long long participantSipAddressId); void deleteChatRoomParticipant (long long chatRoomId, long long participantSipAddressId);
void deleteChatRoomParticipantDevice (long long participantId, long long participantDeviceSipAddressId); void deleteChatRoomParticipantDevice (long long participantId, long long participantDeviceSipAddressId);
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
...@@ -98,7 +98,7 @@ private: ...@@ -98,7 +98,7 @@ private:
const soci::row &row const soci::row &row
) const; ) const;
std::shared_ptr<EventLog> selectGenericConferenceNotifiedEvent ( std::shared_ptr<EventLog> selectConferenceInfoEvent (
const ConferenceId &conferenceId, const ConferenceId &conferenceId,
const soci::row &row const soci::row &row
) const; ) const;
...@@ -146,12 +146,12 @@ private: ...@@ -146,12 +146,12 @@ private:
) const; ) const;
long long insertEvent (const std::shared_ptr<EventLog> &eventLog); long long insertEvent (const std::shared_ptr<EventLog> &eventLog);
long long insertConferenceEvent (const std::shared_ptr<EventLog> &eventLog, long long *conferenceId = nullptr); long long insertConferenceEvent (const std::shared_ptr<EventLog> &eventLog, long long *chatRoomId = nullptr);
long long insertConferenceCallEvent (const std::shared_ptr<EventLog> &eventLog); long long insertConferenceCallEvent (const std::shared_ptr<EventLog> &eventLog);
long long insertConferenceChatMessageEvent (const std::shared_ptr<EventLog> &eventLog); long long insertConferenceChatMessageEvent (const std::shared_ptr<EventLog> &eventLog);
void updateConferenceChatMessageEvent(const std::shared_ptr<EventLog> &eventLog); void updateConferenceChatMessageEvent(const std::shared_ptr<EventLog> &eventLog);
long long insertConferenceNotifiedEvent (const std::shared_ptr<EventLog> &eventLog, long long *conferenceId = nullptr); long long insertConferenceNotifiedEvent (const std::shared_ptr<EventLog> &eventLog, long long *chatRoomId = nullptr);
long long insertConferenceParticipantEvent (const std::shared_ptr<EventLog> &eventLog, long long *conferenceId = nullptr); long long insertConferenceParticipantEvent (const std::shared_ptr<EventLog> &eventLog, long long *chatRoomId = nullptr);
long long insertConferenceParticipantDeviceEvent (const std::shared_ptr<EventLog> &eventLog); long long insertConferenceParticipantDeviceEvent (const std::shared_ptr<EventLog> &eventLog);
long long insertConferenceSubjectEvent (const std::shared_ptr<EventLog> &eventLog); long long insertConferenceSubjectEvent (const std::shared_ptr<EventLog> &eventLog);
long long insertConferenceSecurityEvent (const std::shared_ptr<EventLog> &eventLog); long long insertConferenceSecurityEvent (const std::shared_ptr<EventLog> &eventLog);
...@@ -173,7 +173,7 @@ private: ...@@ -173,7 +173,7 @@ private:
std::shared_ptr<EventLog> getEventFromCache (long long storageId) const; std::shared_ptr<EventLog> getEventFromCache (long long storageId) const;
std::shared_ptr<ChatMessage> getChatMessageFromCache (long long storageId) const; std::shared_ptr<ChatMessage> getChatMessageFromCache (long long storageId) const;
void invalidConferenceEventsFromQuery (const std::string &query, long long conferenceId); void invalidConferenceEventsFromQuery (const std::string &query, long long chatRoomId);
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
// Versions. // Versions.
......
...@@ -337,7 +337,7 @@ long long MainDbPrivate::insertChatRoom (const shared_ptr<AbstractChatRoom> &cha ...@@ -337,7 +337,7 @@ long long MainDbPrivate::insertChatRoom (const shared_ptr<AbstractChatRoom> &cha
long long id = selectChatRoomId(peerSipAddressId, localSipAddressId); long long id = selectChatRoomId(peerSipAddressId, localSipAddressId);
if (id >= 0) { if (id >= 0) {
// The chat room is already stored in DB, but still update the notify id that might have changed // The chat room is already stored in DB, but still update the notify id that might have changed
*dbSession.getBackendSession() << "UPDATE chat_room SET last_notify_id = :lastNotifyId WHERE id = :conferenceId", *dbSession.getBackendSession() << "UPDATE chat_room SET last_notify_id = :lastNotifyId WHERE id = :chatRoomId",
soci::use(notifyId), soci::use(id); soci::use(notifyId), soci::use(id);
return id; return id;
} }
...@@ -390,12 +390,12 @@ long long MainDbPrivate::insertChatRoom (const shared_ptr<AbstractChatRoom> &cha ...@@ -390,12 +390,12 @@ long long MainDbPrivate::insertChatRoom (const shared_ptr<AbstractChatRoom> &cha
} }
long long MainDbPrivate::insertChatRoomParticipant ( long long MainDbPrivate::insertChatRoomParticipant (
long long conferenceId, long long chatRoomId,
long long participantSipAddressId, long long participantSipAddressId,
bool isAdmin bool isAdmin
) { ) {
soci::session *session = dbSession.getBackendSession(); soci::session *session = dbSession.getBackendSession();
long long id = selectChatRoomParticipantId(conferenceId, participantSipAddressId); long long id = selectChatRoomParticipantId(chatRoomId, participantSipAddressId);
if (id >= 0) { if (id >= 0) {
// See: https://stackoverflow.com/a/15299655 (cast to reference) // See: https://stackoverflow.com/a/15299655 (cast to reference)
*session << "UPDATE chat_room_participant SET is_admin = :isAdmin WHERE id = :id", *session << "UPDATE chat_room_participant SET is_admin = :isAdmin WHERE id = :id",
...@@ -404,8 +404,8 @@ long long MainDbPrivate::insertChatRoomParticipant ( ...@@ -404,8 +404,8 @@ long long MainDbPrivate::insertChatRoomParticipant (
} }
*session << "INSERT INTO chat_room_participant (chat_room_id, participant_sip_address_id, is_admin)" *session << "INSERT INTO chat_room_participant (chat_room_id, participant_sip_address_id, is_admin)"
" VALUES (:conferenceId, :participantSipAddressId, :isAdmin)", " VALUES (:chatRoomId, :participantSipAddressId, :isAdmin)",
soci::use(conferenceId), soci::use(participantSipAddressId), soci::use(static_cast<const int &>(isAdmin)); soci::use(chatRoomId), soci::use(participantSipAddressId), soci::use(static_cast<const int &>(isAdmin));
return dbSession.getLastInsertId(); return dbSession.getLastInsertId();
} }
...@@ -470,12 +470,12 @@ long long MainDbPrivate::selectChatRoomId (const ConferenceId &conferenceId) con ...@@ -470,12 +470,12 @@ long long MainDbPrivate::selectChatRoomId (const ConferenceId &conferenceId) con
return selectChatRoomId(peerSipAddressId, localSipAddressId); return selectChatRoomId(peerSipAddressId, localSipAddressId);
} }
long long MainDbPrivate::selectChatRoomParticipantId (long long conferenceId, long long participantSipAddressId) const { long long MainDbPrivate::selectChatRoomParticipantId (long long chatRoomId, long long participantSipAddressId) const {
long long id; long long id;
soci::session *session = dbSession.getBackendSession(); soci::session *session = dbSession.getBackendSession();
*session << Statements::get(Statements::SelectChatRoomParticipantId), *session << Statements::get(Statements::SelectChatRoomParticipantId),
soci::use(conferenceId), soci::use(participantSipAddressId), soci::into(id); soci::use(chatRoomId), soci::use(participantSipAddressId), soci::into(id);
return session->got_data() ? id : -1; return session->got_data() ? id : -1;
} }
...@@ -502,10 +502,10 @@ void MainDbPrivate::deleteContents (long long chatMessageId) { ...@@ -502,10 +502,10 @@ void MainDbPrivate::deleteContents (long long chatMessageId) {
soci::use(chatMessageId); soci::use(chatMessageId);
} }
void MainDbPrivate::deleteChatRoomParticipant (long long conferenceId, long long participantSipAddressId) { void MainDbPrivate::deleteChatRoomParticipant (long long chatRoomId, long long participantSipAddressId) {
*dbSession.getBackendSession() << "DELETE FROM chat_room_participant" *dbSession.getBackendSession() << "DELETE FROM chat_room_participant"
" WHERE chat_room_id = :conferenceId AND participant_sip_address_id = :participantSipAddressId", " WHERE chat_room_id = :chatRoomId AND participant_sip_address_id = :participantSipAddressId",
soci::use(conferenceId), soci::use(participantSipAddressId); soci::use(chatRoomId), soci::use(participantSipAddressId);
} }
void MainDbPrivate::deleteChatRoomParticipantDevice ( void MainDbPrivate::deleteChatRoomParticipantDevice (
...@@ -531,28 +531,17 @@ shared_ptr<EventLog> MainDbPrivate::selectGenericConferenceEvent ( ...@@ -531,28 +531,17 @@ shared_ptr<EventLog> MainDbPrivate::selectGenericConferenceEvent (
long long eventId = getConferenceEventIdFromRow(row); long long eventId = getConferenceEventIdFromRow(row);
shared_ptr<EventLog> eventLog = getEventFromCache(eventId); shared_ptr<EventLog> eventLog = getEventFromCache(eventId);
if (!eventLog) { if (!eventLog) {
EventLog::Type type = EventLog::Type(row.get<int>(1)); eventLog = selectConferenceChatMessageEvent(chatRoom, type, row);
switch (type) {
case EventLog::Type::ConferenceChatMessage:
eventLog = selectConferenceChatMessageEvent(chatRoom, type, row);
break;
case EventLog::Type::ConferenceSecurityEvent:
eventLog = selectConferenceSecurityEvent(chatRoom->getConferenceId(), type, row);
break;
default:
return nullptr;
}
if (eventLog) if (eventLog)
cache(eventLog, eventId); cache(eventLog, eventId);
} }
return eventLog; return eventLog;
} }
return selectGenericConferenceNotifiedEvent(chatRoom->getConferenceId(), row); return selectConferenceInfoEvent(chatRoom->getConferenceId(), row);
} }
shared_ptr<EventLog> MainDbPrivate::selectGenericConferenceNotifiedEvent ( shared_ptr<EventLog> MainDbPrivate::selectConferenceInfoEvent (
const ConferenceId &conferenceId, const ConferenceId &conferenceId,
const soci::row &row const soci::row &row
) const { ) const {
...@@ -589,13 +578,13 @@ shared_ptr<EventLog> MainDbPrivate::selectGenericConferenceNotifiedEvent ( ...@@ -589,13 +578,13 @@ shared_ptr<EventLog> MainDbPrivate::selectGenericConferenceNotifiedEvent (
eventLog = selectConferenceParticipantDeviceEvent(conferenceId, type, row); eventLog = selectConferenceParticipantDeviceEvent(conferenceId, type, row);
break; break;
case EventLog::Type::ConferenceSecurityEvent:
eventLog = selectConferenceSecurityEvent(conferenceId, type, row);
break;
case EventLog::Type::ConferenceSubjectChanged: case EventLog::Type::ConferenceSubjectChanged:
eventLog = selectConferenceSubjectEvent(conferenceId, type, row); eventLog = selectConferenceSubjectEvent(conferenceId, type, row);
break; break;
case EventLog::Type::ConferenceSecurityEvent:
eventLog = selectConferenceSecurityEvent(conferenceId, type, row);
break;
} }
if (eventLog) if (eventLog)
...@@ -732,36 +721,36 @@ long long MainDbPrivate::insertEvent (const shared_ptr<EventLog> &eventLog) { ...@@ -732,36 +721,36 @@ long long MainDbPrivate::insertEvent (const shared_ptr<EventLog> &eventLog) {
return dbSession.getLastInsertId(); return dbSession.getLastInsertId();
} }
long long MainDbPrivate::insertConferenceEvent (const shared_ptr<EventLog> &eventLog, long long *conferenceId) { long long MainDbPrivate::insertConferenceEvent (const shared_ptr<EventLog> &eventLog, long long *chatRoomId) {
shared_ptr<ConferenceEvent> conferenceEvent = static_pointer_cast<ConferenceEvent>(eventLog); shared_ptr<ConferenceEvent> conferenceEvent = static_pointer_cast<ConferenceEvent>(eventLog);
long long eventId = -1; long long eventId = -1;
const long long &curConferenceId = selectChatRoomId(conferenceEvent->getConferenceId()); const ConferenceId &conferenceId = conferenceEvent->getConferenceId();
if (curConferenceId < 0) { const long long &curChatRoomId = selectChatRoomId(conferenceId);
if (curChatRoomId < 0) {
// A conference event can be inserted in database only if chat room exists. // A conference event can be inserted in database only if chat room exists.
// Otherwise it's an error. // Otherwise it's an error.
const ConferenceId &conferenceId = conferenceEvent->getConferenceId();
lError() << "Unable to find chat room storage id of: " << conferenceId << "."; lError() << "Unable to find chat room storage id of: " << conferenceId << ".";
} else { } else {
eventId = insertEvent(eventLog); eventId = insertEvent(eventLog);
soci::session *session = dbSession.getBackendSession(); soci::session *session = dbSession.getBackendSession();
*session << "INSERT INTO conference_event (event_id, chat_room_id)" *session << "INSERT INTO conference_event (event_id, chat_room_id)"
" VALUES (:eventId, :conferenceId)", soci::use(eventId), soci::use(curConferenceId); " VALUES (:eventId, :chatRoomId)", soci::use(eventId), soci::use(curChatRoomId);
const tm &lastUpdateTime = Utils::getTimeTAsTm(eventLog->getCreationTime()); const tm &lastUpdateTime = Utils::getTimeTAsTm(eventLog->getCreationTime());
*session << "UPDATE chat_room SET last_update_time = :lastUpdateTime" *session << "UPDATE chat_room SET last_update_time = :lastUpdateTime"
" WHERE id = :conferenceId", soci::use(lastUpdateTime), " WHERE id = :chatRoomId", soci::use(lastUpdateTime),
soci::use(curConferenceId); soci::use(curChatRoomId);
if (eventLog->getType() == EventLog::Type::ConferenceTerminated) if (eventLog->getType() == EventLog::Type::ConferenceTerminated)
*session << "UPDATE chat_room SET flags = 1, last_notify_id = 0 WHERE id = :conferenceId", soci::use(curConferenceId); *session << "UPDATE chat_room SET flags = 1, last_notify_id = 0 WHERE id = :chatRoomId", soci::use(curChatRoomId);
else if (eventLog->getType() == EventLog::Type::ConferenceCreated) else if (eventLog->getType() == EventLog::Type::ConferenceCreated)
*session << "UPDATE chat_room SET flags = 0 WHERE id = :conferenceId", soci::use(curConferenceId); *session << "UPDATE chat_room SET flags = 0 WHERE id = :chatRoomId", soci::use(curChatRoomId);
} }
if (conferenceId) if (chatRoomId)
*conferenceId = curConferenceId; *chatRoomId = curChatRoomId;
return eventId; return eventId;
} }
...@@ -874,9 +863,9 @@ void MainDbPrivate::updateConferenceChatMessageEvent (const shared_ptr<EventLog> ...@@ -874,9 +863,9 @@ void MainDbPrivate::updateConferenceChatMessageEvent (const shared_ptr<EventLog>
setChatMessageParticipantState(eventLog, participant->getAddress(), state, std::time(nullptr)); setChatMessageParticipantState(eventLog, participant->getAddress(), state, std::time(nullptr));
} }
long long MainDbPrivate::insertConferenceNotifiedEvent (const shared_ptr<EventLog> &eventLog, long long *conferenceId) { long long MainDbPrivate::insertConferenceNotifiedEvent (const shared_ptr<EventLog> &eventLog, long long *chatRoomId) {
long long curConferenceId; long long curChatRoomId;
const long long &eventId = insertConferenceEvent(eventLog, &curConferenceId); const long long &eventId = insertConferenceEvent(eventLog, &curChatRoomId);
if (eventId < 0) if (eventId < 0)
return -1; return -1;
...@@ -885,21 +874,21 @@ long long MainDbPrivate::insertConferenceNotifiedEvent (const shared_ptr<EventLo ...@@ -885,21 +874,21 @@ long long MainDbPrivate::insertConferenceNotifiedEvent (const shared_ptr<EventLo
soci::session *session = dbSession.getBackendSession(); soci::session *session = dbSession.getBackendSession();
*session << "INSERT INTO conference_notified_event (event_id, notify_id)" *session << "INSERT INTO conference_notified_event (event_id, notify_id)"
" VALUES (:eventId, :notifyId)", soci::use(eventId), soci::use(lastNotifyId); " VALUES (:eventId, :notifyId)", soci::use(eventId), soci::use(lastNotifyId);
*session << "UPDATE chat_room SET last_notify_id = :lastNotifyId WHERE id = :conferenceId", *session << "UPDATE chat_room SET last_notify_id = :lastNotifyId WHERE id = :chatRoomId",
soci::use(lastNotifyId), soci::use(curConferenceId); soci::use(lastNotifyId), soci::use(curChatRoomId);
if (conferenceId) if (chatRoomId)
*conferenceId = curConferenceId; *chatRoomId = curChatRoomId;
return eventId; return eventId;
} }
long long MainDbPrivate::insertConferenceParticipantEvent ( long long MainDbPrivate::insertConferenceParticipantEvent (
const shared_ptr<EventLog> &eventLog, const shared_ptr<EventLog> &eventLog,
long long *conferenceId long long *chatRoomId
) { ) {
long long curConferenceId; long long curChatRoomId;
const long long &eventId = insertConferenceNotifiedEvent(eventLog, &curConferenceId); const long long &eventId = insertConferenceNotifiedEvent(eventLog, &curChatRoomId);
if (eventId < 0) if (eventId < 0)
return -1; return -1;
...@@ -918,26 +907,26 @@ long long MainDbPrivate::insertConferenceParticipantEvent ( ...@@ -918,26 +907,26 @@ long long MainDbPrivate::insertConferenceParticipantEvent (
case EventLog::Type::ConferenceParticipantAdded: case EventLog::Type::ConferenceParticipantAdded:
case EventLog::Type::ConferenceParticipantSetAdmin: case EventLog::Type::ConferenceParticipantSetAdmin:
case EventLog::Type::ConferenceParticipantUnsetAdmin: case EventLog::Type::ConferenceParticipantUnsetAdmin:
insertChatRoomParticipant(curConferenceId, participantAddressId, isAdmin); insertChatRoomParticipant(curChatRoomId, participantAddressId, isAdmin);
break; break;
case EventLog::Type::ConferenceParticipantRemoved: case EventLog::Type::ConferenceParticipantRemoved:
deleteChatRoomParticipant(curConferenceId, participantAddressId); deleteChatRoomParticipant(curChatRoomId, participantAddressId);
break; break;
default: default:
break; break;
} }
if (conferenceId) if (chatRoomId)
*conferenceId = curConferenceId; *chatRoomId = curChatRoomId;
return eventId; return eventId;
} }
long long MainDbPrivate::insertConferenceParticipantDeviceEvent (const shared_ptr<EventLog> &eventLog) { long long MainDbPrivate::insertConferenceParticipantDeviceEvent (const shared_ptr<EventLog> &eventLog) {
long long conferenceId; long long chatRoomId;
const long long &eventId = insertConferenceParticipantEvent(eventLog, &conferenceId); const long long &eventId = insertConferenceParticipantEvent(eventLog, &chatRoomId);
if (eventId < 0) if (eventId < 0)
return -1; return -1;
...@@ -950,9 +939,9 @@ long long MainDbPrivate::insertConferenceParticipantDeviceEvent (const shared_pt ...@@ -950,9 +939,9 @@ long long MainDbPrivate::insertConferenceParticipantDeviceEvent (const shared_pt
lError() << "Unable to find sip address id of: `" << participantAddress << "`."; lError() << "Unable to find sip address id of: `" << participantAddress << "`.";
return -1; return -1;
} }
const long long &participantId = selectChatRoomParticipantId(conferenceId, participantAddressId); const long long &participantId = selectChatRoomParticipantId(chatRoomId, participantAddressId);
if (participantId < 0) { if (participantId < 0) {
lError() << "Unable to find valid participant id in database with chat room id = " << conferenceId << lError() << "Unable to find valid participant id in database with chat room id = " << chatRoomId <<
" and participant address id = " << participantAddressId; " and participant address id = " << participantAddressId;
return -1; return -1;
} }
...@@ -980,8 +969,8 @@ long long MainDbPrivate::insertConferenceParticipantDeviceEvent (const shared_pt ...@@ -980,8 +969,8 @@ long long MainDbPrivate::insertConferenceParticipantDeviceEvent (const shared_pt
} }
long long MainDbPrivate::insertConferenceSecurityEvent (const shared_ptr<EventLog> &eventLog) { long long MainDbPrivate::insertConferenceSecurityEvent (const shared_ptr<EventLog> &eventLog) {
long long conferenceId; long long chatRoomId;
const long long &eventId = insertConferenceEvent(eventLog, &conferenceId); const long long &eventId = insertConferenceEvent(eventLog, &chatRoomId);
if (eventId < 0) if (eventId < 0)
return -1; return -1;
...@@ -997,8 +986,8 @@ long long MainDbPrivate::insertConferenceSecurityEvent (const shared_ptr<EventLo ...@@ -997,8 +986,8 @@ long long MainDbPrivate::insertConferenceSecurityEvent (const shared_ptr<EventLo
} }
long long MainDbPrivate::insertConferenceSubjectEvent (const shared_ptr<EventLog> &eventLog) { long long MainDbPrivate::insertConferenceSubjectEvent (const shared_ptr<EventLog> &eventLog) {
long long conferenceId; long long chatRoomId;
const long long &eventId = insertConferenceNotifiedEvent(eventLog, &conferenceId); const long long &eventId = insertConferenceNotifiedEvent(eventLog, &chatRoomId);
if (eventId < 0) if (eventId < 0)
return -1; return -1;
...@@ -1009,7 +998,7 @@ long long MainDbPrivate::insertConferenceSubjectEvent (const shared_ptr<EventLog ...@@ -1009,7 +998,7 @@ long long MainDbPrivate::insertConferenceSubjectEvent (const shared_ptr<EventLog
" VALUES (:eventId, :subject)", soci::use(eventId), soci::use(subject); " VALUES (:eventId, :subject)", soci::use(eventId), soci::use(subject);
*session << "UPDATE chat_room SET subject = :subject" *session << "UPDATE chat_room SET subject = :subject"
" WHERE id = :conferenceId", soci::use(subject), soci::use(conferenceId); " WHERE id = :chatRoomId", soci::use(subject), soci::use(chatRoomId);
return eventId; return eventId;
} }
...@@ -1077,8 +1066,8 @@ void MainDbPrivate::cache (const shared_ptr<ChatMessage> &chatMessage, long long ...@@ -1077,8 +1066,8 @@ void MainDbPrivate::cache (const shared_ptr<ChatMessage> &chatMessage, long long
L_ASSERT(dChatMessage->dbKey.isValid()); L_ASSERT(dChatMessage->dbKey.isValid());
} }
void MainDbPrivate::invalidConferenceEventsFromQuery (const string &query, long long conferenceId) { void MainDbPrivate::invalidConferenceEventsFromQuery (const string &query, long long chatRoomId) {
soci::rowset<soci::row> rows = (dbSession.getBackendSession()->prepare << query, soci::use(conferenceId)); soci::rowset<soci::row> rows = (dbSession.getBackendSession()->prepare << query, soci::use(chatRoomId));
for (const auto &row : rows) { for (const auto &row : rows) {
long long eventId = dbSession.resolveId(row, 0); long long eventId = dbSession.resolveId(row, 0);
shared_ptr<EventLog> eventLog = getEventFromCache(eventId); shared_ptr<EventLog> eventLog = getEventFromCache(eventId);
...@@ -1400,7 +1389,7 @@ void MainDbPrivate::importLegacyHistory (DbSession &inDbSession) { ...@@ -1400,7 +1389,7 @@ void MainDbPrivate::importLegacyHistory (DbSession &inDbSession) {
const long long &remoteSipAddressId = insertSipAddress( const long long &remoteSipAddressId = insertSipAddress(
IdentityAddress(message.get<string>(LegacyMessageColRemoteAddress)).asString() IdentityAddress(message.get<string>(LegacyMessageColRemoteAddress)).asString()
); );
const long long &conferenceId = insertOrUpdateImportedBasicChatRoom( const long long &chatRoomId = insertOrUpdateImportedBasicChatRoom(
remoteSipAddressId, remoteSipAddressId,
localSipAddressId, localSipAddressId,
creationTime creationTime
...@@ -1410,7 +1399,7 @@ void MainDbPrivate::importLegacyHistory (DbSession &inDbSession) { ...@@ -1410,7 +1399,7 @@ void MainDbPrivate::importLegacyHistory (DbSession &inDbSession) {
const int displayNotificationRequired = 0; const int displayNotificationRequired = 0;
*session << "INSERT INTO conference_event (event_id, chat_room_id)" *session << "INSERT INTO conference_event (event_id, chat_room_id)"
" VALUES (:eventId, :conferenceId)", soci::use(eventId), soci::use(conferenceId); " VALUES (:eventId, :chatRoomId)", soci::use(eventId), soci::use(chatRoomId);
*session << "INSERT INTO conference_chat_message_event (" *session << "INSERT INTO conference_chat_message_event ("
" event_id, from_sip_address_id, to_sip_address_id," " event_id, from_sip_address_id, to_sip_address_id,"
...@@ -1426,7 +1415,7 @@ void MainDbPrivate::importLegacyHistory (DbSession &inDbSession) { ...@@ -1426,7 +1415,7 @@ void MainDbPrivate::importLegacyHistory (DbSession &inDbSession) {
if (content) if (content)
insertContent(eventId, *content); insertContent(eventId, *content);
insertChatRoomParticipant(conferenceId, remoteSipAddressId, false); insertChatRoomParticipant(chatRoomId, remoteSipAddressId, false);
insertChatMessageParticipant(eventId, remoteSipAddressId, state, std::time(nullptr)); insertChatMessageParticipant(eventId, remoteSipAddressId, state, std::time(nullptr));
} }
tr.commit(); tr.commit();
...@@ -1996,12 +1985,12 @@ list<shared_ptr<EventLog>> MainDb::getConferenceNotifiedEvents ( ...@@ -1996,12 +1985,12 @@ list<shared_ptr<EventLog>> MainDb::getConferenceNotifiedEvents (
soci::session *session = d->dbSession.getBackendSession(); soci::session *session = d->dbSession.getBackendSession();
const long long &dbConferenceId = d->selectChatRoomId(conferenceId); const long long &dbChatRoomId = d->selectChatRoomId(conferenceId);
list<shared_ptr<EventLog>> events; list<shared_ptr<EventLog>> events;
soci::rowset<soci::row> rows = (session->prepare << query, soci::use(dbConferenceId), soci::use(lastNotifyId)); soci::rowset<soci::row> rows = (session->prepare << query, soci::use(dbChatRoomId), soci::use(lastNotifyId));
for (const auto &row : rows) for (const auto &row : rows)
events.push_back(d->selectGenericConferenceNotifiedEvent(conferenceId, row)); events.push_back(d->selectConferenceInfoEvent(conferenceId, row));
return events; return events;
}; };
} }
...@@ -2024,11 +2013,11 @@ int MainDb::getChatMessageCount (const ConferenceId &conferenceId) const { ...@@ -2024,11 +2013,11 @@ int MainDb::getChatMessageCount (const ConferenceId &conferenceId) const {
*session << query, soci::into(count); *session << query, soci::into(count);
else { else {
query += " WHERE event_id IN (" query += " WHERE event_id IN ("
" SELECT event_id FROM conference_event WHERE chat_room_id = :conferenceId" " SELECT event_id FROM conference_event WHERE chat_room_id = :chatRoomId"
")"; ")";
const long long &dbConferenceId = d->selectChatRoomId(conferenceId); const long long &dbChatRoomId = d->selectChatRoomId(conferenceId);
*session << query, soci::use(dbConferenceId), soci::into(count); *session << query, soci::use(dbChatRoomId), soci::into(count);
} }
return count; return count;
...@@ -2045,7 +2034,7 @@ int MainDb::getUnreadChatMessageCount (const ConferenceId &conferenceId) const { ...@@ -2045,7 +2034,7 @@ int MainDb::getUnreadChatMessageCount (const ConferenceId &conferenceId) const {
string query = "SELECT COUNT(*) FROM conference_chat_message_event WHERE"; string query = "SELECT COUNT(*) FROM conference_chat_message_event WHERE";
if (conferenceId.isValid()) if (conferenceId.isValid())
query += " event_id IN (" query += " event_id IN ("
" SELECT event_id FROM conference_event WHERE chat_room_id = :conferenceId" " SELECT event_id FROM conference_event WHERE chat_room_id = :chatRoomId"
") AND"; ") AND";
query += " direction = " + Utils::toString(int(ChatMessage::Direction::Incoming)) + query += " direction = " + Utils::toString(int(ChatMessage::Direction::Incoming)) +
...@@ -2064,8 +2053,8 @@ int MainDb::getUnreadChatMessageCount (const ConferenceId &conferenceId) const { ...@@ -2064,8 +2053,8 @@ int MainDb::getUnreadChatMessageCount (const ConferenceId &conferenceId) const {
if (!conferenceId.isValid()) if (!conferenceId.isValid())
*session << query, soci::into(count); *session << query, soci::into(count);
else { else {
const long long &dbConferenceId = d->selectChatRoomId(conferenceId); const long long &dbChatRoomId = d->selectChatRoomId(conferenceId);
*session << query, soci::use(dbConferenceId), soci::into(count); *session << query, soci::use(dbChatRoomId), soci::into(count);
} }
d->unreadChatMessageCountCache.insert(conferenceId, count); d->unreadChatMessageCountCache.insert(conferenceId, count);
...@@ -2080,7 +2069,7 @@ void MainDb::markChatMessagesAsRead (const ConferenceId &conferenceId) const { ...@@ -2080,7 +2069,7 @@ void MainDb::markChatMessagesAsRead (const ConferenceId &conferenceId) const {
static const string query = "UPDATE conference_chat_message_event" static const string query = "UPDATE conference_chat_message_event"
" SET state = " + Utils::toString(int(ChatMessage::State::Displayed)) + " SET state = " + Utils::toString(int(ChatMessage::State::Displayed)) +
" WHERE event_id IN (" " WHERE event_id IN ("
" SELECT event_id FROM conference_event WHERE chat_room_id = :conferenceId" " SELECT event_id FROM conference_event WHERE chat_room_id = :chatRoomId"
") AND direction = " + Utils::toString(int(ChatMessage::Direction::Incoming)); ") AND direction = " + Utils::toString(int(ChatMessage::Direction::Incoming));
DurationLogger durationLogger( DurationLogger durationLogger(
...@@ -2091,8 +2080,8 @@ void MainDb::markChatMessagesAsRead (const ConferenceId &conferenceId) const { ...@@ -2091,8 +2080,8 @@ void MainDb::markChatMessagesAsRead (const ConferenceId &conferenceId) const {
L_DB_TRANSACTION { L_DB_TRANSACTION {
L_D(); L_D();
const long long &dbConferenceId = d->selectChatRoomId(conferenceId); const long long &dbChatRoomId = d->selectChatRoomId(conferenceId);
*d->dbSession.getBackendSession() << query, soci::use(dbConferenceId); *d->dbSession.getBackendSession() << query, soci::use(dbChatRoomId);
tr.commit(); tr.commit();
d->unreadChatMessageCountCache.insert(conferenceId, 0); d->unreadChatMessageCountCache.insert(conferenceId, 0);
...@@ -2115,13 +2104,13 @@ list<shared_ptr<ChatMessage>> MainDb::getUnreadChatMessages (const ConferenceId ...@@ -2115,13 +2104,13 @@ list<shared_ptr<ChatMessage>> MainDb::getUnreadChatMessages (const ConferenceId
soci::session *session = d->dbSession.getBackendSession(); soci::session *session = d->dbSession.getBackendSession();
long long dbConferenceId = d->selectChatRoomId(conferenceId); long long dbChatRoomId = d->selectChatRoomId(conferenceId);
shared_ptr<AbstractChatRoom> chatRoom = d->findChatRoom(conferenceId); shared_ptr<AbstractChatRoom> chatRoom = d->findChatRoom(conferenceId);
list<shared_ptr<ChatMessage>> chatMessages; list<shared_ptr<ChatMessage>> chatMessages;
if (!chatRoom) if (!chatRoom)
return chatMessages; return chatMessages;
soci::rowset<soci::row> rows = (session->prepare << query, soci::use(dbConferenceId)); soci::rowset<soci::row> rows = (session->prepare << query, soci::use(dbChatRoomId));
for (const auto &row : rows) { for (const auto &row : rows) {
shared_ptr<EventLog> event = d->selectGenericConferenceEvent( shared_ptr<EventLog> event = d->selectGenericConferenceEvent(
chatRoom, chatRoom,
...@@ -2249,9 +2238,9 @@ list<shared_ptr<ChatMessage>> MainDb::findChatMessages ( ...@@ -2249,9 +2238,9 @@ list<shared_ptr<ChatMessage>> MainDb::findChatMessages (
if (!chatRoom) if (!chatRoom)
return chatMessages; return chatMessages;
const long long &dbConferenceId = d->selectChatRoomId(conferenceId); const long long &dbChatRoomId = d->selectChatRoomId(conferenceId);
soci::rowset<soci::row> rows = ( soci::rowset<soci::row> rows = (
d->dbSession.getBackendSession()->prepare << query, soci::use(dbConferenceId), soci::use(imdnMessageId) d->dbSession.getBackendSession()->prepare << query, soci::use(dbChatRoomId), soci::use(imdnMessageId)
); );
for (const auto &row : rows) { for (const auto &row : rows) {
shared_ptr<EventLog> event = d->selectGenericConferenceEvent(chatRoom, row); shared_ptr<EventLog> event = d->selectGenericConferenceEvent(chatRoom, row);
...@@ -2284,10 +2273,10 @@ list<shared_ptr<ChatMessage>> MainDb::findChatMessagesToBeNotifiedAsDelivered ( ...@@ -2284,10 +2273,10 @@ list<shared_ptr<ChatMessage>> MainDb::findChatMessagesToBeNotifiedAsDelivered (
if (!chatRoom) if (!chatRoom)
return chatMessages; return chatMessages;
const long long &dbConferenceId = d->selectChatRoomId(conferenceId); const long long &dbChatRoomId = d->selectChatRoomId(conferenceId);
const int &direction = int(ChatMessage::Direction::Incoming); const int &direction = int(ChatMessage::Direction::Incoming);
soci::rowset<soci::row> rows = ( soci::rowset<soci::row> rows = (
d->dbSession.getBackendSession()->prepare << query, soci::use(dbConferenceId), soci::use(direction) d->dbSession.getBackendSession()->prepare << query, soci::use(dbChatRoomId), soci::use(direction)
); );
for (const auto &row : rows) { for (const auto &row : rows) {
shared_ptr<EventLog> event = d->selectGenericConferenceEvent(chatRoom, row); shared_ptr<EventLog> event = d->selectGenericConferenceEvent(chatRoom, row);
...@@ -2348,8 +2337,8 @@ list<shared_ptr<EventLog>> MainDb::getHistoryRange ( ...@@ -2348,8 +2337,8 @@ list<shared_ptr<EventLog>> MainDb::getHistoryRange (
if (!chatRoom) if (!chatRoom)
return events; return events;
const long long &dbConferenceId = d->selectChatRoomId(conferenceId); const long long &dbChatRoomId = d->selectChatRoomId(conferenceId);
soci::rowset<soci::row> rows = (d->dbSession.getBackendSession()->prepare << query, soci::use(dbConferenceId)); soci::rowset<soci::row> rows = (d->dbSession.getBackendSession()->prepare << query, soci::use(dbChatRoomId));
for (const auto &row : rows) { for (const auto &row : rows) {
shared_ptr<EventLog> event = d->selectGenericConferenceEvent(chatRoom, row); shared_ptr<EventLog> event = d->selectGenericConferenceEvent(chatRoom, row);
if (event) if (event)
...@@ -2362,7 +2351,7 @@ list<shared_ptr<EventLog>> MainDb::getHistoryRange ( ...@@ -2362,7 +2351,7 @@ list<shared_ptr<EventLog>> MainDb::getHistoryRange (
int MainDb::getHistorySize (const ConferenceId &conferenceId, FilterMask mask) const { int MainDb::getHistorySize (const ConferenceId &conferenceId, FilterMask mask) const {
const string query = "SELECT COUNT(*) FROM event, conference_event" const string query = "SELECT COUNT(*) FROM event, conference_event"
" WHERE chat_room_id = :conferenceId" " WHERE chat_room_id = :chatRoomId"
" AND event_id = event.id" + buildSqlEventFilter({ " AND event_id = event.id" + buildSqlEventFilter({
ConferenceCallFilter, ConferenceChatMessageFilter, ConferenceInfoFilter, ConferenceInfoNoDeviceFilter ConferenceCallFilter, ConferenceChatMessageFilter, ConferenceInfoFilter, ConferenceInfoNoDeviceFilter
}, mask, "AND"); }, mask, "AND");
...@@ -2371,8 +2360,8 @@ int MainDb::getHistorySize (const ConferenceId &conferenceId, FilterMask mask) c ...@@ -2371,8 +2360,8 @@ int MainDb::getHistorySize (const ConferenceId &conferenceId, FilterMask mask) c
L_D(); L_D();