diff options
Diffstat (limited to 'Swiften')
| -rw-r--r-- | Swiften/Elements/SecurityLabelsCatalog.h | 6 | ||||
| -rw-r--r-- | Swiften/MUC/MUC.cpp | 15 | ||||
| -rw-r--r-- | Swiften/MUC/MUC.h | 7 |
3 files changed, 17 insertions, 11 deletions
diff --git a/Swiften/Elements/SecurityLabelsCatalog.h b/Swiften/Elements/SecurityLabelsCatalog.h index b9419a9..5498fcf 100644 --- a/Swiften/Elements/SecurityLabelsCatalog.h +++ b/Swiften/Elements/SecurityLabelsCatalog.h @@ -1,79 +1,79 @@ /* * Copyright (c) 2010 Remko Tronçon * Licensed under the GNU General Public License v3. * See Documentation/Licenses/GPLv3.txt for more information. */ #pragma once #include <vector> #include <string> #include <boost/shared_ptr.hpp> #include <Swiften/JID/JID.h> #include <Swiften/Elements/Payload.h> #include <Swiften/Elements/SecurityLabel.h> namespace Swift { class SecurityLabelsCatalog : public Payload { public: typedef boost::shared_ptr<SecurityLabelsCatalog> ref; class Item { public: Item() : default_(false) {} - const boost::shared_ptr<SecurityLabel> getLabel() const { + SecurityLabel::ref getLabel() const { return label_; } - void setLabel(boost::shared_ptr<SecurityLabel> label) { + void setLabel(SecurityLabel::ref label) { label_ = label; } const std::string& getSelector() const { return selector_; } void setSelector(const std::string& selector) { selector_ = selector; } bool getIsDefault() const { return default_; } void setIsDefault(bool isDefault) { default_ = isDefault; } private: - boost::shared_ptr<SecurityLabel> label_; + SecurityLabel::ref label_; std::string selector_; bool default_; }; SecurityLabelsCatalog(const JID& to = JID()) : to_(to) {} const std::vector<Item>& getItems() const { return items_; } void addItem(const Item& item) { items_.push_back(item); } const JID& getTo() const { return to_; } void setTo(const JID& to) { to_ = to; } const std::string& getName() const { return name_; } void setName(const std::string& name) { name_ = name; } const std::string& getDescription() const { return description_; } void setDescription(const std::string& description) { description_ = description; diff --git a/Swiften/MUC/MUC.cpp b/Swiften/MUC/MUC.cpp index 15355ad..204fdcc 100644 --- a/Swiften/MUC/MUC.cpp +++ b/Swiften/MUC/MUC.cpp @@ -205,84 +205,89 @@ void MUC::handleIncomingPresence(Presence::ref presence) { 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) { return occupants.find(nick)->second; } -void MUC::kickUser(const JID& jid) { +void MUC::kickOccupant(const JID& jid) { + changeOccupantRole(jid, MUCOccupant::NoRole); +} + +void MUC::changeOccupantRole(const JID& jid, MUCOccupant::Role role) { MUCAdminPayload::ref mucPayload = boost::make_shared<MUCAdminPayload>(); MUCItem item; - item.role = MUCOccupant::NoRole; + 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::handleKickResponse, this, _1, _2, jid)); + request->onResponse.connect(boost::bind(&MUC::handleOccupantRoleChangeResponse, this, _1, _2, jid, role)); request->send(); + } -void MUC::handleKickResponse(MUCAdminPayload::ref /*unused*/, ErrorPayload::ref error, const JID& jid) { +void MUC::handleOccupantRoleChangeResponse(MUCAdminPayload::ref /*unused*/, ErrorPayload::ref error, const JID& jid, MUCOccupant::Role role) { if (error) { - onKickFailed(error, jid); + onRoleChangeFailed(error, jid, role); } } void MUC::changeSubject(const std::string& subject) { Message::ref message = boost::make_shared<Message>(); message->setSubject(subject); message->setType(Message::Groupchat); message->setTo(ownMUCJID.toBare()); stanzaChannel->sendMessage(message); } void MUC::requestConfigurationForm() { MUCOwnerPayload::ref mucPayload(new MUCOwnerPayload()); GenericRequest<MUCOwnerPayload>* request = new GenericRequest<MUCOwnerPayload>(IQ::Get, getJID(), mucPayload, iqRouter_); request->onResponse.connect(boost::bind(&MUC::handleConfigurationFormReceived, this, _1, _2)); request->send(); } void MUC::cancelConfigureRoom() { MUCOwnerPayload::ref mucPayload(new MUCOwnerPayload()); mucPayload->setPayload(boost::make_shared<Form>(Form::CancelType)); GenericRequest<MUCOwnerPayload>* request = new GenericRequest<MUCOwnerPayload>(IQ::Set, getJID(), mucPayload, iqRouter_); request->send(); } void MUC::handleConfigurationFormReceived(MUCOwnerPayload::ref payload, ErrorPayload::ref error) { Form::ref form; if (payload) { form = payload->getForm(); } if (error || !form) { onConfigurationFailed(error); } else { onConfigurationFormReceived(form); } diff --git a/Swiften/MUC/MUC.h b/Swiften/MUC/MUC.h index a9b42b8..d855033 100644 --- a/Swiften/MUC/MUC.h +++ b/Swiften/MUC/MUC.h @@ -24,93 +24,94 @@ 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); bool hasOccupant(const std::string& nick); - void kickUser(const JID& jid); + void kickOccupant(const JID& jid); + void changeOccupantRole(const JID& jid, MUCOccupant::Role role); 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&)> onKickFailed; + boost::signal<void (ErrorPayload::ref, const JID&, MUCOccupant::Role)> onRoleChangeFailed; boost::signal<void (ErrorPayload::ref)> onConfigurationFailed; 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 (const MUCInfo&)> onInfoResult; */ /* boost::signal<void (const blah&)> onItemsResult; */ private: bool isFromMUC(const JID& j) const { return ownMUCJID.equals(j, JID::WithoutResource); } const std::string& getOwnNick() const { return ownMUCJID.getResource(); } private: void handleIncomingPresence(Presence::ref presence); void internalJoin(const std::string& nick); void handleCreationConfigResponse(MUCOwnerPayload::ref, ErrorPayload::ref); - void handleKickResponse(MUCAdminPayload::ref, ErrorPayload::ref, const JID&); + void handleOccupantRoleChangeResponse(MUCAdminPayload::ref, ErrorPayload::ref, const JID&, MUCOccupant::Role); void handleConfigurationFormReceived(MUCOwnerPayload::ref, ErrorPayload::ref); void handleConfigurationResultReceived(MUCOwnerPayload::ref, ErrorPayload::ref); private: JID ownMUCJID; StanzaChannel* stanzaChannel; IQRouter* iqRouter_; DirectedPresenceSender* presenceSender; MUCRegistry* mucRegistry; std::map<std::string, MUCOccupant> occupants; bool joinSucceeded_; bool joinComplete_; boost::bsignals::scoped_connection scopedConnection_; boost::posix_time::ptime joinSince_; bool createAsReservedIfNew; bool unlocking; boost::optional<std::string> password; }; } |
Swift