From 1cb2bb760d6487764a9480c84cf2d2edc65ff564 Mon Sep 17 00:00:00 2001 From: Joanna Hulboj Date: Thu, 4 May 2017 15:50:51 +0100 Subject: Fix chat window title being displayed incorrectly Test-Information: Open Swift app, from Recent Chat List click on entry that was created from offline invitees. New chat window will be opened and the title will be the same as Recent Chat List entry. Change-Id: Ia8730aaabfd78e7026d15f3162d4fa46b1489397 diff --git a/Swift/Controllers/Chat/ChatsManager.cpp b/Swift/Controllers/Chat/ChatsManager.cpp index 9db343f..d9f80ba 100644 --- a/Swift/Controllers/Chat/ChatsManager.cpp +++ b/Swift/Controllers/Chat/ChatsManager.cpp @@ -875,6 +875,10 @@ MUC::ref ChatsManager::handleJoinMUCRequest(const JID &mucJID, const boost::opti } handleChatActivity(mucJID.toBare(), "", true); } + auto chatListWindowIter = std::find_if(recentChats_.begin(), recentChats_.end(), [&](const ChatListWindow::Chat& chatListWindow) { return mucJID == (chatListWindow.jid); }); + if (chatListWindowIter != recentChats_.end()) { + mucControllers_[mucJID]->setChatWindowTitle(chatListWindowIter->getTitle()); + } mucControllers_[mucJID]->showChatWindow(); return muc; diff --git a/Swift/Controllers/Chat/MUCController.cpp b/Swift/Controllers/Chat/MUCController.cpp index fd3dc37..d10e6d4 100644 --- a/Swift/Controllers/Chat/MUCController.cpp +++ b/Swift/Controllers/Chat/MUCController.cpp @@ -110,6 +110,7 @@ MUCController::MUCController ( xmppRoster_ = xmppRoster; subject_ = ""; isInitialJoin_ = true; + chatWindowTitle_ = ""; roster_ = std::unique_ptr(new Roster(false, true)); rosterVCardProvider_ = new RosterVCardProvider(roster_.get(), vcardManager, JID::WithResource); @@ -406,10 +407,6 @@ void MUCController::handleJoinComplete(const std::string& nick) { setAvailableRoomActions(occupant.getAffiliation(), occupant.getRole()); } onUserJoined(); - - if (isImpromptu_) { - setImpromptuWindowTitle(); - } } void MUCController::handleAvatarChanged(const JID& jid) { @@ -464,7 +461,6 @@ void MUCController::handleOccupantJoined(const MUCOccupant& occupant) { } if (isImpromptu_) { - setImpromptuWindowTitle(); onActivity(""); } } @@ -769,10 +765,6 @@ void MUCController::handleOccupantLeft(const MUCOccupant& occupant, MUC::Leaving if (clearAfter) { clearPresenceQueue(); } - - if (isImpromptu_) { - setImpromptuWindowTitle(); - } } void MUCController::handleOccupantNicknameChanged(const std::string& oldNickname, const std::string& newNickname) { @@ -1178,21 +1170,6 @@ Form::ref MUCController::buildImpromptuRoomConfiguration(Form::ref roomConfigura return result; } -void MUCController::setImpromptuWindowTitle() { - std::string title; - std::map occupants = muc_->getOccupants(); - if (occupants.size() <= 1) { - title = QT_TRANSLATE_NOOP("", "Empty Chat"); - } else { - for (const auto& pair : occupants) { - if (pair.first != nick_) { - title += (title.empty() ? "" : ", ") + pair.first; - } - } - } - chatWindow_->setName(title); -} - void MUCController::handleRoomUnlocked() { // Handle buggy MUC implementations where the joined room already exists and is unlocked. // Configure the room again in this case. @@ -1261,4 +1238,9 @@ void MUCController::addChatSystemMessage() { lastJoinMessageUID_ = chatWindow_->addSystemMessage(chatMessageParser_->parseMessageBody(lastStartMessage_), ChatWindow::DefaultDirection); } +void MUCController::setChatWindowTitle(const std::string& title) { + chatWindowTitle_ = title; + chatWindow_->setName(chatWindowTitle_); +} + } diff --git a/Swift/Controllers/Chat/MUCController.h b/Swift/Controllers/Chat/MUCController.h index b8f2aac..258eaaf 100644 --- a/Swift/Controllers/Chat/MUCController.h +++ b/Swift/Controllers/Chat/MUCController.h @@ -73,6 +73,7 @@ namespace Swift { bool isImpromptu() const; std::map getParticipantJIDs() const; void sendInvites(const std::vector& jids, const std::string& reason) const; + void setChatWindowTitle(const std::string& title); protected: virtual void preSendMessageRequest(std::shared_ptr message) SWIFTEN_OVERRIDE; @@ -134,7 +135,6 @@ namespace Swift { void addRecentLogs(); void checkDuplicates(std::shared_ptr newMessage); void setNick(const std::string& nick); - void setImpromptuWindowTitle(); void handleRoomUnlocked(); void configureAsImpromptuRoom(Form::ref form); Form::ref buildImpromptuRoomConfiguration(Form::ref roomConfigurationForm); @@ -187,6 +187,7 @@ namespace Swift { std::string subject_; bool isInitialJoin_; + std::string chatWindowTitle_; }; } diff --git a/Swift/Controllers/Chat/UnitTest/ChatsManagerTest.cpp b/Swift/Controllers/Chat/UnitTest/ChatsManagerTest.cpp index 52537a9..20c959c 100644 --- a/Swift/Controllers/Chat/UnitTest/ChatsManagerTest.cpp +++ b/Swift/Controllers/Chat/UnitTest/ChatsManagerTest.cpp @@ -152,6 +152,7 @@ class ChatsManagerTest : public CppUnit::TestFixture { //Imptomptu test CPPUNIT_TEST(testImpromptuChatTitle); + CPPUNIT_TEST(testImpromptuChatWindowTitle); CPPUNIT_TEST_SUITE_END(); @@ -1511,13 +1512,11 @@ public: CPPUNIT_ASSERT_EQUAL(std::string("Some correctly spelled message."), window->bodyFromMessage(window->lastReplacedMessage_)); } - void testImpromptuChatTitle() { + void impromptuChatSetup(MockChatWindow* window) { 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 infoRequest = std::dynamic_pointer_cast(stanzaChannel_->sentStanzas[1]); CPPUNIT_ASSERT(infoRequest); @@ -1569,11 +1568,23 @@ public: for (const auto& participantJID : jids) { stanzaChannel_->onPresenceReceived(mucParticipantJoined(participantJID)); } + } + void testImpromptuChatTitle() { + // Open a new chat window to a sender. + MockChatWindow* window = new MockChatWindow(); + impromptuChatSetup(window); // 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()); } + void testImpromptuChatWindowTitle() { + // Open a new chat window to a sender. + MockChatWindow* window = new MockChatWindow(); + impromptuChatSetup(window); + // After people joined, the title of chat window is combined of participant nicknames or names coming from Roster (if nicknames are unavailable) + CPPUNIT_ASSERT_EQUAL(std::string("bar@test.com, foo@test.com"), window->name_); + } private: std::shared_ptr makeDeliveryReceiptTestMessage(const JID& from, const std::string& id) { diff --git a/Swift/Controllers/Chat/UnitTest/MUCControllerTest.cpp b/Swift/Controllers/Chat/UnitTest/MUCControllerTest.cpp index e7b4b3e..1f69f4f 100644 --- a/Swift/Controllers/Chat/UnitTest/MUCControllerTest.cpp +++ b/Swift/Controllers/Chat/UnitTest/MUCControllerTest.cpp @@ -65,6 +65,9 @@ class MUCControllerTest : public CppUnit::TestFixture { CPPUNIT_TEST(testHandleOccupantNicknameChanged); CPPUNIT_TEST(testHandleOccupantNicknameChangedRoster); CPPUNIT_TEST(testHandleChangeSubjectRequest); + + CPPUNIT_TEST(testNonImpromptuMUCWindowTitle); + CPPUNIT_TEST_SUITE_END(); public: @@ -586,6 +589,10 @@ public: CPPUNIT_ASSERT_EQUAL(testStr, muc_->newSubjectSet_); } + void testNonImpromptuMUCWindowTitle() { + CPPUNIT_ASSERT_EQUAL(muc_->getJID().getNode(), window_->name_); + } + private: JID self_; JID mucJID_; -- cgit v0.10.2-6-g49f6