diff options
author | Cătălin Badea <catalin.badea392@gmail.com> | 2012-08-12 11:27:05 (GMT) |
---|---|---|
committer | Cătălin Badea <catalin.badea392@gmail.com> | 2012-08-12 11:27:05 (GMT) |
commit | d9e90fa37405092bfde2fa8f1bb0ab6208f716d1 (patch) | |
tree | 7eb7a9a3cc435903c310b0dbe57151aa9abc1352 | |
parent | 6dc43419273f09b9d786d8bae97206960ff85dbf (diff) | |
download | swift-contrib-d9e90fa37405092bfde2fa8f1bb0ab6208f716d1.zip swift-contrib-d9e90fa37405092bfde2fa8f1bb0ab6208f716d1.tar.bz2 |
Fix duplicate messages when joining a muc.
-rw-r--r-- | Swift/Controllers/Chat/MUCController.cpp | 30 | ||||
-rw-r--r-- | Swift/Controllers/Chat/MUCController.h | 2 |
2 files changed, 30 insertions, 2 deletions
diff --git a/Swift/Controllers/Chat/MUCController.cpp b/Swift/Controllers/Chat/MUCController.cpp index 745c9da..b2ba871 100644 --- a/Swift/Controllers/Chat/MUCController.cpp +++ b/Swift/Controllers/Chat/MUCController.cpp @@ -435,6 +435,7 @@ void MUCController::preHandleIncomingMessage(boost::shared_ptr<MessageEvent> mes } if (!doneGettingHistory_) { + checkDuplicates(message); messageEvent->conclude(); } } @@ -796,9 +797,9 @@ void MUCController::addRecentLogs() { return; } - std::vector<HistoryMessage> messages = historyController_->getMUCContext(selfJID_, toJID_, lastActivity_); + joinContext_ = historyController_->getMUCContext(selfJID_, toJID_, lastActivity_); - foreach (const HistoryMessage& message, messages) { + foreach (const HistoryMessage& message, joinContext_) { bool senderIsSelf = nick_ == message.getFromJID().getResource(); // the chatWindow uses utc timestamps @@ -806,4 +807,29 @@ void MUCController::addRecentLogs() { } } +void MUCController::checkDuplicates(boost::shared_ptr<Message> newMessage) { + std::string body = newMessage->getBody(); + JID jid = newMessage->getFrom(); + boost::optional<boost::posix_time::ptime> time = newMessage->getTimestamp(); + + reverse_foreach (const HistoryMessage& message, joinContext_) { + boost::posix_time::ptime messageTime = message.getTime() - boost::posix_time::hours(message.getOffset()); + if (time && time < messageTime) { + break; + } + if (time && time != messageTime) { + continue; + } + if (message.getFromJID() != jid) { + continue; + } + if (message.getMessage() != body) { + continue; + } + + // Mark the message as unreadable + newMessage->setBody(""); + } +} + } diff --git a/Swift/Controllers/Chat/MUCController.h b/Swift/Controllers/Chat/MUCController.h index 0ade758..63893d0 100644 --- a/Swift/Controllers/Chat/MUCController.h +++ b/Swift/Controllers/Chat/MUCController.h @@ -107,6 +107,7 @@ namespace Swift { void handleInviteToMUCWindowDismissed(); void handleInviteToMUCWindowCompleted(); void addRecentLogs(); + void checkDuplicates(boost::shared_ptr<Message> newMessage); private: MUC::ref muc_; @@ -128,6 +129,7 @@ namespace Swift { boost::optional<std::string> password_; InviteToChatWindow* inviteWindow_; XMPPRoster* xmppRoster_; + std::vector<HistoryMessage> joinContext_; }; } |