gloox  1.0.20
chatstatefilter.cpp
1 /*
2  Copyright (c) 2005-2017 by Jakob Schröter <js@camaya.net>
3  This file is part of the gloox library. http://camaya.net/gloox
4 
5  This software is distributed under a license. The full license
6  agreement can be found in the file LICENSE in this distribution.
7  This software may not be copied, modified, sold or distributed
8  other than expressed in the named license agreement.
9 
10  This software is distributed without any warranty.
11 */
12 
13 
14 #include "chatstatefilter.h"
15 #include "chatstatehandler.h"
16 #include "messageeventhandler.h"
17 #include "messagesession.h"
18 #include "message.h"
19 #include "chatstate.h"
20 
21 namespace gloox
22 {
23 
25  : MessageFilter( parent ), m_chatStateHandler( 0 ), m_lastSent( ChatStateGone ),
26  m_enableChatStates( true )
27  {
28  }
29 
31  {
32  }
33 
35  {
37  {
38  const ChatState* state = msg.findExtension<ChatState>( ExtChatState );
39 
40  if( !state )
41  return;
42  m_enableChatStates = ( state->state() != ChatStateInvalid );
43 
44  if( m_enableChatStates && msg.body().empty() )
45  m_chatStateHandler->handleChatState( msg.from(), state->state() );
46  }
47  }
48 
50  {
51  if( !m_enableChatStates || state == m_lastSent || state == ChatStateInvalid )
52  return;
53 
54  Message m( Message::Chat, m_parent->target() );
55  m.addExtension( new ChatState( state ) );
56 
57  m_lastSent = state;
58 
59  send( m );
60  }
61 
63  {
64  if( m_enableChatStates )
66  }
67 
68 }
virtual void decorate(Message &msg)
const StanzaExtension * findExtension(int type) const
Definition: stanza.cpp:57
An abstraction of a message session between any two entities.
void addExtension(const StanzaExtension *se)
Definition: stanza.cpp:52
virtual void handleChatState(const JID &from, ChatStateType state)=0
An implementation of Chat State Notifications (XEP-0085) as a StanzaExtension.
Definition: chatstate.h:33
const std::string body(const std::string &lang="default") const
Definition: message.h:87
An abstraction of a message stanza.
Definition: message.h:33
virtual void filter(Message &msg)
The namespace for the gloox library.
Definition: adhoc.cpp:27
ChatStateType m_lastSent
void setChatState(ChatStateType state)
ChatStateHandler * m_chatStateHandler
const JID & from() const
Definition: stanza.h:51
ChatStateType
Definition: gloox.h:1104
ChatStateType state() const
Definition: chatstate.h:60
Virtual base class for message filters.
Definition: messagefilter.h:37
ChatStateFilter(MessageSession *parent)
const JID & target() const