gloox
1.0.1
Main Page
Related Pages
Namespaces
Classes
Files
File List
src
chatstatefilter.cpp
1
/*
2
Copyright (c) 2005-2012 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
24
ChatStateFilter::ChatStateFilter
(
MessageSession
* parent )
25
:
MessageFilter
( parent ), m_chatStateHandler( 0 ), m_lastSent(
ChatStateGone
),
26
m_enableChatStates( true )
27
{
28
}
29
30
ChatStateFilter::~ChatStateFilter
()
31
{
32
}
33
34
void
ChatStateFilter::filter
(
Message
& msg )
35
{
36
if
(
m_enableChatStates
&&
m_chatStateHandler
)
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
46
void
ChatStateFilter::setChatState
(
ChatStateType
state )
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
59
void
ChatStateFilter::decorate
(
Message
& msg )
60
{
61
if
(
m_enableChatStates
)
62
msg.
addExtension
(
new
ChatState
(
ChatStateActive
) );
63
}
64
65
}
Generated on Sun Jun 30 2013 14:37:36 for gloox by
1.8.1.2