summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTobias Markmann <tm@ayena.de>2014-10-07 11:58:34 (GMT)
committerSwift Review <review@swift.im>2014-10-17 18:18:54 (GMT)
commit1722d220533a78e8b2acbcd571631960656e78f8 (patch)
tree4da1095da990626652774962bab8a1c8db9ff2ea /Swift/Controllers/Chat/MUCController.cpp
parent0e7940bf2ede0147ee1eafced53bc9ad08a4015e (diff)
downloadswift-1722d220533a78e8b2acbcd571631960656e78f8.zip
swift-1722d220533a78e8b2acbcd571631960656e78f8.tar.bz2
Implement support for displaying nickname changes.
This implements Swiften API for changing nicknames in MUC and correctly detecting nick name changes. In addition Swift now displays nickname changes as such and not as join/leave of a user. In addition, handling of nickname changes is integrated in ChatsManager and ChatControllers so that they are forwarded to PM chats of MUCs. Test-Information: Added unit tests for change of own nickname and nickname changes of others. Tested correct detection of nickname changes in a MUC with a Psi user changing its nickname and Swift correctly detecting and displaying it. Change-Id: I3287ba6ceeccd3be5cfb591acd6f88bffc9a43b2
Diffstat (limited to 'Swift/Controllers/Chat/MUCController.cpp')
-rw-r--r--Swift/Controllers/Chat/MUCController.cpp45
1 files changed, 44 insertions, 1 deletions
diff --git a/Swift/Controllers/Chat/MUCController.cpp b/Swift/Controllers/Chat/MUCController.cpp
index b467227..fe90c60 100644
--- a/Swift/Controllers/Chat/MUCController.cpp
+++ b/Swift/Controllers/Chat/MUCController.cpp
@@ -103,6 +103,7 @@ MUCController::MUCController (
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));
@@ -483,7 +484,7 @@ std::string MUCController::roleToSortName(MUCOccupant::Role role) {
}
JID MUCController::nickToJID(const std::string& nick) {
- return JID(toJID_.getNode(), toJID_.getDomain(), nick);
+ return muc_->getJID().withResource(nick);
}
bool MUCController::messageTargetsMe(boost::shared_ptr<Message> message) {
@@ -691,6 +692,44 @@ void MUCController::handleOccupantLeft(const MUCOccupant& occupant, MUC::Leaving
}
}
+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);
+ MUCOccupant occupant = muc_->getOccupant(newNickname);
+
+ JID realJID;
+ if (occupant.getRealJID()) {
+ realJID = occupant.getRealJID().get();
+ }
+ 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(newJID, realJID, newNickname, groupName, avatarManager_->getAvatarPath(newJID));
+ roster_->applyOnItems(SetMUC(newJID, role, affiliation));
+ if (avatarManager_ != NULL) {
+ handleAvatarChanged(newJID);
+ }
+
+ clearPresenceQueue();
+ onUserNicknameChanged(oldNickname, newNickname);
+}
+
void MUCController::handleOccupantPresenceChange(boost::shared_ptr<Presence> presence) {
receivedActivity();
roster_->applyOnItems(SetPresence(presence, JID::WithResource));
@@ -818,6 +857,10 @@ std::string MUCController::generateJoinPartString(const std::vector<NickJoinPart
return result;
}
+std::string MUCController::generateNicknameChangeString(const std::string& oldNickname, const std::string& newNickname) {
+ return str(boost::format(QT_TRANSLATE_NOOP("", "%1% is now known as %2%.")) % oldNickname % newNickname);
+}
+
void MUCController::handleChangeSubjectRequest(const std::string& subject) {
muc_->changeSubject(subject);
}