gloox  1.1-svn
chatstatefilter.cpp
1 /*
2  Copyright (c) 2005-2009 by Jakob Schroeter <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  m_enableChatStates = state && state->state() != ChatStateInvalid;
41  if( m_enableChatStates && msg.body().empty() )
42  m_chatStateHandler->handleChatState( msg.from(), state->state() );
43  }
44  }
45 
47  {
48  if( !m_enableChatStates || state == m_lastSent || state == ChatStateInvalid )
49  return;
50 
51  Message m( Message::Chat, m_parent->target() );
52  m.addExtension( new ChatState( state ) );
53 
54  m_lastSent = state;
55 
56  send( m );
57  }
58 
60  {
61  if( m_enableChatStates )
63  }
64 
65 }