diff options
author | Catalin Badea <catalin.badea392@gmail.com> | 2012-08-02 15:01:55 (GMT) |
---|---|---|
committer | Cătălin Badea <catalin.badea392@gmail.com> | 2012-08-11 15:59:13 (GMT) |
commit | 2316553cb5a191e0e8b098bb5b39fba0d9e37b13 (patch) | |
tree | e3f905491ffa65ff83c069a792d5b851d10b2134 /Swiften | |
parent | f3401e17bf241734414a3ff84e94ee64b882bcbc (diff) | |
download | swift-contrib-2316553cb5a191e0e8b098bb5b39fba0d9e37b13.zip swift-contrib-2316553cb5a191e0e8b098bb5b39fba0d9e37b13.tar.bz2 |
use local db when joining a muc.
Diffstat (limited to 'Swiften')
-rw-r--r-- | Swiften/History/HistoryManager.h | 1 | ||||
-rw-r--r-- | Swiften/History/SQLiteHistoryManager.cpp | 37 | ||||
-rw-r--r-- | Swiften/History/SQLiteHistoryManager.h | 1 |
3 files changed, 38 insertions, 1 deletions
diff --git a/Swiften/History/HistoryManager.h b/Swiften/History/HistoryManager.h index 104f0ad..33e9143 100644 --- a/Swiften/History/HistoryManager.h +++ b/Swiften/History/HistoryManager.h @@ -29,5 +29,6 @@ namespace Swift { virtual std::vector<HistoryMessage> getMessagesFromNextDate(const JID& selfJID, const JID& contactJID, HistoryMessage::Type type, const boost::gregorian::date& date) const = 0; virtual std::vector<HistoryMessage> getMessagesFromPreviousDate(const JID& selfJID, const JID& contactJID, HistoryMessage::Type type, const boost::gregorian::date& date) const = 0; virtual ContactsMap getContacts(const JID& selfJID, HistoryMessage::Type type, const std::string& keyword) const = 0; + virtual boost::posix_time::ptime getLastTimeStampFromMUC(const JID& selfJID, const JID& mucJID) const = 0; }; } diff --git a/Swiften/History/SQLiteHistoryManager.cpp b/Swiften/History/SQLiteHistoryManager.cpp index 3b90219..e385b1e 100644 --- a/Swiften/History/SQLiteHistoryManager.cpp +++ b/Swiften/History/SQLiteHistoryManager.cpp @@ -136,7 +136,10 @@ std::vector<HistoryMessage> SQLiteHistoryManager::getMessagesFromDate(const JID& int secondsSinceEpoch(sqlite3_column_int(selectStatement, 6)); boost::posix_time::ptime time(boost::gregorian::date(1970, 1, 1), boost::posix_time::seconds(secondsSinceEpoch)); - result.push_back(HistoryMessage(message, (fromJID ? *fromJID : JID()), (toJID ? *toJID : JID()), type, time)); + // offset from utc + int offset = sqlite3_column_int(selectStatement, 7); + + result.push_back(HistoryMessage(message, (fromJID ? *fromJID : JID()), (toJID ? *toJID : JID()), type, time, offset)); r = sqlite3_step(selectStatement); } if (r != SQLITE_DONE) { @@ -336,4 +339,36 @@ std::vector<HistoryMessage> SQLiteHistoryManager::getMessagesFromPreviousDate(co return getMessagesFromDate(selfJID, contactJID, type, previousDate); } +boost::posix_time::ptime SQLiteHistoryManager::getLastTimeStampFromMUC(const JID& selfJID, const JID& mucJID) const { + boost::optional<int> selfID = getIDFromJID(selfJID.toBare()); + boost::optional<int> mucID = getIDFromJID(mucJID.toBare()); + + if (!selfID || !mucID) { + // JIDs missing from the database + return boost::posix_time::ptime(boost::posix_time::not_a_date_time); + } + + + sqlite3_stmt* selectStatement; + std::string selectQuery = "SELECT messages.'time', messages.'offset' from messages WHERE type=1 AND (toBare=" + + boost::lexical_cast<std::string>(*selfID) + " AND fromBare=" + + boost::lexical_cast<std::string>(*mucID) + ") ORDER BY time DESC LIMIT 1"; + + int r = sqlite3_prepare(db_, selectQuery.c_str(), selectQuery.size(), &selectStatement, NULL); + if (r != SQLITE_OK) { + std::cout << "Error: " << sqlite3_errmsg(db_) << std::endl; + } + + r = sqlite3_step(selectStatement); + if (r == SQLITE_ROW) { + int secondsSinceEpoch(sqlite3_column_int(selectStatement, 0)); + boost::posix_time::ptime time(boost::gregorian::date(1970, 1, 1), boost::posix_time::seconds(secondsSinceEpoch)); + int offset = sqlite3_column_int(selectStatement, 1); + + return time - boost::posix_time::hours(offset); + } + + return boost::posix_time::ptime(boost::posix_time::not_a_date_time); +} + } diff --git a/Swiften/History/SQLiteHistoryManager.h b/Swiften/History/SQLiteHistoryManager.h index 8b08e6b..b74fbde 100644 --- a/Swiften/History/SQLiteHistoryManager.h +++ b/Swiften/History/SQLiteHistoryManager.h @@ -23,6 +23,7 @@ namespace Swift { std::vector<HistoryMessage> getMessagesFromDate(const JID& selfJID, const JID& contactJID, HistoryMessage::Type type, const boost::gregorian::date& date) const; std::vector<HistoryMessage> getMessagesFromNextDate(const JID& selfJID, const JID& contactJID, HistoryMessage::Type type, const boost::gregorian::date& date) const; std::vector<HistoryMessage> getMessagesFromPreviousDate(const JID& selfJID, const JID& contactJID, HistoryMessage::Type type, const boost::gregorian::date& date) const; + boost::posix_time::ptime getLastTimeStampFromMUC(const JID& selfJID, const JID& mucJID) const; private: boost::gregorian::date getNextDateWithLogs(const JID& selfJID, const JID& contactJID, HistoryMessage::Type type, const boost::gregorian::date& date, bool reverseOrder) const; |