📄 mucroom.h
字号:
/* Copyright (c) 2006-2008 by Jakob Schroeter <js@camaya.net> This file is part of the gloox library. http://camaya.net/gloox This software is distributed under a license. The full license agreement can be found in the file LICENSE in this distribution. This software may not be copied, modified, sold or distributed other than expressed in the named license agreement. This software is distributed without any warranty.*/#ifndef MUCROOM_H__#define MUCROOM_H__#include "discohandler.h"#include "disconodehandler.h"#include "presencehandler.h"#include "iqhandler.h"#include "messagehandler.h"#include "mucroomhandler.h"#include "mucroomconfighandler.h"#include "jid.h"#include <string>namespace gloox{ class ClientBase; class MUCMessageSession; class Stanza; /** * @brief This is an implementation of XEP-0045 (Multi-User Chat). * * Usage is pretty simple: * * Derrive an object from MUCRoomHandler and implement its virtuals: * @code * class MyClass : public MUCRoomHandler * { * ... * }; * @endcode * * Then create a new MUCRoom object and pass it a valid ClientBase, the desired full room JID, * your MUCRoomHandler-derived object, and an optional MUCRoomConfigHandler-derived object. * @code * void MyOtherClass::joinRoom( const std::string& room, const std::string& service, * const std::string& nick ) * { * MyClass *myHandler = new MyClass(...); * JID roomJID( room + "@" + service + "/" + nick ); * m_room = new MUCRoom( m_clientbase, roomJID, myHandler, 0 ); * m_room->join(); * } * @endcode * * When joining the room was successful, the various MUCRoomHandler functions will start to * be called. If joining was not successful, MUCRoomHandler::handleMUCError() will be called, * giving a hint at the reason for the failure. * * To set up your own room, or to configure an existing room, you should also derive a * class from MUCRoomConfigHandler and register it with the MUCRoom (either by using it * with MUCRoom's constructor, or by calling registerMUCRoomConfigHandler()). * * To quickly create an instant room, see InstantMUCRoom. * * To quickly create an instant room to turn a one-to-one chat into a multi-user chat, * see UniqueMUCRoom. * * To send a private message to a room participant, use * @link MessageSession gloox::MessageSession @endlink with the participant's full room JID * (room\@service/nick). * * XEP version: 1.21 * @author Jakob Schroeter <js@camaya.net> * @since 0.9 */ class GLOOX_API MUCRoom : private DiscoHandler, private PresenceHandler, public IqHandler, private MessageHandler, private DiscoNodeHandler { public: /** * Allowable history request types. To disable sending of history, use any value except * HistoryUnknown and specify a zero-length time span (using setRequestHistory()). */ enum HistoryRequestType { HistoryUnknown, /**< It is up to the service to decide how much history to send. * This is the default. */ HistoryMaxChars, /**< Limit the total number of characters in the history to "X" * (where the character count is the characters of the complete * XML stanzas, not only their XML character data). */ HistoryMaxStanzas, /**< Limit the total number of messages in the history to "X". */ HistorySeconds, /**< Send only the messages received in the last "X" seconds. */ HistorySince /**< Send only the messages received since the datetime specified * (which MUST conform to the DateTime profile specified in Jabber * Date and Time Profiles (XEP-0082)). */ }; /** * Creates a new abstraction of a Multi-User Chat room. The room is not joined automatically. * Use join() to join the room, use leave() to leave it. * @param parent The ClientBase object to use for the communication. * @param nick The room's name and service plus the desired nickname in the form * room\@service/nick. * @param mrh The MUCRoomHandler that will listen to room events. May be 0 and may be specified * later using registerMUCRoomHandler(). However, without one, MUC is no joy. * @param mrch The MUCRoomConfigHandler that will listen to room config result. Defaults to 0 * initially. However, at the latest you need one when you create a new room which is not an * instant room. You can set a MUCRoomConfigHandler using registerMUCRoomConfigHandler(). */ MUCRoom( ClientBase *parent, const JID& nick, MUCRoomHandler *mrh, MUCRoomConfigHandler *mrch = 0 ); /** * Virtual Destructor. */ virtual ~MUCRoom(); /** * Use this function to set a password to use when joining a (password protected) * room. * @param password The password to use for this room. * @note This function does not password-protect a room. */ void setPassword( const std::string& password ) { m_password = password; } /** * A convenience function that returns the room's name. * @return The room's name. */ const std::string name() const { return m_nick.username(); } /** * A convenience function that returns the name/address of the MUC service the room is running on * (e.g., conference.jabber.org). * @return The MUC service's name/address. */ const std::string service() const { return m_nick.server(); } /** * A convenience function that returns the user's nickname in the room. * @return The user's nickname. */ const std::string nick() const { return m_nick.resource(); } /** * Join this room. */ virtual void join(); /** * Leave this room. * @param msg An optional msg indicating the reason for leaving the room. Default: empty. */ void leave( const std::string& msg = "" ); /** * Sends a chat message to the room. * @param message The message to send. */ void send( const std::string& message ); /** * Sets the subject of the room to the given string. * The MUC service may decline the request to set a new subject. You should * not assume the subject was set successfully util it is acknowledged via the MUCRoomHandler. * @param subject The new subject. */ void setSubject( const std::string& subject ); /** * Returns the user's current affiliation with this room. * @return The user's current affiliation. */ MUCRoomAffiliation affiliation() const { return m_affiliation; } /** * Returns the user's current role in this room. * @return The user's current role. */ MUCRoomRole role() const { return m_role; } /** * Use this function to change the user's nickname in the room. * The MUC service may decline the request to set a new nickname. You should not assume * the nick change was successful until it is acknowledged via the MUCRoomHandler. * @param nick The user's new nickname. */ void setNick( const std::string& nick ); /** * Use this function to set the user's presence in this room. It is not possible to * use PresenceUnavailable with this function. * @param presence The user's new presence. * @param msg An optional status message. Default: empty. */ void setPresence( Presence presence, const std::string& msg = "" ); /** * Use this function to invite another user to this room. * @param invitee The (bare) JID of the user to invite. * @param reason The user-supplied reason for the invitation. * @param cont Whether this invitation is part of a transformation of a * one-to-one chat to a MUC. Default: false. */ void invite( const JID& invitee, const std::string& reason, bool cont = false ); /** * Use this function to request basic room info, possibly prior to joining it. * Results are announced using the MUCRoomHandler. */ void getRoomInfo(); /** * Use this function to request information about the current room occupants, * possibly prior to joining it. The room ay be configured not to disclose such * information. * Results are announced using the MUCRoomHandler. */ void getRoomItems(); /** * The MUC spec enables other entities to discover via Service Discovery which rooms * an entity is in. By default, gloox does not publish such info for privacy reasons. * This function can be used to enable publishing the info for @b this room. * @param publish Whether to enable other entities to discover the user's presence in * @b this room. * @param publishNick Whether to publish the nickname used in the room. This parameter * is ignored if @c publish is @b false. */ void setPublish( bool publish, bool publishNick ); /** * Use this function to register a (new) MUCRoomHandler with this room. There can be only one * MUCRoomHandler per room at any one time. * @param mrl The MUCRoomHandler to register. */ void registerMUCRoomHandler( MUCRoomHandler *mrl ) { m_roomHandler = mrl; } /** * Use this function to remove the registered MUCRoomHandler. */ void removeMUCRoomHandler() { m_roomHandler = 0; } /** * Use this function to register a (new) MUCRoomConfigHandler with this room. There can * be only one MUCRoomConfigHandler per room at any one time. * @param mrch The MUCRoomConfigHandler to register. */ void registerMUCRoomConfigHandler( MUCRoomConfigHandler *mrch ) { m_roomConfigHandler = mrch; } /** * Use this function to remove the registered MUCRoomConfigHandler. */ void removeMUCRoomConfigHandler() { m_roomConfigHandler = 0; } /** * Use this function to add history to a (newly created) room. The use case from the MUC spec * is to add history to a room that was created in the process of a transformation of a * one-to-one chat to a multi-user chat. * @param message A reason for declining the invitation. * @param from The JID of the original author of this part of the history. * @param stamp The datetime of the original message in the format: 20061224T12:15:23Z * @note You should not attempt to use this function before * MUCRoomHandler::handleMUCParticipantPresence() was called for the first time. */ void addHistory( const std::string& message, const JID& from, const std::string& stamp );
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -