summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Swift/Controllers/Chat/ChatsManager.cpp4
-rw-r--r--Swift/Controllers/Chat/MUCController.cpp30
-rw-r--r--Swift/Controllers/Chat/MUCController.h3
-rw-r--r--Swift/Controllers/Chat/UnitTest/ChatsManagerTest.cpp17
-rw-r--r--Swift/Controllers/Chat/UnitTest/MUCControllerTest.cpp7
5 files changed, 33 insertions, 28 deletions
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<Roster>(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<std::string, MUCOccupant> 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<std::string, JID> getParticipantJIDs() const;
void sendInvites(const std::vector<JID>& jids, const std::string& reason) const;
+ void setChatWindowTitle(const std::string& title);
protected:
virtual void preSendMessageRequest(std::shared_ptr<Message> message) SWIFTEN_OVERRIDE;
@@ -134,7 +135,6 @@ namespace Swift {
void addRecentLogs();
void checkDuplicates(std::shared_ptr<Message> 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<IQ> infoRequest = std::dynamic_pointer_cast<IQ>(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<Message> 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_;