summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'Swift/Controllers/Chat')
-rw-r--r--Swift/Controllers/Chat/ChatsManager.cpp21
-rw-r--r--Swift/Controllers/Chat/ChatsManager.h3
-rw-r--r--Swift/Controllers/Chat/UnitTest/ChatsManagerTest.cpp73
3 files changed, 93 insertions, 4 deletions
diff --git a/Swift/Controllers/Chat/ChatsManager.cpp b/Swift/Controllers/Chat/ChatsManager.cpp
index db3b3b7..9db343f 100644
--- a/Swift/Controllers/Chat/ChatsManager.cpp
+++ b/Swift/Controllers/Chat/ChatsManager.cpp
@@ -69,3 +69,3 @@
-BOOST_CLASS_VERSION(Swift::ChatListWindow::Chat, 1)
+BOOST_CLASS_VERSION(Swift::ChatListWindow::Chat, 2)
@@ -98,2 +98,5 @@ namespace serialization {
}
+ if (version > 1) {
+ ar & chat.inviteesNames;
+ }
}
@@ -404,2 +407,8 @@ ChatListWindow::Chat ChatsManager::createChatListChatItem(const JID& jid, const
chat.impromptuJIDs = participants;
+
+ std::map<JID, std::string> participantsNames;
+ for (auto& i : invitees_[jid]) {
+ participantsNames.emplace(i, roster_->getNameForJID(i));
+ }
+ chat.inviteesNames = participantsNames;
return chat;
@@ -490,3 +499,4 @@ void ChatsManager::appendRecent(const ChatListWindow::Chat& chat) {
ChatListWindow::Chat mergedChat = chat;
- if (oldChat && !oldChat->impromptuJIDs.empty()) {
+ if (oldChat) {
+ mergedChat.inviteesNames.insert(oldChat->inviteesNames.begin(), oldChat->inviteesNames.end());
mergedChat.impromptuJIDs.insert(oldChat->impromptuJIDs.begin(), oldChat->impromptuJIDs.end());
@@ -499,3 +509,4 @@ void ChatsManager::prependRecent(const ChatListWindow::Chat& chat) {
ChatListWindow::Chat mergedChat = chat;
- if (oldChat && !oldChat->impromptuJIDs.empty()) {
+ if (oldChat) {
+ mergedChat.inviteesNames.insert(oldChat->inviteesNames.begin(), oldChat->inviteesNames.end());
mergedChat.impromptuJIDs.insert(oldChat->impromptuJIDs.begin(), oldChat->impromptuJIDs.end());
@@ -592,2 +603,6 @@ void ChatsManager::handleUIEvent(std::shared_ptr<UIEvent> event) {
+ std::vector<JID> missingJIDsToInvite = createImpromptuMUCEvent->getJIDs();
+ for (const JID& jid : missingJIDsToInvite) {
+ invitees_[roomJID].insert(jid);
+ }
// join muc
diff --git a/Swift/Controllers/Chat/ChatsManager.h b/Swift/Controllers/Chat/ChatsManager.h
index 593624d..6004347 100644
--- a/Swift/Controllers/Chat/ChatsManager.h
+++ b/Swift/Controllers/Chat/ChatsManager.h
@@ -11,2 +11,3 @@
#include <string>
+#include <set>
@@ -183,2 +184,4 @@ namespace Swift {
VCardManager* vcardManager_;
+
+ std::map<JID, std::set<JID>> invitees_;
};
diff --git a/Swift/Controllers/Chat/UnitTest/ChatsManagerTest.cpp b/Swift/Controllers/Chat/UnitTest/ChatsManagerTest.cpp
index bf645d0..52537a9 100644
--- a/Swift/Controllers/Chat/UnitTest/ChatsManagerTest.cpp
+++ b/Swift/Controllers/Chat/UnitTest/ChatsManagerTest.cpp
@@ -18,2 +18,4 @@
#include <Swiften/Base/Algorithm.h>
+#include <Swiften/Base/Log.h>
+#include <Swiften/Base/LogSerializers.h>
#include <Swiften/Client/Client.h>
@@ -54,2 +56,3 @@
#include <Swift/Controllers/Settings/DummySettingsProvider.h>
+#include <Swift/Controllers/UIEvents/CreateImpromptuMUCUIEvent.h>
#include <Swift/Controllers/UIEvents/JoinMUCUIEvent.h>
@@ -69,2 +72,5 @@
+#include <Swift/QtUI/QtSwiftUtil.h>
+#include <Swiften/MUC/UnitTest/MockMUC.h>
+
using namespace Swift;
@@ -139,3 +145,2 @@ class ChatsManagerTest : public CppUnit::TestFixture {
-
// Message correction tests
@@ -147,2 +152,5 @@ class ChatsManagerTest : public CppUnit::TestFixture {
+ //Imptomptu test
+ CPPUNIT_TEST(testImpromptuChatTitle);
+
CPPUNIT_TEST_SUITE_END();
@@ -1505,2 +1513,65 @@ public:
+ void testImpromptuChatTitle() {
+ stanzaChannel_->uniqueIDs_ = true;
+ JID mucJID("795B7BBE-9099-4A0D-81BA-C816F78E275C@test.com");
+ manager_->setOnline(true);
+
+ // Open chat window to a sender.
+ MockChatWindow* window = new MockChatWindow();
+ std::shared_ptr<IQ> infoRequest = std::dynamic_pointer_cast<IQ>(stanzaChannel_->sentStanzas[1]);
+ CPPUNIT_ASSERT(infoRequest);
+
+ std::shared_ptr<IQ> infoResponse = IQ::createResult(infoRequest->getFrom(), infoRequest->getTo(), infoRequest->getID());
+
+ DiscoInfo info;
+ info.addIdentity(DiscoInfo::Identity("Shakespearean Chat Service", "conference", "text"));
+ info.addFeature("http://jabber.org/protocol/muc");
+ infoResponse->addPayload(std::make_shared<DiscoInfo>(info));
+ stanzaChannel_->onIQReceived(infoResponse);
+
+ std::vector<JID> jids;
+ jids.emplace_back("foo@test.com");
+ jids.emplace_back("bar@test.com");
+
+ mocks_->ExpectCall(chatWindowFactory_, ChatWindowFactory::createChatWindow).With(mucJID, uiEventStream_).Return(window);
+ uiEventStream_->send(std::make_shared<CreateImpromptuMUCUIEvent>(jids, mucJID, ""));
+ CPPUNIT_ASSERT_EQUAL(std::string("bar@test.com, foo@test.com"), manager_->getRecentChats()[0].getTitle());
+
+ auto mucJoinPresence = std::dynamic_pointer_cast<Presence>(stanzaChannel_->sentStanzas[2]);
+ CPPUNIT_ASSERT(mucJoinPresence);
+
+ // MUC presence reply
+ auto mucResponse = Presence::create();
+ mucResponse->setTo(jid_);
+ mucResponse->setFrom(mucJoinPresence->getTo());
+ mucResponse->addPayload([]() {
+ auto mucUser = std::make_shared<MUCUserPayload>();
+ mucUser->addItem(MUCItem(MUCOccupant::Member, MUCOccupant::Participant));
+ mucUser->addStatusCode(MUCUserPayload::StatusCode(110));
+ mucUser->addStatusCode(MUCUserPayload::StatusCode(210));
+ return mucUser;
+ }());
+ stanzaChannel_->onPresenceReceived(mucResponse);
+
+ // Before people join the impromptu room, the title is based on names coming from Roster
+ CPPUNIT_ASSERT_EQUAL(std::string("bar@test.com, foo@test.com"), manager_->getRecentChats()[0].getTitle());
+
+ auto mucParticipantJoined = [&](const JID& jid) {
+ auto participantJoinedPresence = Presence::create();
+ participantJoinedPresence->setTo(jid_);
+ participantJoinedPresence->setFrom(mucJID.withResource(jid.toString()));
+ auto mucUser = std::make_shared<MUCUserPayload>();
+ mucUser->addItem(MUCItem(MUCOccupant::Member, MUCOccupant::Participant));
+ participantJoinedPresence->addPayload(mucUser);
+ return participantJoinedPresence;
+ };
+
+ for (const auto& participantJID : jids) {
+ stanzaChannel_->onPresenceReceived(mucParticipantJoined(participantJID));
+ }
+
+ // After people joined, the title is the list of participant nicknames or names coming from Roster (if nicknames are unavailable)
+ CPPUNIT_ASSERT_EQUAL(std::string("bar@test.com, foo@test.com"), manager_->getRecentChats()[0].getTitle());
+ }
+