summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTobias Markmann <tm@ayena.de>2016-09-19 09:35:57 (GMT)
committerTobias Markmann <tm@ayena.de>2017-04-20 10:16:56 (GMT)
commitc6daa0af52934c46ae3c26f9e9149d18e44c203e (patch)
tree28f11a1cc288932afe15ab0b9a4825af4506bdcf /Swift/Controllers/Chat/MUCController.cpp
parent57a611f942f2387e497334888a4bc4f68b9275c9 (diff)
downloadswift-c6daa0af52934c46ae3c26f9e9149d18e44c203e.zip
swift-c6daa0af52934c46ae3c26f9e9149d18e44c203e.tar.bz2
Verify message IDs during last message correction
Previously we did not check the ID in the replace tag against the ID of the last message from that JID because some MUC components change the message ID. In case the ID of the last message and the ID in the replace tag do not match, the message is simply treated as a normal message. Test-Information: Added unit tests to verify the new behavior and adjusted existing test cases for new behavior. Added test cases to ChatsManagerTest.cpp that test verification of replacement IDs for 1-to-1 chats and test non-verification of replacement IDs for MUC. All tests pass on OS X 10.11.6. Change-Id: I85b1d2138b056b445a663f3ee3ab89a56cef4a2a
Diffstat (limited to 'Swift/Controllers/Chat/MUCController.cpp')
-rw-r--r--Swift/Controllers/Chat/MUCController.cpp14
1 files changed, 12 insertions, 2 deletions
diff --git a/Swift/Controllers/Chat/MUCController.cpp b/Swift/Controllers/Chat/MUCController.cpp
index b685e04..fd3dc37 100644
--- a/Swift/Controllers/Chat/MUCController.cpp
+++ b/Swift/Controllers/Chat/MUCController.cpp
@@ -587,12 +587,22 @@ void MUCController::preHandleIncomingMessage(std::shared_ptr<MessageEvent> messa
}
}
-void MUCController::addMessageHandleIncomingMessage(const JID& from, const ChatWindow::ChatMessage& message, bool senderIsSelf, std::shared_ptr<SecurityLabel> label, const boost::posix_time::ptime& time) {
+void MUCController::addMessageHandleIncomingMessage(const JID& from, const ChatWindow::ChatMessage& message, const std::string& messageID, bool senderIsSelf, std::shared_ptr<SecurityLabel> label, const boost::posix_time::ptime& time) {
if (from.isBare()) {
chatWindow_->addSystemMessage(message, ChatWindow::DefaultDirection);
}
else {
- ChatControllerBase::addMessageHandleIncomingMessage(from, message, senderIsSelf, label, time);
+ lastMessagesIDs_[from] = {messageID, addMessage(message, senderDisplayNameFromMessage(from), senderIsSelf, label, avatarManager_->getAvatarPath(from), time)};
+ }
+}
+
+void MUCController::handleIncomingReplaceMessage(const JID& from, const ChatWindow::ChatMessage& message, const std::string& messageID, const std::string& /*idToReplace*/, bool senderIsSelf, std::shared_ptr<SecurityLabel> label, const boost::posix_time::ptime& timeStamp) {
+ auto lastMessage = lastMessagesIDs_.find(from);
+ if (lastMessage != lastMessagesIDs_.end()) {
+ replaceMessage(message, lastMessage->second.idInWindow, timeStamp);
+ }
+ else {
+ addMessageHandleIncomingMessage(from, message, messageID, senderIsSelf, label, timeStamp);
}
}