From 9be191f71246c7f3b19233abe64971a3d0751434 Mon Sep 17 00:00:00 2001 From: Ronan Abhamon Date: Wed, 18 Oct 2017 10:27:23 +0200 Subject: [PATCH] feat(MainDb): store last notify id --- src/db/main-db-p.h | 2 +- src/db/main-db.cpp | 27 ++++++++++++++------------- 2 files changed, 15 insertions(+), 14 deletions(-) diff --git a/src/db/main-db-p.h b/src/db/main-db-p.h index fef0bd127..84fdf413c 100644 --- a/src/db/main-db-p.h +++ b/src/db/main-db-p.h @@ -64,7 +64,7 @@ private: long insertEvent (const EventLog &eventLog); long insertCallEvent (const EventLog &eventLog); long insertMessageEvent (const EventLog &eventLog); - long insertConferenceEvent (const EventLog &eventLog); + long insertConferenceEvent (const EventLog &eventLog, long *chatRoomId = nullptr); long insertConferenceNotifiedEvent (const EventLog &eventLog); long insertConferenceParticipantEvent (const EventLog &eventLog); long insertConferenceParticipantDeviceEvent (const EventLog &eventLog); diff --git a/src/db/main-db.cpp b/src/db/main-db.cpp index 8df3f068b..5376a8f87 100644 --- a/src/db/main-db.cpp +++ b/src/db/main-db.cpp @@ -273,9 +273,7 @@ MainDb::MainDb () : AbstractDb(*new MainDbPrivate) {} eventTime ); - insertChatRoomParticipant(references.chatRoomId, references.remoteSipAddressId, false); - - long eventId = insertMessageEvent ( + return insertMessageEvent ( references, static_cast(chatMessage->getState()), static_cast(chatMessage->getDirection()), @@ -283,31 +281,34 @@ MainDb::MainDb () : AbstractDb(*new MainDbPrivate) {} chatMessage->isSecured(), chatMessage->getContents() ); - - return eventId; } - long MainDbPrivate::insertConferenceEvent (const EventLog &eventLog) { + long MainDbPrivate::insertConferenceEvent (const EventLog &eventLog, long *chatRoomId) { long eventId = insertEvent(eventLog); - long chatRoomId = insertSipAddress( + long curChatRoomId = insertSipAddress( static_cast(eventLog).getConferenceAddress().asString() ); soci::session *session = dbSession.getBackendSession(); *session << "INSERT INTO conference_event (event_id, chat_room_id)" - " VALUES (:eventId, :chatRoomId)", soci::use(eventId), soci::use(chatRoomId); + " VALUES (:eventId, :chatRoomId)", soci::use(eventId), soci::use(curChatRoomId); + + if (chatRoomId) + *chatRoomId = curChatRoomId; return eventId; } long MainDbPrivate::insertConferenceNotifiedEvent (const EventLog &eventLog) { - long eventId = insertConferenceEvent(eventLog); + long chatRoomId; + long eventId = insertConferenceEvent(eventLog, &chatRoomId); + unsigned int lastNotifyId = static_cast(eventLog).getNotifyId(); soci::session *session = dbSession.getBackendSession(); *session << "INSERT INTO conference_notified_event (event_id, notify_id)" - " VALUES (:eventId, :notifyId)", soci::use(eventId), soci::use( - static_cast(eventLog).getNotifyId() - ); + " VALUES (:eventId, :notifyId)", soci::use(eventId), soci::use(lastNotifyId); + *session << "UPDATE chat_room SET last_notify_id = :lastNotifyId WHERE peer_sip_address_id = :chatRoomId", + soci::use(lastNotifyId), soci::use(chatRoomId); return eventId; } @@ -420,7 +421,7 @@ MainDb::MainDb () : AbstractDb(*new MainDbPrivate) {} // Chatroom subject. " subject VARCHAR(255)," - " last_notify INT UNSIGNED," + " last_notify_id INT UNSIGNED," " FOREIGN KEY (peer_sip_address_id)" " REFERENCES sip_address(id)"