summaryrefslogtreecommitdiffstats
path: root/Swift
diff options
context:
space:
mode:
Diffstat (limited to 'Swift')
-rw-r--r--Swift/Controllers/Chat/MUCController.cpp20
-rw-r--r--Swift/Controllers/Chat/MUCController.h1
-rw-r--r--Swift/Controllers/HistoryController.cpp9
-rw-r--r--Swift/Controllers/HistoryController.h3
4 files changed, 30 insertions, 3 deletions
diff --git a/Swift/Controllers/Chat/MUCController.cpp b/Swift/Controllers/Chat/MUCController.cpp
index bdc9b20..68be032 100644
--- a/Swift/Controllers/Chat/MUCController.cpp
+++ b/Swift/Controllers/Chat/MUCController.cpp
@@ -196,10 +196,10 @@ void MUCController::rejoin() {
}
//FIXME: check for received activity
if (lastActivity_ == boost::posix_time::not_a_date_time) {
- muc_->joinAs(nick_);
- } else {
- muc_->joinWithContextSince(nick_, lastActivity_);
+ lastActivity_ = historyController_->getLastTimeStampFromMUC(selfJID_, toJID_);
}
+
+ muc_->joinWithContextSince(nick_, lastActivity_);
}
}
@@ -275,6 +275,9 @@ void MUCController::handleJoinComplete(const std::string& nick) {
std::string joinMessage = str(format(QT_TRANSLATE_NOOP("", "You have entered room %1% as %2%.")) % toJID_.toString() % nick);
nick_ = nick;
chatWindow_->addSystemMessage(joinMessage);
+
+ addRecentLogs();
+
clearPresenceQueue();
shouldJoinOnReconnect_ = true;
setEnabled(true);
@@ -788,4 +791,15 @@ void MUCController::logMessage(const std::string& message, const JID& fromJID, c
}
}
+void MUCController::addRecentLogs() {
+ std::vector<HistoryMessage> messages = historyController_->getMUCContext(selfJID_, toJID_, lastActivity_);
+
+ foreach (const HistoryMessage& message, messages) {
+ bool senderIsSelf = nick_ == message.getFromJID().getResource();
+
+ // the chatWindow uses utc timestamps
+ addMessage(message.getMessage(), senderDisplayNameFromMessage(message.getFromJID()), senderIsSelf, boost::shared_ptr<SecurityLabel>(new SecurityLabel()), std::string(avatarManager_->getAvatarPath(message.getFromJID()).string()), message.getTime() - boost::posix_time::hours(message.getOffset()));
+ }
+}
+
}
diff --git a/Swift/Controllers/Chat/MUCController.h b/Swift/Controllers/Chat/MUCController.h
index 0c6cfa4..0ade758 100644
--- a/Swift/Controllers/Chat/MUCController.h
+++ b/Swift/Controllers/Chat/MUCController.h
@@ -106,6 +106,7 @@ namespace Swift {
void handleChangeAffiliationsRequest(const std::vector<std::pair<MUCOccupant::Affiliation, JID> >& changes);
void handleInviteToMUCWindowDismissed();
void handleInviteToMUCWindowCompleted();
+ void addRecentLogs();
private:
MUC::ref muc_;
diff --git a/Swift/Controllers/HistoryController.cpp b/Swift/Controllers/HistoryController.cpp
index 7461a1e..6ab1235 100644
--- a/Swift/Controllers/HistoryController.cpp
+++ b/Swift/Controllers/HistoryController.cpp
@@ -35,6 +35,11 @@ std::vector<HistoryMessage> HistoryController::getMessagesFromDate(const JID& se
return localHistory_->getMessagesFromDate(selfJID, contactJID, type, date);
}
+std::vector<HistoryMessage> HistoryController::getMUCContext(const JID& selfJID, const JID& mucJID, const boost::posix_time::ptime& timeStamp) const {
+ boost::posix_time::ptime localTime = boost::date_time::c_local_adjustor<boost::posix_time::ptime>::utc_to_local(timeStamp);
+ return getMessagesFromDate(selfJID, mucJID, HistoryMessage::Groupchat, localTime.date());
+}
+
std::vector<HistoryMessage> HistoryController::getMessagesFromPreviousDate(const JID& selfJID, const JID& contactJID, HistoryMessage::Type type, const boost::gregorian::date& date) const {
return localHistory_->getMessagesFromPreviousDate(selfJID, contactJID, type, date);
}
@@ -47,4 +52,8 @@ ContactsMap HistoryController::getContacts(const JID& selfJID, HistoryMessage::T
return localHistory_->getContacts(selfJID, type, keyword);
}
+boost::posix_time::ptime HistoryController::getLastTimeStampFromMUC(const JID& selfJID, const JID& mucJID) {
+ return localHistory_->getLastTimeStampFromMUC(selfJID, mucJID);
+}
+
}
diff --git a/Swift/Controllers/HistoryController.h b/Swift/Controllers/HistoryController.h
index 00ad752..f231724 100644
--- a/Swift/Controllers/HistoryController.h
+++ b/Swift/Controllers/HistoryController.h
@@ -27,6 +27,9 @@ namespace Swift {
std::vector<HistoryMessage> getMessagesFromPreviousDate(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;
ContactsMap getContacts(const JID& selfJID, HistoryMessage::Type type, const std::string& keyword = std::string()) const;
+ std::vector<HistoryMessage> getMUCContext(const JID& selfJID, const JID& mucJID, const boost::posix_time::ptime& timeStamp) const;
+
+ boost::posix_time::ptime getLastTimeStampFromMUC(const JID& selfJID, const JID& mucJID);
boost::signal<void (const HistoryMessage&)> onNewMessage;