diff options
| author | Kevin Smith <git@kismith.co.uk> | 2011-10-19 11:03:21 (GMT) |
|---|---|---|
| committer | Kevin Smith <git@kismith.co.uk> | 2011-10-19 15:36:21 (GMT) |
| commit | 30359b48e18bcf171a53d50d84a178b9cb376d7a (patch) | |
| tree | 42b59ff30433bf7d3f164aa64639312e865d2d4b | |
| parent | b951e04a08f368dad564995813323fd098c70e95 (diff) | |
| download | swift-contrib-30359b48e18bcf171a53d50d84a178b9cb376d7a.zip swift-contrib-30359b48e18bcf171a53d50d84a178b9cb376d7a.tar.bz2 | |
Use real JID for bans, not room JID.
Resolves: #1020
| -rw-r--r-- | Swift/Controllers/Chat/MUCController.cpp | 16 | ||||
| -rw-r--r-- | Swiften/MUC/MUC.cpp | 2 | ||||
| -rw-r--r-- | Swiften/MUC/MUC.h | 2 |
3 files changed, 13 insertions, 7 deletions
diff --git a/Swift/Controllers/Chat/MUCController.cpp b/Swift/Controllers/Chat/MUCController.cpp index 6d3f9f2..1120f4b 100644 --- a/Swift/Controllers/Chat/MUCController.cpp +++ b/Swift/Controllers/Chat/MUCController.cpp @@ -94,76 +94,82 @@ MUCController::MUCController ( loginCheckTimer_->onTick.connect(boost::bind(&MUCController::handleJoinTimeoutTick, this)); loginCheckTimer_->start(); } chatWindow_->convertToMUC(); setOnline(true); if (avatarManager_ != NULL) { avatarChangedConnection_ = (avatarManager_->onAvatarChanged.connect(boost::bind(&MUCController::handleAvatarChanged, this, _1))); } handleBareJIDCapsChanged(muc->getJID()); } MUCController::~MUCController() { chatWindow_->setRosterModel(NULL); delete roster_; if (loginCheckTimer_) { loginCheckTimer_->stop(); } chatWindow_->setTabComplete(NULL); delete completer_; } void MUCController::handleWindowOccupantSelectionChanged(ContactRosterItem* item) { std::vector<ChatWindow::OccupantAction> actions; /* FIXME: all of these should be conditional */ if (item) { actions.push_back(ChatWindow::Kick); actions.push_back(ChatWindow::Ban); actions.push_back(ChatWindow::MakeModerator); actions.push_back(ChatWindow::MakeParticipant); actions.push_back(ChatWindow::MakeVisitor); } chatWindow_->setAvailableOccupantActions(actions); } void MUCController::handleActionRequestedOnOccupant(ChatWindow::OccupantAction action, ContactRosterItem* item) { + JID mucJID = item->getJID(); + MUCOccupant occupant = muc_->getOccupant(mucJID.getResource()); + JID realJID; + if (occupant.getRealJID()) { + realJID = occupant.getRealJID().get(); + } switch (action) { - case ChatWindow::Kick: muc_->kickOccupant(item->getJID());break; - case ChatWindow::Ban: muc_->changeAffiliation(item->getJID(), MUCOccupant::Outcast);break; - case ChatWindow::MakeModerator: muc_->changeOccupantRole(item->getJID(), MUCOccupant::Moderator);break; - case ChatWindow::MakeParticipant: muc_->changeOccupantRole(item->getJID(), MUCOccupant::Participant);break; - case ChatWindow::MakeVisitor: muc_->changeOccupantRole(item->getJID(), MUCOccupant::Visitor);break; + case ChatWindow::Kick: muc_->kickOccupant(mucJID);break; + case ChatWindow::Ban: muc_->changeAffiliation(realJID, MUCOccupant::Outcast);break; + case ChatWindow::MakeModerator: muc_->changeOccupantRole(mucJID, MUCOccupant::Moderator);break; + case ChatWindow::MakeParticipant: muc_->changeOccupantRole(mucJID, MUCOccupant::Participant);break; + case ChatWindow::MakeVisitor: muc_->changeOccupantRole(mucJID, MUCOccupant::Visitor);break; } } void MUCController::handleBareJIDCapsChanged(const JID& /*jid*/) { ChatWindow::Tristate support = ChatWindow::Yes; bool any = false; foreach (const std::string& nick, currentOccupants_) { DiscoInfo::ref disco = entityCapsProvider_->getCaps(toJID_.toBare().toString() + "/" + nick); if (disco && disco->hasFeature(DiscoInfo::MessageCorrectionFeature)) { any = true; } else { support = ChatWindow::Maybe; } } if (!any) { support = ChatWindow::No; } chatWindow_->setCorrectionEnabled(support); } /** * Join the MUC if not already in it. */ void MUCController::rejoin() { if (parting_) { joined_ = false; parting_ = false; if (password_) { muc_->setPassword(*password_); } //FIXME: check for received activity if (lastActivity_ == boost::posix_time::not_a_date_time) { muc_->joinAs(nick_); } else { muc_->joinWithContextSince(nick_, lastActivity_); diff --git a/Swiften/MUC/MUC.cpp b/Swiften/MUC/MUC.cpp index 824ced1..78546c8 100644 --- a/Swiften/MUC/MUC.cpp +++ b/Swiften/MUC/MUC.cpp @@ -201,71 +201,71 @@ void MUC::handleIncomingPresence(Presence::ref presence) { presenceSender->removeDirectedPresenceReceiver(ownMUCJID, DirectedPresenceSender::DontSendPresence); ownMUCJID = presence->getFrom(); presenceSender->addDirectedPresenceReceiver(ownMUCJID, DirectedPresenceSender::AndSendPresence); } if (createAsReservedIfNew) { unlocking = true; requestConfigurationForm(); } else { MUCOwnerPayload::ref mucPayload(new MUCOwnerPayload()); presenceSender->addDirectedPresenceReceiver(ownMUCJID, DirectedPresenceSender::DontSendPresence); mucPayload->setPayload(boost::make_shared<Form>(Form::SubmitType)); GenericRequest<MUCOwnerPayload>* request = new GenericRequest<MUCOwnerPayload>(IQ::Set, getJID(), mucPayload, iqRouter_); request->onResponse.connect(boost::bind(&MUC::handleCreationConfigResponse, this, _1, _2)); request->send(); } } } } } void MUC::handleCreationConfigResponse(MUCOwnerPayload::ref /*unused*/, ErrorPayload::ref error) { unlocking = false; if (error) { presenceSender->removeDirectedPresenceReceiver(ownMUCJID, DirectedPresenceSender::AndSendPresence); onJoinFailed(error); } else { onJoinComplete(getOwnNick()); /* Previously, this wasn't needed here, as the presence duplication bug caused an emit elsewhere. */ } } bool MUC::hasOccupant(const std::string& nick) { return occupants.find(nick) != occupants.end(); } -MUCOccupant MUC::getOccupant(const std::string& nick) { +const MUCOccupant& MUC::getOccupant(const std::string& nick) { return occupants.find(nick)->second; } void MUC::kickOccupant(const JID& jid) { changeOccupantRole(jid, MUCOccupant::NoRole); } /** * Call with the room JID, not the real JID. */ void MUC::changeOccupantRole(const JID& jid, MUCOccupant::Role role) { MUCAdminPayload::ref mucPayload = boost::make_shared<MUCAdminPayload>(); MUCItem item; item.role = role; item.nick = jid.getResource(); mucPayload->addItem(item); GenericRequest<MUCAdminPayload>* request = new GenericRequest<MUCAdminPayload>(IQ::Set, getJID(), mucPayload, iqRouter_); request->onResponse.connect(boost::bind(&MUC::handleOccupantRoleChangeResponse, this, _1, _2, jid, role)); request->send(); } void MUC::handleOccupantRoleChangeResponse(MUCAdminPayload::ref /*unused*/, ErrorPayload::ref error, const JID& jid, MUCOccupant::Role role) { if (error) { onRoleChangeFailed(error, jid, role); } } void MUC::requestAffiliationList(MUCOccupant::Affiliation affiliation) { MUCAdminPayload::ref mucPayload = boost::make_shared<MUCAdminPayload>(); MUCItem item; item.affiliation = affiliation; mucPayload->addItem(item); GenericRequest<MUCAdminPayload>* request = new GenericRequest<MUCAdminPayload>(IQ::Get, getJID(), mucPayload, iqRouter_); request->onResponse.connect(boost::bind(&MUC::handleAffiliationListResponse, this, _1, _2, affiliation)); diff --git a/Swiften/MUC/MUC.h b/Swiften/MUC/MUC.h index 1070c69..39acb22 100644 --- a/Swiften/MUC/MUC.h +++ b/Swiften/MUC/MUC.h @@ -22,71 +22,71 @@ #include <map> namespace Swift { class StanzaChannel; class IQRouter; class DirectedPresenceSender; class MUC { public: typedef boost::shared_ptr<MUC> ref; enum JoinResult { JoinSucceeded, JoinFailed }; enum LeavingType { Part, Disconnect }; public: MUC(StanzaChannel* stanzaChannel, IQRouter* iqRouter, DirectedPresenceSender* presenceSender, const JID &muc, MUCRegistry* mucRegistry); /** * Returns the (bare) JID of the MUC. */ JID getJID() const { return ownMUCJID.toBare(); } void joinAs(const std::string &nick); void joinWithContextSince(const std::string &nick, const boost::posix_time::ptime& since); /*void queryRoomInfo(); */ /*void queryRoomItems(); */ std::string getCurrentNick(); void part(); void handleIncomingMessage(Message::ref message); /** Expose public so it can be called when e.g. user goes offline */ void handleUserLeft(LeavingType); /** Get occupant information*/ - MUCOccupant getOccupant(const std::string& nick); + const MUCOccupant& getOccupant(const std::string& nick); bool hasOccupant(const std::string& nick); void kickOccupant(const JID& jid); void changeOccupantRole(const JID& jid, MUCOccupant::Role role); void requestAffiliationList(MUCOccupant::Affiliation); void changeAffiliation(const JID& jid, MUCOccupant::Affiliation affiliation); void changeSubject(const std::string& subject); void requestConfigurationForm(); void configureRoom(Form::ref); void cancelConfigureRoom(); void destroyRoom(); /** Send an invite for the person to join the MUC */ void invitePerson(const JID& person, const std::string& reason = ""); void setCreateAsReservedIfNew() {createAsReservedIfNew = true;} void setPassword(const boost::optional<std::string>& password); public: boost::signal<void (const std::string& /*nick*/)> onJoinComplete; boost::signal<void (ErrorPayload::ref)> onJoinFailed; boost::signal<void (ErrorPayload::ref, const JID&, MUCOccupant::Role)> onRoleChangeFailed; boost::signal<void (ErrorPayload::ref, const JID&, MUCOccupant::Affiliation)> onAffiliationChangeFailed; boost::signal<void (ErrorPayload::ref)> onConfigurationFailed; boost::signal<void (ErrorPayload::ref)> onAffiliationListFailed; boost::signal<void (Presence::ref)> onOccupantPresenceChange; boost::signal<void (const std::string&, const MUCOccupant& /*now*/, const MUCOccupant::Role& /*old*/)> onOccupantRoleChanged; boost::signal<void (const std::string&, const MUCOccupant::Affiliation& /*new*/, const MUCOccupant::Affiliation& /*old*/)> onOccupantAffiliationChanged; boost::signal<void (const MUCOccupant&)> onOccupantJoined; boost::signal<void (const MUCOccupant&, LeavingType, const std::string& /*reason*/)> onOccupantLeft; boost::signal<void (Form::ref)> onConfigurationFormReceived; boost::signal<void (MUCOccupant::Affiliation, const std::vector<JID>&)> onAffiliationListReceived; /* boost::signal<void (const MUCInfo&)> onInfoResult; */ /* boost::signal<void (const blah&)> onItemsResult; */ private: bool isFromMUC(const JID& j) const { |
Swift