#include <messagesession.h>
Inherited by MUCMessageSession.
Inheritance diagram for MessageSession:

Public Member Functions | |
| MessageSession (ClientBase *parent, const JID &jid, bool wantUpgrade=true, int types=0) | |
| virtual | ~MessageSession () |
| const JID & | target () const |
| const std::string & | threadID () const |
| void | setThreadID (const std::string &thread) |
| void | registerMessageHandler (MessageHandler *mh) |
| void | removeMessageHandler () |
| virtual void | send (const std::string &message, const std::string &subject=EmptyString) |
| void | registerMessageFilter (MessageFilter *mf) |
| void | removeMessageFilter (MessageFilter *mf) |
| void | disposeMessageFilter (MessageFilter *mf) |
| int | types () const |
| void | resetResource () |
| virtual void | handleMessage (Message &msg) |
Protected Member Functions | |
| virtual void | send (const Message &msg) |
This is an alternative interface to raw, old-style messaging. The original interface, using the simple MessageHandler-derived interface, is based on an all-or-nothing approach. Once registered with ClientBase, a handler receives all message stanzas sent to this client and has to do any filtering on its own.
MessageSession adds an abstraction to a chat conversation. A MessageSession is responsible for communicating with exactly one (full) JID. It is extensible with so-called MessageFilters, which can provide additional features such as Message Events, Chat State Notifications or In-Band Bytestreams.
You can still use the old MessageHandler in parallel, but messages will not be relayed to both the generic MessageHandler and a MessageSession established for the sender's JID. The MessageSession takes precedence.
Using MessageSessions has the following advantages over the plain old MessageHandler:
Derive an object from MessageSessionHandler and reimplement handleMessageSession() to store your shiny new sessions somewhere, or to create a new chat window, or whatever. Register your object with a ClientBase instance using registerMessageSessionHandler(). In code:
void MyClass::myFunc() { JID jid( "abc@example.org/gloox" ); j = new Client( jid, "password" ); [...] j->registerMessageSessionHandler( this, 0 ); }
In this example, MyClass needs to be MessageHandler, MessageEventHandler and ChatStateHandler, too. The handlers are registered with the session to receive the respective events.
virtual void MyClass::handleMessageSession( MessageSession* session ) { // for this example only, we delete any earlier session if( m_session ) j->disposeMessageSession( m_session ); m_session = session; m_session->registerMessageHandler( this ); // the following is optional m_messageEventFilter = new MessageEventFilter( m_session ); m_messageEventFilter->registerMessageEventHandler( this ); m_chatStateFilter = new ChatStateFilter( m_session ); m_chatStateFilter->registerChatStateHandler( this ); }
MessageEventHandler::handleMessageEvent() and ChatStateHandler::handleChatState() are called for incoming Message Events and Chat States, respectively.
virtual void MyClass::handleMessageEvent( const JID& from, MessageEventType event ) { // display contact's Message Event } virtual void MyClass::handleChatState( const JID& from, ChatStateType state ) { // display contact's Chat State }
To let the chat partner now that the user is typing a message or has closed the chat window, use raiseMessageEvent() and setChatState(), respectively. For example:
// user is typing a message m_messageEventFilter->raiseMessageEvent( MessageEventComposing ); // acknowledge receiving of a message m_messageEventFilter->raiseMessageEvent( MessageEventDelivered ); // user is not actively paying attention to the chat m_chatStateFilter->setChatState( ChatStateInactive ); // user has closed the chat window m_chatStateFilter->setChatState( ChatStateGone );
To send a message to the chat partner of the session, use send( const std::string& message, const std::string& subject ). You don't have to care about receipient, thread id, etc., they are added automatically.
m_session->send( "Hello World!", "No Subject" );
To initiate a new chat session, all you have to do is create a new MessageSession and register a MessageHandler with it:
MessageSession* MyClass::newSession( const JID& to ) { MessageSession* session = new MessageSession( m_client, to ); session->registerMessageHandler( this ); return session; }
See InBandBytestreamManager for a detailed description on how to implement In-Band Bytestreams.
Definition at line 146 of file messagesession.h.
|
||||||||||||||||||||
|
Constructs a new MessageSession for the given JID. It is recommended to supply a full JID, in other words, it should have a resource set. No resource can lead to unexpected behavior. A thread ID is generated and sent along with every message sent through this session.
Definition at line 24 of file messagesession.cpp. |
|
|
Virtual destructor.
Definition at line 32 of file messagesession.cpp. |
|
|
Use this function to remove and delete a MessageFilter from the MessageSession.
Definition at line 115 of file messagesession.cpp. |
|
|
This function can be used to feed a message into the session. Ususally, only ClientBase should call this function.
Reimplemented in MUCMessageSession. Definition at line 47 of file messagesession.cpp. |
|
|
Use this function to hook a new MessageFilter into a MessageSession. The filter will be able to read and/or modify a message stanza's content.
Definition at line 230 of file messagesession.h. |
|
|
Use this function to associate a MessageHandler with this MessageSession. The MessageHandler will receive all messages sent from this MessageSession's remote contact.
Definition at line 204 of file messagesession.h. |
|
|
Use this function to remove a MessageFilter from the MessageSession.
Definition at line 238 of file messagesession.h. |
|
|
This function clears the internal pointer to the MessageHandler and therefore disables message delivery. Definition at line 211 of file messagesession.h. |
|
|
This function resets the session's target JID to its bare form such that subsequently sent messages will be sent to that bare JID. The server will determine the best resource to deliver to. Useful if the target resource changed presence to e.g. away or offline. Definition at line 104 of file messagesession.cpp. |
|
|
A wrapper around ClientBase::send(). You should not use this function to send a chat message because the Tag is not prepared accordingly (neither Thread ID nor is the mesage ran through the message filters).
Definition at line 94 of file messagesession.cpp. |
|
||||||||||||
|
A convenience function to quickly send a message (optionally with subject). This is the preferred way to send a message from a MessageSession.
Definition at line 80 of file messagesession.cpp. |
|
|
Use this function to set the session's thread ID if e.g. a specific thread is continued. It shpuld not normally be needed to set the thread ID manually.
Definition at line 196 of file messagesession.h. |
|
|
Use this function to find out where this session points at.
Definition at line 182 of file messagesession.h. |
|
|
By default, a thread ID is sent with every message to identify messages belonging together.
Definition at line 189 of file messagesession.h. |
|
|
Returns the message type this MessageSession wants to receive.
Definition at line 252 of file messagesession.h. |
1.4.1