diff options
author | Tobias Markmann <tm@ayena.de> | 2014-10-07 11:58:34 (GMT) |
---|---|---|
committer | Swift Review <review@swift.im> | 2014-10-17 18:18:54 (GMT) |
commit | 1722d220533a78e8b2acbcd571631960656e78f8 (patch) | |
tree | 4da1095da990626652774962bab8a1c8db9ff2ea /Swiften/MUC/MUCImpl.cpp | |
parent | 0e7940bf2ede0147ee1eafced53bc9ad08a4015e (diff) | |
download | swift-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 'Swiften/MUC/MUCImpl.cpp')
-rw-r--r-- | Swiften/MUC/MUCImpl.cpp | 41 |
1 files changed, 32 insertions, 9 deletions
diff --git a/Swiften/MUC/MUCImpl.cpp b/Swiften/MUC/MUCImpl.cpp index a1854e3..ab5faf4 100644 --- a/Swiften/MUC/MUCImpl.cpp +++ b/Swiften/MUC/MUCImpl.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2010-2013 Kevin Smith + * Copyright (c) 2010-2014 Kevin Smith * Licensed under the GNU General Public License v3. * See Documentation/Licenses/GPLv3.txt for more information. */ @@ -90,6 +90,12 @@ void MUCImpl::internalJoin(const std::string &nick) { presenceSender->sendPresence(joinPresence); } +void MUCImpl::changeNickname(const std::string& newNickname) { + Presence::ref changeNicknamePresence = boost::make_shared<Presence>(); + changeNicknamePresence->setTo(ownMUCJID.toBare().toString() + std::string("/") + newNickname); + presenceSender->sendPresence(changeNicknamePresence); +} + void MUCImpl::part() { presenceSender->removeDirectedPresenceReceiver(ownMUCJID, DirectedPresenceSender::AndSendPresence); mucRegistry->removeMUC(getJID()); @@ -154,6 +160,7 @@ void MUCImpl::handleIncomingPresence(Presence::ref presence) { //TODO: Nick changes if (presence->getType() == Presence::Unavailable) { LeavingType type = LeavePart; + boost::optional<std::string> newNickname; if (mucPayload) { if (boost::dynamic_pointer_cast<MUCDestroyPayload>(mucPayload->getPayload())) { type = LeaveDestroy; @@ -168,20 +175,36 @@ void MUCImpl::handleIncomingPresence(Presence::ref presence) { else if (status.code == 321) { type = LeaveNotMember; } + else if (status.code == 303) { + if (mucPayload->getItems().size() == 1) { + newNickname = mucPayload->getItems()[0].nick; + } + } } } - - if (presence->getFrom() == ownMUCJID) { - handleUserLeft(type); - return; - } - else { + if (newNickname) { std::map<std::string,MUCOccupant>::iterator i = occupants.find(nick); if (i != occupants.end()) { - //TODO: part type MUCOccupant occupant = i->second; occupants.erase(i); - onOccupantLeft(occupant, type, ""); + occupant.setNick(newNickname.get()); + occupants.insert(std::make_pair(newNickname.get(), occupant)); + onOccupantNicknameChanged(nick, newNickname.get()); + } + } + else { + if (presence->getFrom() == ownMUCJID) { + handleUserLeft(type); + return; + } + else { + std::map<std::string,MUCOccupant>::iterator i = occupants.find(nick); + if (i != occupants.end()) { + //TODO: part type + MUCOccupant occupant = i->second; + occupants.erase(i); + onOccupantLeft(occupant, type, ""); + } } } } |