/* * Copyright (c) 2010 Kevin Smith * Licensed under the GNU General Public License v3. * See Documentation/Licenses/GPLv3.txt for more information. */ #pragma once #include "Swiften/JID/JID.h" #include #include "Swiften/Elements/Message.h" #include "Swiften/Elements/Presence.h" #include "Swiften/Elements/MUCOccupant.h" #include "Swiften/MUC/MUCRegistry.h" #include "Swiften/Elements/MUCOwnerPayload.h" #include #include "Swiften/Base/boost_bsignals.h" #include #include namespace Swift { class StanzaChannel; class IQRouter; class DirectedPresenceSender; class MUC { public: typedef boost::shared_ptr 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); public: boost::signal onJoinComplete; boost::signal onJoinFailed; boost::signal onOccupantPresenceChange; boost::signal onOccupantRoleChanged; boost::signal onOccupantAffiliationChanged; boost::signal onOccupantJoined; boost::signal onOccupantLeft; /* boost::signal onInfoResult; */ /* boost::signal 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); private: JID ownMUCJID; StanzaChannel* stanzaChannel; IQRouter* iqRouter_; DirectedPresenceSender* presenceSender; MUCRegistry* mucRegistry; std::map occupants; bool joinSucceeded_; bool joinComplete_; boost::bsignals::scoped_connection scopedConnection_; boost::posix_time::ptime joinSince_; }; }