summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJoanna Hulboj <joanna.hulboj@isode.com>2017-05-04 14:50:51 (GMT)
committerKevin Smith <kevin.smith@isode.com>2017-05-10 08:56:38 (GMT)
commit1cb2bb760d6487764a9480c84cf2d2edc65ff564 (patch)
treeaa5d01bb3c0fc74d28c96343571ff934447f059a /Swift/Controllers/Chat/MUCController.cpp
parent473a73c7112e9fbcd441fa1bf5ff7b1f96ee28bd (diff)
downloadswift-1cb2bb760d6487764a9480c84cf2d2edc65ff564.zip
swift-1cb2bb760d6487764a9480c84cf2d2edc65ff564.tar.bz2
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
Diffstat (limited to 'Swift/Controllers/Chat/MUCController.cpp')
-rw-r--r--Swift/Controllers/Chat/MUCController.cpp30
1 files changed, 6 insertions, 24 deletions
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
@@ -83,60 +83,61 @@ MUCController::MUCController (
ChatWindowFactory* chatWindowFactory,
NickResolver* nickResolver,
PresenceOracle* presenceOracle,
AvatarManager* avatarManager,
UIEventStream* uiEventStream,
bool useDelayForLatency,
TimerFactory* timerFactory,
EventController* eventController,
EntityCapsProvider* entityCapsProvider,
XMPPRoster* xmppRoster,
HistoryController* historyController,
MUCRegistry* mucRegistry,
HighlightManager* highlightManager,
ClientBlockListManager* clientBlockListManager,
std::shared_ptr<ChatMessageParser> chatMessageParser,
bool isImpromptu,
AutoAcceptMUCInviteDecider* autoAcceptMUCInviteDecider,
VCardManager* vcardManager,
MUCBookmarkManager* mucBookmarkManager) :
ChatControllerBase(self, stanzaChannel, iqRouter, chatWindowFactory, muc->getJID(), nickResolver, presenceOracle, avatarManager, useDelayForLatency, uiEventStream, eventController, entityCapsProvider, historyController, mucRegistry, highlightManager, chatMessageParser, autoAcceptMUCInviteDecider), muc_(muc), nick_(nick), desiredNick_(nick), password_(password), renameCounter_(0), isImpromptu_(isImpromptu), isImpromptuAlreadyConfigured_(false), clientBlockListManager_(clientBlockListManager), mucBookmarkManager_(mucBookmarkManager) {
assert(avatarManager_);
parting_ = true;
joined_ = false;
lastWasPresence_ = false;
shouldJoinOnReconnect_ = true;
doneGettingHistory_ = false;
xmppRoster_ = xmppRoster;
subject_ = "";
isInitialJoin_ = true;
+ chatWindowTitle_ = "";
roster_ = std::unique_ptr<Roster>(new Roster(false, true));
rosterVCardProvider_ = new RosterVCardProvider(roster_.get(), vcardManager, JID::WithResource);
completer_ = new TabComplete();
chatWindow_->setRosterModel(roster_.get());
chatWindow_->setTabComplete(completer_);
chatWindow_->onClosed.connect(boost::bind(&MUCController::handleWindowClosed, this));
chatWindow_->onOccupantSelectionChanged.connect(boost::bind(&MUCController::handleWindowOccupantSelectionChanged, this, _1));
chatWindow_->onOccupantActionSelected.connect(boost::bind(&MUCController::handleActionRequestedOnOccupant, this, _1, _2));
chatWindow_->onChangeSubjectRequest.connect(boost::bind(&MUCController::handleChangeSubjectRequest, this, _1));
chatWindow_->onBookmarkRequest.connect(boost::bind(&MUCController::handleBookmarkRequest, this));
chatWindow_->onConfigureRequest.connect(boost::bind(&MUCController::handleConfigureRequest, this, _1));
chatWindow_->onConfigurationFormCancelled.connect(boost::bind(&MUCController::handleConfigurationCancelled, this));
chatWindow_->onDestroyRequest.connect(boost::bind(&MUCController::handleDestroyRoomRequest, this));
chatWindow_->onInviteToChat.connect(boost::bind(&MUCController::handleInvitePersonToThisMUCRequest, this, _1));
chatWindow_->onGetAffiliationsRequest.connect(boost::bind(&MUCController::handleGetAffiliationsRequest, this));
chatWindow_->onChangeAffiliationsRequest.connect(boost::bind(&MUCController::handleChangeAffiliationsRequest, this, _1));
chatWindow_->onUnblockUserRequest.connect(boost::bind(&MUCController::handleUnblockUserRequest, this));
chatWindow_->onContinuationsBroken.connect(boost::bind(&MUCController::addChatSystemMessage, this));
muc_->onJoinComplete.connect(boost::bind(&MUCController::handleJoinComplete, this, _1));
muc_->onJoinFailed.connect(boost::bind(&MUCController::handleJoinFailed, this, _1));
muc_->onOccupantJoined.connect(boost::bind(&MUCController::handleOccupantJoined, this, _1));
muc_->onOccupantNicknameChanged.connect(boost::bind(&MUCController::handleOccupantNicknameChanged, this, _1, _2));
muc_->onOccupantPresenceChange.connect(boost::bind(&MUCController::handleOccupantPresenceChange, this, _1));
muc_->onOccupantLeft.connect(boost::bind(&MUCController::handleOccupantLeft, this, _1, _2, _3));
muc_->onRoleChangeFailed.connect(boost::bind(&MUCController::handleOccupantRoleChangeFailed, this, _1, _2, _3));
muc_->onAffiliationListReceived.connect(boost::bind(&MUCController::handleAffiliationListReceived, this, _1, _2));
muc_->onConfigurationFailed.connect(boost::bind(&MUCController::handleConfigurationFailed, this, _1));
muc_->onConfigurationFormReceived.connect(boost::bind(&MUCController::handleConfigurationFormReceived, this, _1));
chatMessageParser_->setNick(nick_);
@@ -379,119 +380,114 @@ void MUCController::handleJoinFailed(std::shared_ptr<ErrorPayload> error) {
#pragma clang diagnostic pop
void MUCController::handleJoinComplete(const std::string& nick) {
receivedActivity();
renameCounter_ = 0;
joined_ = true;
if (isImpromptu_) {
lastStartMessage_ = str(format(QT_TRANSLATE_NOOP("", "You have joined the chat as %1%.")) % nick);
}
else {
lastStartMessage_ = str(format(QT_TRANSLATE_NOOP("", "You have entered room %1% as %2%.")) % toJID_.toString() % nick);
}
setNick(nick);
chatWindow_->replaceSystemMessage(chatMessageParser_->parseMessageBody(lastStartMessage_, "", true), lastJoinMessageUID_, ChatWindow::UpdateTimestamp);
lastJoinMessageUID_ = "";
#ifdef SWIFT_EXPERIMENTAL_HISTORY
addRecentLogs();
#endif
clearPresenceQueue();
shouldJoinOnReconnect_ = true;
setEnabled(true);
if (isImpromptu_) {
setAvailableRoomActions(MUCOccupant::NoAffiliation, MUCOccupant::Participant);
} else {
MUCOccupant occupant = muc_->getOccupant(nick);
setAvailableRoomActions(occupant.getAffiliation(), occupant.getRole());
}
onUserJoined();
-
- if (isImpromptu_) {
- setImpromptuWindowTitle();
- }
}
void MUCController::handleAvatarChanged(const JID& jid) {
if (parting_ || !jid.equals(toJID_, JID::WithoutResource)) {
return;
}
roster_->applyOnItems(SetAvatar(jid, avatarManager_->getAvatarPath(jid), JID::WithResource));
}
void MUCController::handleWindowClosed() {
parting_ = true;
shouldJoinOnReconnect_ = false;
muc_->part();
onUserLeft();
}
void MUCController::handleOccupantJoined(const MUCOccupant& occupant) {
if (nick_ != occupant.getNick()) {
completer_->addWord(occupant.getNick());
}
receivedActivity();
JID jid(nickToJID(occupant.getNick()));
JID realJID;
if (occupant.getRealJID()) {
realJID = occupant.getRealJID().get();
}
currentOccupants_.insert(occupant.getNick());
NickJoinPart event(occupant.getNick(), Join);
appendToJoinParts(joinParts_, event);
MUCOccupant::Role role = MUCOccupant::Participant;
MUCOccupant::Affiliation affiliation = MUCOccupant::NoAffiliation;
if (!isImpromptu_) {
role = occupant.getRole();
affiliation = occupant.getAffiliation();
}
std::string groupName(roleToGroupName(role));
roster_->addContact(jid, realJID, occupant.getNick(), groupName, avatarManager_->getAvatarPath(jid));
roster_->applyOnItems(SetMUC(jid, role, affiliation));
roster_->getGroup(groupName)->setManualSort(roleToSortName(role));
if (joined_) {
std::string joinString;
if (role != MUCOccupant::NoRole && role != MUCOccupant::Participant) {
joinString = str(format(QT_TRANSLATE_NOOP("", "%1% has entered the %3% as a %2%.")) % occupant.getNick() % roleToFriendlyName(role) % (isImpromptu_ ? QT_TRANSLATE_NOOP("", "chat") : QT_TRANSLATE_NOOP("", "room")));
}
else {
joinString = str(format(QT_TRANSLATE_NOOP("", "%1% has entered the %2%.")) % occupant.getNick() % (isImpromptu_ ? QT_TRANSLATE_NOOP("", "chat") : QT_TRANSLATE_NOOP("", "room")));
}
if (shouldUpdateJoinParts()) {
updateJoinParts();
} else {
addPresenceMessage(joinString);
}
if (isImpromptu_) {
- setImpromptuWindowTitle();
onActivity("");
}
}
handleAvatarChanged(jid);
}
void MUCController::addPresenceMessage(const std::string& message) {
lastWasPresence_ = true;
chatWindow_->addPresenceMessage(chatMessageParser_->parseMessageBody(message), ChatWindow::DefaultDirection);
}
void MUCController::setAvailableRoomActions(const MUCOccupant::Affiliation& affiliation, const MUCOccupant::Role& role)
{
std::vector<ChatWindow::RoomAction> actions;
if (role <= MUCOccupant::Participant) {
actions.push_back(ChatWindow::ChangeSubject);
}
if (affiliation == MUCOccupant::Owner) {
actions.push_back(ChatWindow::Configure);
}
if (affiliation <= MUCOccupant::Admin) {
actions.push_back(ChatWindow::Affiliations);
}
if (affiliation == MUCOccupant::Owner) {
actions.push_back(ChatWindow::Destroy);
}
if (role <= MUCOccupant::Visitor) {
actions.push_back(ChatWindow::Invite);
@@ -742,64 +738,60 @@ void MUCController::handleOccupantLeft(const MUCOccupant& occupant, MUC::Leaving
else {
switch (type) {
case MUC::LeaveKick: clearPresenceQueue(); clearAfter = true; partMessage = QT_TRANSLATE_NOOP("", "You have been kicked out of the room"); break;
case MUC::LeaveBan: clearPresenceQueue(); clearAfter = true; partMessage = QT_TRANSLATE_NOOP("", "You have been banned from the room"); break;
case MUC::LeaveNotMember: clearPresenceQueue(); clearAfter = true; partMessage = QT_TRANSLATE_NOOP("", "You are no longer a member of the room and have been removed"); break;
case MUC::LeaveDestroy: clearPresenceQueue(); clearAfter = true; partMessage = QT_TRANSLATE_NOOP("", "The room has been destroyed"); break;
case MUC::Disconnect:
case MUC::LeavePart: partMessage = QT_TRANSLATE_NOOP("", "You have left the room");
}
}
if (!reason.empty()) {
partMessage += " (" + reason + ")";
}
partMessage += ".";
if (occupant.getNick() != nick_) {
if (shouldUpdateJoinParts()) {
updateJoinParts();
} else {
addPresenceMessage(partMessage);
}
roster_->removeContact(JID(toJID_.getNode(), toJID_.getDomain(), occupant.getNick()));
} else {
addPresenceMessage(partMessage);
parting_ = true;
processUserPart();
}
if (clearAfter) {
clearPresenceQueue();
}
-
- if (isImpromptu_) {
- setImpromptuWindowTitle();
- }
}
void MUCController::handleOccupantNicknameChanged(const std::string& oldNickname, const std::string& newNickname) {
addPresenceMessage(generateNicknameChangeString(oldNickname, newNickname));
JID oldJID = muc_->getJID().withResource(oldNickname);
JID newJID = muc_->getJID().withResource(newNickname);
// adjust occupants
currentOccupants_.erase(oldNickname);
currentOccupants_.insert(newNickname);
// adjust completer
completer_->removeWord(oldNickname);
completer_->addWord(newNickname);
// update contact
roster_->removeContact(oldJID);
auto it = currentOccupants_.find(newNickname);
if (it != currentOccupants_.end()) {
roster_->removeContact(newJID);
}
MUCOccupant occupant = muc_->getOccupant(newNickname);
JID realJID;
if (occupant.getRealJID()) {
realJID = occupant.getRealJID().get();
}
MUCOccupant::Role role = MUCOccupant::Participant;
MUCOccupant::Affiliation affiliation = MUCOccupant::NoAffiliation;
@@ -1151,75 +1143,60 @@ Form::ref MUCController::buildImpromptuRoomConfiguration(Form::ref roomConfigura
}
if (field->getName() == "muc#roomconfig_publicroom") {
resultField = std::make_shared<FormField>(FormField::BooleanType, "0");
}
if (field->getName() == "muc#roomconfig_whois") {
resultField = std::make_shared<FormField>(FormField::ListSingleType, "anyone");
}
if (field->getName() == "FORM_TYPE") {
resultField = std::make_shared<FormField>(FormField::HiddenType, "http://jabber.org/protocol/muc#roomconfig");
}
if (resultField) {
impromptuConfigsMissing.erase(field->getName());
resultField->setName(field->getName());
result->addField(resultField);
}
}
for (const auto& config : impromptuConfigsMissing) {
if (config == "muc#roomconfig_publicroom") {
chatWindow_->addSystemMessage(chatMessageParser_->parseMessageBody(QT_TRANSLATE_NOOP("", "This server doesn't support hiding your chat from other users.")), ChatWindow::DefaultDirection);
} else if (config == "muc#roomconfig_whois") {
chatWindow_->addSystemMessage(chatMessageParser_->parseMessageBody(QT_TRANSLATE_NOOP("", "This server doesn't support sharing people's real identity in this chat.")), ChatWindow::DefaultDirection);
}
}
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.
if (!isImpromptuAlreadyConfigured_) {
if (isImpromptu_ && (muc_->getOccupant(nick_).getAffiliation() == MUCOccupant::Owner)) {
muc_->requestConfigurationForm();
} else if (isImpromptu_) {
onImpromptuConfigCompleted();
}
}
}
void MUCController::setAvailableServerFeatures(std::shared_ptr<DiscoInfo> info) {
ChatControllerBase::setAvailableServerFeatures(info);
if (iqRouter_->isAvailable() && info->hasFeature(DiscoInfo::BlockingCommandFeature)) {
std::shared_ptr<BlockList> blockList = clientBlockListManager_->getBlockList();
blockingOnStateChangedConnection_ = blockList->onStateChanged.connect(boost::bind(&MUCController::handleBlockingStateChanged, this));
blockingOnItemAddedConnection_ = blockList->onItemAdded.connect(boost::bind(&MUCController::handleBlockingStateChanged, this));
blockingOnItemRemovedConnection_ = blockList->onItemRemoved.connect(boost::bind(&MUCController::handleBlockingStateChanged, this));
handleBlockingStateChanged();
}
}
void MUCController::handleMUCBookmarkAdded(const MUCBookmark& bookmark) {
if (bookmark.getRoom() == muc_->getJID()) {
updateChatWindowBookmarkStatus(bookmark);
}
}
@@ -1234,31 +1211,36 @@ void MUCController::updateChatWindowBookmarkStatus(const boost::optional<MUCBook
assert(chatWindow_);
if (bookmark) {
if (bookmark->getAutojoin()) {
chatWindow_->setBookmarkState(ChatWindow::RoomAutoJoined);
}
else {
chatWindow_->setBookmarkState(ChatWindow::RoomBookmarked);
}
}
else {
chatWindow_->setBookmarkState(ChatWindow::RoomNotBookmarked);
}
}
void MUCController::displaySubjectIfChanged(const std::string& subject) {
if (subject_ != subject) {
if (!subject.empty()) {
chatWindow_->addSystemMessage(chatMessageParser_->parseMessageBody(str(format(QT_TRANSLATE_NOOP("", "The room subject is now: %1%")) % subject)), ChatWindow::DefaultDirection);
}
else {
chatWindow_->addSystemMessage(chatMessageParser_->parseMessageBody(str(format(QT_TRANSLATE_NOOP("", "The room subject has been removed")))), ChatWindow::DefaultDirection);
}
subject_ = subject;
}
}
void MUCController::addChatSystemMessage() {
lastJoinMessageUID_ = chatWindow_->addSystemMessage(chatMessageParser_->parseMessageBody(lastStartMessage_), ChatWindow::DefaultDirection);
}
+void MUCController::setChatWindowTitle(const std::string& title) {
+ chatWindowTitle_ = title;
+ chatWindow_->setName(chatWindowTitle_);
+}
+
}