From be19ba1a3e2e214ba559b1b7168e90f1551d88f0 Mon Sep 17 00:00:00 2001 From: Ronan Abhamon Date: Mon, 23 Oct 2017 10:22:21 +0200 Subject: [PATCH] feat(MainDb): fetch ConferenceSubjectEvent => OK --- src/db/main-db-p.h | 55 ++++++++++++++++++++++++++---- src/db/main-db.cpp | 85 +++++++++++++++++++++++++++++++++++++--------- 2 files changed, 117 insertions(+), 23 deletions(-) diff --git a/src/db/main-db-p.h b/src/db/main-db-p.h index 11dd2308b..1d896dbf5 100644 --- a/src/db/main-db-p.h +++ b/src/db/main-db-p.h @@ -50,13 +50,54 @@ private: // Events API. // --------------------------------------------------------------------------- - std::shared_ptr selectEvent (long eventId, EventLog::Type type, time_t date) const; - std::shared_ptr selectConferenceEvent (long eventId, EventLog::Type type, time_t date) const; - std::shared_ptr selectConferenceCallEvent (long eventId, EventLog::Type type, time_t date) const; - std::shared_ptr selectConferenceChatMessageEvent (long eventId, EventLog::Type type, time_t date) const; - std::shared_ptr selectConferenceParticipantEvent (long eventId, EventLog::Type type, time_t date) const; - std::shared_ptr selectConferenceParticipantDeviceEvent (long eventId, EventLog::Type type, time_t date) const; - std::shared_ptr selectConferenceSubjectEvent (long eventId, EventLog::Type type, time_t date) const; + std::shared_ptr selectEventFromPeerAddress ( + long eventId, + EventLog::Type type, + time_t date, + const std::string &peerAddress + ) const; + + std::shared_ptr selectConferenceEvent ( + long eventId, + EventLog::Type type, + time_t date, + const std::string &peerAddress + ) const; + + std::shared_ptr selectConferenceCallEvent ( + long eventId, + EventLog::Type type, + time_t date, + const std::string &peerAddress + ) const; + + std::shared_ptr selectConferenceChatMessageEvent ( + long eventId, + EventLog::Type type, + time_t date, + const std::string &peerAddress + ) const; + + std::shared_ptr selectConferenceParticipantEvent ( + long eventId, + EventLog::Type type, + time_t date, + const std::string &peerAddress + ) const; + + std::shared_ptr selectConferenceParticipantDeviceEvent ( + long eventId, + EventLog::Type type, + time_t date, + const std::string &peerAddress + ) const; + + std::shared_ptr selectConferenceSubjectEvent ( + long eventId, + EventLog::Type type, + time_t date, + const std::string &peerAddress + ) const; long insertEvent (const EventLog &eventLog); long insertConferenceEvent (const EventLog &eventLog, long *chatRoomId = nullptr); diff --git a/src/db/main-db.cpp b/src/db/main-db.cpp index 6c3ecffcb..25cc4e00d 100644 --- a/src/db/main-db.cpp +++ b/src/db/main-db.cpp @@ -205,67 +205,115 @@ MainDb::MainDb () : AbstractDb(*new MainDbPrivate) {} // ----------------------------------------------------------------------------- - shared_ptr MainDbPrivate::selectEvent (long eventId, EventLog::Type type, time_t date) const { + shared_ptr MainDbPrivate::selectEventFromPeerAddress ( + long eventId, + EventLog::Type type, + time_t date, + const string &peerAddress + ) const { switch (type) { case EventLog::Type::None: return nullptr; case EventLog::Type::ConferenceCreated: case EventLog::Type::ConferenceDestroyed: - return selectConferenceEvent(eventId, type, date); + return selectConferenceEvent(eventId, type, date, peerAddress); case EventLog::Type::CallStart: case EventLog::Type::CallEnd: - return selectConferenceCallEvent(eventId, type, date); + return selectConferenceCallEvent(eventId, type, date, peerAddress); case EventLog::Type::ConferenceChatMessage: - return selectConferenceChatMessageEvent(eventId, type, date); + return selectConferenceChatMessageEvent(eventId, type, date, peerAddress); case EventLog::Type::ConferenceParticipantAdded: case EventLog::Type::ConferenceParticipantRemoved: case EventLog::Type::ConferenceParticipantSetAdmin: case EventLog::Type::ConferenceParticipantUnsetAdmin: - return selectConferenceParticipantEvent(eventId, type, date); + return selectConferenceParticipantEvent(eventId, type, date, peerAddress); case EventLog::Type::ConferenceParticipantDeviceAdded: case EventLog::Type::ConferenceParticipantDeviceRemoved: - return selectConferenceParticipantDeviceEvent(eventId, type, date); + return selectConferenceParticipantDeviceEvent(eventId, type, date, peerAddress); case EventLog::Type::ConferenceSubjectChanged: - return selectConferenceSubjectEvent(eventId, type, date); + return selectConferenceSubjectEvent(eventId, type, date, peerAddress); } return nullptr; } - shared_ptr MainDbPrivate::selectConferenceEvent (long eventId, EventLog::Type type, time_t date) const { + shared_ptr MainDbPrivate::selectConferenceEvent ( + long eventId, + EventLog::Type type, + time_t date, + const string &peerAddress + ) const { // TODO. return nullptr; } - shared_ptr MainDbPrivate::selectConferenceCallEvent (long eventId, EventLog::Type type, time_t date) const { + shared_ptr MainDbPrivate::selectConferenceCallEvent ( + long eventId, + EventLog::Type type, + time_t date, + const string &peerAddress + ) const { // TODO. return nullptr; } - shared_ptr MainDbPrivate::selectConferenceChatMessageEvent (long eventId, EventLog::Type type, time_t date) const { + shared_ptr MainDbPrivate::selectConferenceChatMessageEvent ( + long eventId, + EventLog::Type type, + time_t date, + const string &peerAddress + ) const { // TODO. return nullptr; } - shared_ptr MainDbPrivate::selectConferenceParticipantEvent (long eventId, EventLog::Type type, time_t date) const { + shared_ptr MainDbPrivate::selectConferenceParticipantEvent ( + long eventId, + EventLog::Type type, + time_t date, + const string &peerAddress + ) const { // TODO. return nullptr; } - shared_ptr MainDbPrivate::selectConferenceParticipantDeviceEvent (long eventId, EventLog::Type type, time_t date) const { + shared_ptr MainDbPrivate::selectConferenceParticipantDeviceEvent ( + long eventId, + EventLog::Type type, + time_t date, + const string &peerAddress + ) const { // TODO. return nullptr; } - shared_ptr MainDbPrivate::selectConferenceSubjectEvent (long eventId, EventLog::Type type, time_t date) const { - // TODO. - return nullptr; + shared_ptr MainDbPrivate::selectConferenceSubjectEvent ( + long eventId, + EventLog::Type type, + time_t date, + const string &peerAddress + ) const { + soci::session *session = dbSession.getBackendSession(); + + unsigned int notifyId; + string subject; + + *session << "SELECT notify_id, subject FROM conference_subject_event WHERE event_id = :eventId", + soci::use(eventId), soci::into(notifyId), soci::into(subject); + + // TODO: Use cache. + return make_shared( + date, + Address(peerAddress), + notifyId, + subject + ); } // ----------------------------------------------------------------------------- @@ -859,7 +907,12 @@ MainDb::MainDb () : AbstractDb(*new MainDbPrivate) {} soci::rowset rows = (session->prepare << query, soci::use(peerAddress)); for (const auto &row : rows) { tm date = row.get(2); - events.push_back(d->selectEvent(row.get(0), static_cast(row.get(1)), mktime(&date))); + events.push_back(d->selectConferenceEvent( + row.get(0), + static_cast(row.get(1)), + mktime(&date), + peerAddress + )); } L_END_LOG_EXCEPTION