summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Swift/Controllers/Chat/MUCController.cpp30
-rw-r--r--Swift/Controllers/Chat/MUCController.h2
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_;
};
}