gloox  1.0.28
chatstatefilter.cpp
1 /*
2  Copyright (c) 2005-2023 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 }
void setChatState(ChatStateType state)
virtual void decorate(Message &msg)
ChatStateFilter(MessageSession *parent)
ChatStateType m_lastSent
virtual void filter(Message &msg)
ChatStateHandler * m_chatStateHandler
virtual void handleChatState(const JID &from, ChatStateType state)=0
An implementation of Chat State Notifications (XEP-0085) as a StanzaExtension.
Definition: chatstate.h:34
ChatStateType state() const
Definition: chatstate.h:60
Virtual base class for message filters.
Definition: messagefilter.h:38
An abstraction of a message session between any two entities.
const JID & target() const
An abstraction of a message stanza.
Definition: message.h:34
const std::string body(const std::string &lang="default") const
Definition: message.h:87
void addExtension(const StanzaExtension *se)
Definition: stanza.cpp:52
const JID & from() const
Definition: stanza.h:51
const StanzaExtension * findExtension(int type) const
Definition: stanza.cpp:57
The namespace for the gloox library.
Definition: adhoc.cpp:28
ChatStateType
Definition: gloox.h:1105
@ ChatStateInvalid
Definition: gloox.h:1112
@ ChatStateActive
Definition: gloox.h:1106
@ ChatStateGone
Definition: gloox.h:1110
@ ExtChatState