summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'Swiften/History/SQLiteHistoryManager.cpp')
-rw-r--r--Swiften/History/SQLiteHistoryManager.cpp37
1 files changed, 36 insertions, 1 deletions
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);
+}
+
}