• Main Page
  • Classes
  • Files
  • File List

Swiften/MUC/MUC.h

00001 /*
00002  * Copyright (c) 2010 Kevin Smith
00003  * Licensed under the GNU General Public License v3.
00004  * See Documentation/Licenses/GPLv3.txt for more information.
00005  */
00006 
00007 #pragma once
00008 
00009 #include <Swiften/JID/JID.h>
00010 #include <Swiften/Base/API.h>
00011 #include <string>
00012 #include <Swiften/Elements/Message.h>
00013 #include <Swiften/Elements/Presence.h>
00014 #include <Swiften/Elements/MUCOccupant.h>
00015 #include <Swiften/MUC/MUCRegistry.h>
00016 #include <Swiften/Elements/MUCOwnerPayload.h>
00017 #include <Swiften/Elements/MUCAdminPayload.h>
00018 #include <Swiften/Elements/Form.h>
00019 
00020 #include <boost/shared_ptr.hpp>
00021 #include <Swiften/Base/boost_bsignals.h>
00022 #include <boost/signals/connection.hpp>
00023 
00024 #include <map>
00025 
00026 namespace Swift {
00027   class StanzaChannel;
00028   class IQRouter;
00029   class DirectedPresenceSender;
00030 
00031   class SWIFTEN_API MUC {
00032     public:
00033       typedef boost::shared_ptr<MUC> ref;
00034 
00035       enum JoinResult { JoinSucceeded, JoinFailed };
00036       enum LeavingType { LeavePart, LeaveKick, LeaveBan, LeaveDestroy, LeaveNotMember, Disconnect };
00037 
00038     public:
00039       MUC(StanzaChannel* stanzaChannel, IQRouter* iqRouter, DirectedPresenceSender* presenceSender, const JID &muc, MUCRegistry* mucRegistry);
00040 
00044       JID getJID() const {
00045         return ownMUCJID.toBare();
00046       }
00047 
00048       void joinAs(const std::string &nick);
00049       void joinWithContextSince(const std::string &nick, const boost::posix_time::ptime& since);
00050       /*void queryRoomInfo(); */
00051       /*void queryRoomItems(); */
00052       std::string getCurrentNick();
00053       void part();
00054       void handleIncomingMessage(Message::ref message);
00056       void handleUserLeft(LeavingType);
00058       const MUCOccupant& getOccupant(const std::string& nick);
00059       bool hasOccupant(const std::string& nick);
00060       void kickOccupant(const JID& jid);
00061       void changeOccupantRole(const JID& jid, MUCOccupant::Role role);
00062       void requestAffiliationList(MUCOccupant::Affiliation);
00063       void changeAffiliation(const JID& jid, MUCOccupant::Affiliation affiliation);
00064       void changeSubject(const std::string& subject);
00065       void requestConfigurationForm();
00066       void configureRoom(Form::ref);
00067       void cancelConfigureRoom();
00068       void destroyRoom();
00070       void invitePerson(const JID& person, const std::string& reason = "");
00071       void setCreateAsReservedIfNew() {createAsReservedIfNew = true;}
00072       void setPassword(const boost::optional<std::string>& password);
00073       
00074     public:
00075       boost::signal<void (const std::string& /*nick*/)> onJoinComplete;
00076       boost::signal<void (ErrorPayload::ref)> onJoinFailed;
00077       boost::signal<void (ErrorPayload::ref, const JID&, MUCOccupant::Role)> onRoleChangeFailed;
00078       boost::signal<void (ErrorPayload::ref, const JID&, MUCOccupant::Affiliation)> onAffiliationChangeFailed;
00079       boost::signal<void (ErrorPayload::ref)> onConfigurationFailed;
00080       boost::signal<void (ErrorPayload::ref)> onAffiliationListFailed;
00081       boost::signal<void (Presence::ref)> onOccupantPresenceChange;
00082       boost::signal<void (const std::string&, const MUCOccupant& /*now*/, const MUCOccupant::Role& /*old*/)> onOccupantRoleChanged;
00083       boost::signal<void (const std::string&, const MUCOccupant::Affiliation& /*new*/, const MUCOccupant::Affiliation& /*old*/)> onOccupantAffiliationChanged;
00084       boost::signal<void (const MUCOccupant&)> onOccupantJoined;
00085       boost::signal<void (const MUCOccupant&, LeavingType, const std::string& /*reason*/)> onOccupantLeft;
00086       boost::signal<void (Form::ref)> onConfigurationFormReceived;
00087       boost::signal<void (MUCOccupant::Affiliation, const std::vector<JID>&)> onAffiliationListReceived;
00088       /* boost::signal<void (const MUCInfo&)> onInfoResult; */
00089       /* boost::signal<void (const blah&)> onItemsResult; */
00090       
00091 
00092     private:
00093       bool isFromMUC(const JID& j) const {
00094         return ownMUCJID.equals(j, JID::WithoutResource);
00095       }
00096 
00097       const std::string& getOwnNick() const {
00098         return ownMUCJID.getResource();
00099       }
00100 
00101     private:
00102       void handleIncomingPresence(Presence::ref presence);
00103       void internalJoin(const std::string& nick);
00104       void handleCreationConfigResponse(MUCOwnerPayload::ref, ErrorPayload::ref);
00105       void handleOccupantRoleChangeResponse(MUCAdminPayload::ref, ErrorPayload::ref, const JID&, MUCOccupant::Role);
00106       void handleAffiliationChangeResponse(MUCAdminPayload::ref, ErrorPayload::ref, const JID&, MUCOccupant::Affiliation);
00107       void handleAffiliationListResponse(MUCAdminPayload::ref, ErrorPayload::ref, MUCOccupant::Affiliation);
00108       void handleConfigurationFormReceived(MUCOwnerPayload::ref, ErrorPayload::ref);
00109       void handleConfigurationResultReceived(MUCOwnerPayload::ref, ErrorPayload::ref);
00110 
00111     private:
00112       JID ownMUCJID;
00113       StanzaChannel* stanzaChannel;
00114       IQRouter* iqRouter_;
00115       DirectedPresenceSender* presenceSender;
00116       MUCRegistry* mucRegistry;
00117       std::map<std::string, MUCOccupant> occupants;
00118       bool joinSucceeded_;
00119       bool joinComplete_;
00120       boost::bsignals::scoped_connection scopedConnection_;
00121       boost::posix_time::ptime joinSince_;
00122       bool createAsReservedIfNew;
00123       bool unlocking;
00124       boost::optional<std::string> password;
00125   };
00126 }

Generated on Fri Oct 12 2012 21:00:19 for Swiften by  doxygen 1.7.1