From 814d279f56586e911cda88e127a1e32a68b445f0 Mon Sep 17 00:00:00 2001 From: Ronan Abhamon Date: Mon, 9 Oct 2017 16:50:25 +0200 Subject: [PATCH] fix(EventsDb): repare getMessagesCount --- src/db/events-db.cpp | 40 +++++++++++++++++++++------------------- src/db/events-db.h | 10 +++++----- 2 files changed, 26 insertions(+), 24 deletions(-) diff --git a/src/db/events-db.cpp b/src/db/events-db.cpp index 0cc4e0062..fa2c2db65 100644 --- a/src/db/events-db.cpp +++ b/src/db/events-db.cpp @@ -529,34 +529,36 @@ EventsDb::EventsDb () : AbstractDb(*new EventsDbPrivate) {} return count; } - int EventsDb::getMessagesCount (const string &remoteAddress) const { + int EventsDb::getMessagesCount (const string &peerAddress) const { L_D(); if (!isConnected()) { lWarning() << "Unable to get messages count. Not connected."; return 0; } - - string query = "SELECT COUNT(*) FROM message_event"; - if (!remoteAddress.empty()) - query += " WHERE chat_room_id = (" - " SELECT id FROM dialog WHERE remote_sip_address_id =(" - " SELECT id FROM sip_address WHERE value = :remote_address" - " )" - " )"; int count = 0; L_BEGIN_LOG_EXCEPTION soci::session *session = d->dbSession.getBackendSession(); - *session << query, soci::use(remoteAddress), soci::into(count); + + string query = "SELECT COUNT(*) FROM message_event"; + if (peerAddress.empty()) + *session << query, soci::into(count); + else { + query += " WHERE chat_room_id = (" + " SELECT id FROM sip_address WHERE value = :peerSipAddress" + ")"; + + *session << query, soci::use(peerAddress), soci::into(count); + } L_END_LOG_EXCEPTION return count; } - int EventsDb::getUnreadMessagesCount (const string &remoteAddress) const { + int EventsDb::getUnreadMessagesCount (const string &peerAddress) const { L_D(); if (!isConnected()) { @@ -565,7 +567,7 @@ EventsDb::EventsDb () : AbstractDb(*new EventsDbPrivate) {} } string query = "SELECT COUNT(*) FROM message_event"; - if (!remoteAddress.empty()) + if (!peerAddress.empty()) query += " WHERE chat_room_id = (" " SELECT id FROM dialog WHERE remote_sip_address_id = (" " SELECT id FROM sip_address WHERE value = :remote_address" @@ -578,28 +580,28 @@ EventsDb::EventsDb () : AbstractDb(*new EventsDbPrivate) {} L_BEGIN_LOG_EXCEPTION soci::session *session = d->dbSession.getBackendSession(); - *session << query, soci::use(remoteAddress), soci::into(count); + *session << query, soci::use(peerAddress), soci::into(count); L_END_LOG_EXCEPTION return count; } - list> EventsDb::getHistory (const string &remoteAddress, int nLast, FilterMask mask) const { + list> EventsDb::getHistory (const string &peerAddress, int nLast, FilterMask mask) const { if (!isConnected()) { lWarning() << "Unable to get history. Not connected."; return list>(); } // TODO. - (void)remoteAddress; + (void)peerAddress; (void)nLast; (void)mask; return list>(); } list> EventsDb::getHistory ( - const string &remoteAddress, + const string &peerAddress, int begin, int end, FilterMask mask @@ -610,21 +612,21 @@ EventsDb::EventsDb () : AbstractDb(*new EventsDbPrivate) {} } // TODO. - (void)remoteAddress; + (void)peerAddress; (void)begin; (void)end; (void)mask; return list>(); } - void EventsDb::cleanHistory (const string &remoteAddress) { + void EventsDb::cleanHistory (const string &peerAddress) { if (!isConnected()) { lWarning() << "Unable to clean history. Not connected."; return; } // TODO. - (void)remoteAddress; + (void)peerAddress; } // ----------------------------------------------------------------------------- diff --git a/src/db/events-db.h b/src/db/events-db.h index 6e997ff0a..030ff7eeb 100644 --- a/src/db/events-db.h +++ b/src/db/events-db.h @@ -51,20 +51,20 @@ public: int getEventsCount (FilterMask mask = NoFilter) const; // Messages, calls and conferences. - int getMessagesCount (const std::string &remoteAddress = "") const; - int getUnreadMessagesCount (const std::string &remoteAddress = "") const; + int getMessagesCount (const std::string &peerAddress = "") const; + int getUnreadMessagesCount (const std::string &peerAddress = "") const; std::list> getHistory ( - const std::string &remoteAddress, + const std::string &peerAddress, int nLast, FilterMask mask = NoFilter ) const; std::list> getHistory ( - const std::string &remoteAddress, + const std::string &peerAddress, int begin, int end, FilterMask mask = NoFilter ) const; - void cleanHistory (const std::string &remoteAddress = ""); + void cleanHistory (const std::string &peerAddress = ""); bool import (Backend backend, const std::string ¶meters) override;