gloox  1.0.22
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 }
gloox::ChatStateFilter::ChatStateFilter
ChatStateFilter(MessageSession *parent)
Definition: chatstatefilter.cpp:24
gloox::ExtChatState
@ ExtChatState
Definition: stanzaextension.h:50
gloox::Message
An abstraction of a message stanza.
Definition: message.h:34
gloox::ChatStateInvalid
@ ChatStateInvalid
Definition: gloox.h:1112
gloox::ChatStateType
ChatStateType
Definition: gloox.h:1105
gloox::Stanza::addExtension
void addExtension(const StanzaExtension *se)
Definition: stanza.cpp:52
gloox::Stanza::findExtension
const StanzaExtension * findExtension(int type) const
Definition: stanza.cpp:57
gloox::ChatStateFilter::~ChatStateFilter
virtual ~ChatStateFilter()
Definition: chatstatefilter.cpp:30
gloox::ChatStateFilter::setChatState
void setChatState(ChatStateType state)
Definition: chatstatefilter.cpp:49
gloox::ChatState
An implementation of Chat State Notifications (XEP-0085) as a StanzaExtension.
Definition: chatstate.h:34
gloox::MessageFilter
Virtual base class for message filters.
Definition: messagefilter.h:38
gloox::MessageSession
An abstraction of a message session between any two entities.
Definition: messagesession.h:146
gloox::Stanza::from
const JID & from() const
Definition: stanza.h:51
gloox::Message::Chat
@ Chat
Definition: message.h:46
gloox::ChatStateFilter::filter
virtual void filter(Message &msg)
Definition: chatstatefilter.cpp:34
gloox::ChatStateHandler::handleChatState
virtual void handleChatState(const JID &from, ChatStateType state)=0
gloox::ChatStateFilter::m_lastSent
ChatStateType m_lastSent
Definition: chatstatefilter.h:96
gloox::ChatStateFilter::m_enableChatStates
bool m_enableChatStates
Definition: chatstatefilter.h:99
gloox
The namespace for the gloox library.
Definition: adhoc.cpp:28
gloox::ChatStateFilter::m_chatStateHandler
ChatStateHandler * m_chatStateHandler
Definition: chatstatefilter.h:93
gloox::ChatStateActive
@ ChatStateActive
Definition: gloox.h:1106
gloox::Message::body
const std::string body(const std::string &lang="default") const
Definition: message.h:87
gloox::ChatStateFilter::decorate
virtual void decorate(Message &msg)
Definition: chatstatefilter.cpp:62
gloox::ChatStateGone
@ ChatStateGone
Definition: gloox.h:1110
gloox::ChatState::state
ChatStateType state() const
Definition: chatstate.h:60
gloox::MessageSession::target
const JID & target() const
Definition: messagesession.h:183