summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Swift/ChangeLog.md1
-rw-r--r--Swift/Controllers/Chat/ChatController.cpp4
-rw-r--r--Swift/Controllers/Chat/ChatController.h1
-rw-r--r--Swift/Controllers/Chat/ChatControllerBase.cpp6
-rw-r--r--Swift/Controllers/Chat/ChatControllerBase.h5
-rw-r--r--Swift/Controllers/Chat/MUCController.cpp4
-rw-r--r--Swift/Controllers/Chat/MUCController.h1
-rw-r--r--Swift/Controllers/Chat/UnitTest/ChatsManagerTest.cpp84
-rw-r--r--Swift/Controllers/UnitTest/MockChatWindow.h11
-rw-r--r--Swiften/Base/LogSerializers.h26
10 files changed, 122 insertions, 21 deletions
diff --git a/Swift/ChangeLog.md b/Swift/ChangeLog.md
index a174436..68d1554 100644
--- a/Swift/ChangeLog.md
+++ b/Swift/ChangeLog.md
@@ -5,2 +5,3 @@
- Handle sessions being closed by the server
+- Fix Last Message Correction in multi client scenarios
- Fix display of default avatar on Windows
diff --git a/Swift/Controllers/Chat/ChatController.cpp b/Swift/Controllers/Chat/ChatController.cpp
index 3bc9d20..3e58e40 100644
--- a/Swift/Controllers/Chat/ChatController.cpp
+++ b/Swift/Controllers/Chat/ChatController.cpp
@@ -567,2 +567,6 @@ bool ChatController::shouldIgnoreMessage(std::shared_ptr<Message> message) {
}
+
+JID ChatController::messageCorrectionJID(const JID& fromJID) {
+ return fromJID.toBare();
+}
diff --git a/Swift/Controllers/Chat/ChatController.h b/Swift/Controllers/Chat/ChatController.h
index ffc6be9..1deb0bb 100644
--- a/Swift/Controllers/Chat/ChatController.h
+++ b/Swift/Controllers/Chat/ChatController.h
@@ -50,2 +50,3 @@ namespace Swift {
virtual bool shouldIgnoreMessage(std::shared_ptr<Message> message) SWIFTEN_OVERRIDE;
+ virtual JID messageCorrectionJID(const JID& fromJID) SWIFTEN_OVERRIDE;
diff --git a/Swift/Controllers/Chat/ChatControllerBase.cpp b/Swift/Controllers/Chat/ChatControllerBase.cpp
index ecaf186..7ae7dbd 100644
--- a/Swift/Controllers/Chat/ChatControllerBase.cpp
+++ b/Swift/Controllers/Chat/ChatControllerBase.cpp
@@ -281,6 +281,6 @@ void ChatControllerBase::handleIncomingMessage(std::shared_ptr<MessageEvent> mes
std::map<JID, std::string>::iterator lastMessage;
- lastMessage = lastMessagesUIID_.find(from);
+ lastMessage = lastMessagesUIID_.find(messageCorrectionJID(from));
if (lastMessage != lastMessagesUIID_.end()) {
chatMessage = buildChatWindowChatMessage(body, senderHighlightNameFromMessage(from), senderIsSelf);
- replaceMessage(chatMessage, lastMessagesUIID_[from], timeStamp);
+ replaceMessage(chatMessage, lastMessagesUIID_[messageCorrectionJID(from)], timeStamp);
}
@@ -300,3 +300,3 @@ void ChatControllerBase::handleIncomingMessage(std::shared_ptr<MessageEvent> mes
void ChatControllerBase::addMessageHandleIncomingMessage(const JID& from, const ChatWindow::ChatMessage& message, bool senderIsSelf, std::shared_ptr<SecurityLabel> label, const boost::posix_time::ptime& timeStamp) {
- lastMessagesUIID_[from] = addMessage(message, senderDisplayNameFromMessage(from), senderIsSelf, label, avatarManager_->getAvatarPath(from), timeStamp);
+ lastMessagesUIID_[messageCorrectionJID(from)] = addMessage(message, senderDisplayNameFromMessage(from), senderIsSelf, label, avatarManager_->getAvatarPath(from), timeStamp);
}
diff --git a/Swift/Controllers/Chat/ChatControllerBase.h b/Swift/Controllers/Chat/ChatControllerBase.h
index c84c4d4..d10df8f 100644
--- a/Swift/Controllers/Chat/ChatControllerBase.h
+++ b/Swift/Controllers/Chat/ChatControllerBase.h
@@ -103,2 +103,7 @@ namespace Swift {
+ /**
+ * What JID should be used for last message correction (XEP-0308) tracking.
+ */
+ virtual JID messageCorrectionJID(const JID& fromJID) = 0;
+
private:
diff --git a/Swift/Controllers/Chat/MUCController.cpp b/Swift/Controllers/Chat/MUCController.cpp
index 73cf748..b685e04 100644
--- a/Swift/Controllers/Chat/MUCController.cpp
+++ b/Swift/Controllers/Chat/MUCController.cpp
@@ -1080,2 +1080,6 @@ void MUCController::logMessage(const std::string& message, const JID& fromJID, c
+JID MUCController::messageCorrectionJID(const JID& fromJID) {
+ return fromJID;
+}
+
void MUCController::addRecentLogs() {
diff --git a/Swift/Controllers/Chat/MUCController.h b/Swift/Controllers/Chat/MUCController.h
index 9d6428b..ba68ec6 100644
--- a/Swift/Controllers/Chat/MUCController.h
+++ b/Swift/Controllers/Chat/MUCController.h
@@ -87,2 +87,3 @@ namespace Swift {
virtual void logMessage(const std::string& message, const JID& fromJID, const JID& toJID, const boost::posix_time::ptime& timeStamp, bool isIncoming) SWIFTEN_OVERRIDE;
+ virtual JID messageCorrectionJID(const JID& fromJID) SWIFTEN_OVERRIDE;
diff --git a/Swift/Controllers/Chat/UnitTest/ChatsManagerTest.cpp b/Swift/Controllers/Chat/UnitTest/ChatsManagerTest.cpp
index d104fbd..0356c6a 100644
--- a/Swift/Controllers/Chat/UnitTest/ChatsManagerTest.cpp
+++ b/Swift/Controllers/Chat/UnitTest/ChatsManagerTest.cpp
@@ -139,2 +139,7 @@ class ChatsManagerTest : public CppUnit::TestFixture {
+
+ // Message correction tests
+ CPPUNIT_TEST(testChatControllerMessageCorrectionReplaceBySameResource);
+ CPPUNIT_TEST(testChatControllerMessageCorrectionReplaceByOtherResource);
+
CPPUNIT_TEST_SUITE_END();
@@ -219,3 +224,2 @@ public:
delete settings_;
-
}
@@ -734,3 +738,3 @@ public:
stanzaChannel_->onPresenceReceived(presence);
- CPPUNIT_ASSERT_EQUAL(std::string("participantA has gone offline."), MockChatWindow::bodyFromMessage(window->lastReplacedMessage_));
+ CPPUNIT_ASSERT_EQUAL(std::string("participantA has gone offline."), MockChatWindow::bodyFromMessage(window->lastReplacedLastMessage_));
}
@@ -1099,3 +1103,3 @@ public:
stanzaChannel_->onPresenceReceived(generateIncomingPresence(Presence::Unavailable));
- CPPUNIT_ASSERT_EQUAL(std::string(""), MockChatWindow::bodyFromMessage(window->lastReplacedMessage_));
+ CPPUNIT_ASSERT_EQUAL(std::string(""), MockChatWindow::bodyFromMessage(window->lastReplacedLastMessage_));
CPPUNIT_ASSERT_EQUAL(std::string("testling@test.com has gone offline."), MockChatWindow::bodyFromMessage(window->lastAddedPresence_));
@@ -1136,3 +1140,3 @@ public:
CPPUNIT_ASSERT_EQUAL(std::string("someDifferentNickname has entered the room."), window->bodyFromMessage(window->lastAddedPresence_));
- CPPUNIT_ASSERT_EQUAL(std::string(), window->bodyFromMessage(window->lastReplacedMessage_));
+ CPPUNIT_ASSERT_EQUAL(std::string(), window->bodyFromMessage(window->lastReplacedLastMessage_));
window->resetLastMessages();
@@ -1147,3 +1151,3 @@ public:
CPPUNIT_ASSERT_EQUAL(std::string(), window->bodyFromMessage(window->lastAddedPresence_));
- CPPUNIT_ASSERT_EQUAL(std::string("someDifferentNickname and Romeo have entered the room"), window->bodyFromMessage(window->lastReplacedMessage_));
+ CPPUNIT_ASSERT_EQUAL(std::string("someDifferentNickname and Romeo have entered the room"), window->bodyFromMessage(window->lastReplacedLastMessage_));
window->resetLastMessages();
@@ -1167,3 +1171,3 @@ public:
CPPUNIT_ASSERT_EQUAL(std::string(), window->bodyFromMessage(window->lastAddedPresence_));
- CPPUNIT_ASSERT_EQUAL(std::string("someDifferentNickname, Romeo and Juliet have entered the room"), window->bodyFromMessage(window->lastReplacedMessage_));
+ CPPUNIT_ASSERT_EQUAL(std::string("someDifferentNickname, Romeo and Juliet have entered the room"), window->bodyFromMessage(window->lastReplacedLastMessage_));
}
@@ -1267,3 +1271,3 @@ public:
}
-
+
void testCarbonsForwardedIncomingDuplicates() {
@@ -1271,6 +1275,6 @@ public:
JID jid2 = jid_.toBare().withResource("someOtherResource");
-
+
MockChatWindow* window = new MockChatWindow();
mocks_->ExpectCall(chatWindowFactory_, ChatWindowFactory::createChatWindow).With(messageJID, uiEventStream_).Return(window);
-
+
std::shared_ptr<Message> message(new Message());
@@ -1281,3 +1285,3 @@ public:
CPPUNIT_ASSERT_EQUAL(body, MockChatWindow::bodyFromMessage(window->lastAddedMessage_));
-
+
// incoming carbons message from another resource and duplicate of it
@@ -1291,7 +1295,7 @@ public:
originalMessage->setBody(forwardedBody);
-
+
auto messageWrapper = createCarbonsMessage(std::make_shared<CarbonsReceived>(), originalMessage);
-
+
manager_->handleIncomingMessage(messageWrapper);
-
+
CPPUNIT_ASSERT_EQUAL(forwardedBody, MockChatWindow::bodyFromMessage(window->lastAddedMessage_));
@@ -1299,3 +1303,3 @@ public:
window->resetLastMessages();
-
+
messageWrapper = createCarbonsMessage(std::make_shared<CarbonsReceived>(), originalMessage);
@@ -1307,2 +1311,54 @@ public:
+ void testChatControllerMessageCorrectionReplaceBySameResource() {
+ JID messageJID("testling@test.com/resource1");
+
+ MockChatWindow* window = new MockChatWindow();
+ mocks_->ExpectCall(chatWindowFactory_, ChatWindowFactory::createChatWindow).With(messageJID, uiEventStream_).Return(window);
+
+ auto message = std::make_shared<Message>();
+ message->setFrom(messageJID);
+ message->setTo(jid_);
+ message->setType(Message::Chat);
+ message->setBody("text before edit");
+ manager_->handleIncomingMessage(message);
+
+ CPPUNIT_ASSERT_EQUAL(std::string("text before edit"), MockChatWindow::bodyFromMessage(window->lastAddedMessage_));
+
+ message = std::make_shared<Message>();
+ message->setFrom(messageJID);
+ message->setTo(jid_);
+ message->setType(Message::Chat);
+ message->setBody("text after edit");
+ message->addPayload(std::make_shared<Replace>("someID"));
+ manager_->handleIncomingMessage(message);
+
+ CPPUNIT_ASSERT_EQUAL(std::string("text after edit"), MockChatWindow::bodyFromMessage(window->lastReplacedMessage_));
+ }
+
+ void testChatControllerMessageCorrectionReplaceByOtherResource() {
+ JID messageJID("testling@test.com/resource1");
+
+ MockChatWindow* window = new MockChatWindow();
+ mocks_->ExpectCall(chatWindowFactory_, ChatWindowFactory::createChatWindow).With(messageJID, uiEventStream_).Return(window);
+
+ auto message = std::make_shared<Message>();
+ message->setFrom(messageJID);
+ message->setTo(jid_);
+ message->setType(Message::Chat);
+ message->setBody("text before edit");
+ manager_->handleIncomingMessage(message);
+
+ CPPUNIT_ASSERT_EQUAL(std::string("text before edit"), MockChatWindow::bodyFromMessage(window->lastAddedMessage_));
+
+ message = std::make_shared<Message>();
+ message->setFrom(messageJID.toBare().withResource("resource2"));
+ message->setTo(jid_);
+ message->setType(Message::Chat);
+ message->setBody("text after edit");
+ message->addPayload(std::make_shared<Replace>("someID"));
+ manager_->handleIncomingMessage(message);
+
+ CPPUNIT_ASSERT_EQUAL(std::string("text after edit"), MockChatWindow::bodyFromMessage(window->lastReplacedMessage_));
+ }
+
private:
diff --git a/Swift/Controllers/UnitTest/MockChatWindow.h b/Swift/Controllers/UnitTest/MockChatWindow.h
index 84c86fc..7682781 100644
--- a/Swift/Controllers/UnitTest/MockChatWindow.h
+++ b/Swift/Controllers/UnitTest/MockChatWindow.h
@@ -45,6 +45,10 @@ namespace Swift {
}
- virtual void replaceMessage(const ChatMessage& /*message*/, const std::string& /*id*/, const boost::posix_time::ptime& /*time*/) {}
+
+ virtual void replaceMessage(const ChatMessage& message, const std::string& /*id*/, const boost::posix_time::ptime& /*time*/) {
+ lastReplacedMessage_ = message;
+ }
+
virtual void replaceWithAction(const ChatMessage& /*message*/, const std::string& /*id*/, const boost::posix_time::ptime& /*time*/) {}
virtual void replaceLastMessage(const ChatMessage& message, const TimestampBehaviour /*timestampBehaviour*/) {
- lastReplacedMessage_ = message;
+ lastReplacedLastMessage_ = message;
}
@@ -126,3 +130,3 @@ namespace Swift {
void resetLastMessages() {
- lastAddedMessage_ = lastAddedAction_ = lastAddedPresence_ = lastReplacedMessage_ = lastAddedSystemMessage_ = lastReplacedSystemMessage_ = ChatMessage();
+ lastAddedMessage_ = lastAddedAction_ = lastAddedPresence_ = lastReplacedLastMessage_ = lastAddedSystemMessage_ = lastReplacedSystemMessage_ = ChatMessage();
lastAddedMessageSenderName_ = lastAddedActionSenderName_ = "";
@@ -140,2 +144,3 @@ namespace Swift {
ChatMessage lastReplacedMessage_;
+ ChatMessage lastReplacedLastMessage_;
ChatMessage lastAddedSystemMessage_;
diff --git a/Swiften/Base/LogSerializers.h b/Swiften/Base/LogSerializers.h
index b804808..7f73686 100644
--- a/Swiften/Base/LogSerializers.h
+++ b/Swiften/Base/LogSerializers.h
@@ -8,2 +8,3 @@
+#include <map>
#include <memory>
@@ -11,2 +12,3 @@
#include <string>
+#include <utility>
#include <vector>
@@ -42,3 +44,3 @@ std::ostream& operator<<(std::ostream& stream, const std::vector<T>& vec) {
}
- }
+ }
stream << "]";
@@ -47,2 +49,24 @@ std::ostream& operator<<(std::ostream& stream, const std::vector<T>& vec) {
+template <typename KEY, typename VALUE>
+std::ostream& operator<<(std::ostream& stream, const std::pair<KEY, VALUE>& pair) {
+ stream << pair.first << ":" << pair.second;
+ return stream;
+}
+
+template <typename KEY, typename VALUE>
+std::ostream& operator<<(std::ostream& stream, const std::map<KEY, VALUE>& map) {
+ stream << "{";
+ if (!map.empty()) {
+ auto it = std::begin(map);
+ stream << *it;
+
+ ++it;
+ for (auto end = std::end(map); it != end; ++it) {
+ stream << ", " << *it;
+ }
+ }
+ stream << "}";
+ return stream;
+}
+
std::ostream& operator<<(std::ostream& stream, const Presence& presence);