gloox
1.0
Main Page
Related Pages
Namespaces
Classes
Files
File List
src
messageeventfilter.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 "messageeventfilter.h"
15
#include "messageeventhandler.h"
16
#include "messagesession.h"
17
#include "message.h"
18
#include "messageevent.h"
19
#include "error.h"
20
21
namespace
gloox
22
{
23
24
MessageEventFilter::MessageEventFilter
(
MessageSession
* parent )
25
:
MessageFilter
( parent ), m_messageEventHandler( 0 ), m_requestedEvents( 0 ),
26
m_lastSent(
MessageEventCancel
), m_disable( false )
27
{
28
}
29
30
MessageEventFilter::~MessageEventFilter
()
31
{
32
}
33
34
void
MessageEventFilter::filter
(
Message
& msg )
35
{
36
if
( m_disable || !m_messageEventHandler )
37
return
;
38
39
if
( msg.
subtype
() ==
Message::Error
)
40
{
41
if
( msg.
error
() && msg.
error
()->
error
() ==
StanzaErrorFeatureNotImplemented
)
42
m_disable =
true
;
43
44
return
;
45
}
46
47
const
MessageEvent
* me = msg.
findExtension
<
MessageEvent
>(
ExtMessageEvent
);
48
if
( !me )
49
{
50
m_requestedEvents = 0;
51
m_lastID =
EmptyString
;
52
return
;
53
}
54
55
if
( msg.
body
().empty() )
56
m_messageEventHandler->
handleMessageEvent
( msg.
from
(), (
MessageEventType
)me->
event
() );
57
else
58
{
59
m_lastID = msg.
id
();
60
m_requestedEvents = 0;
61
m_requestedEvents = me->
event
();
62
}
63
}
64
65
void
MessageEventFilter::raiseMessageEvent
(
MessageEventType
event )
66
{
67
if
( m_disable || ( !( m_requestedEvents & event ) && ( event !=
MessageEventCancel
) ) )
68
return
;
69
70
switch
( event )
71
{
72
case
MessageEventOffline
:
73
case
MessageEventDelivered
:
74
case
MessageEventDisplayed
:
75
m_requestedEvents &= ~event;
76
break
;
77
case
MessageEventComposing
:
78
if
( m_lastSent ==
MessageEventComposing
)
79
return
;
80
break
;
81
case
MessageEventCancel
:
82
default
:
83
break
;
84
}
85
86
m_lastSent = event;
87
Message
m(
Message::Normal
, m_parent->
target
() );
88
m.
addExtension
(
new
MessageEvent
( event, m_lastID ) );
89
send( m );
90
}
91
92
void
MessageEventFilter::decorate
(
Message
& msg )
93
{
94
if
( m_disable )
95
return
;
96
97
msg.
addExtension
(
new
MessageEvent
(
MessageEventOffline
|
MessageEventDelivered
|
98
MessageEventDisplayed
|
MessageEventComposing
) );
99
m_lastSent =
MessageEventCancel
;
100
}
101
102
void
MessageEventFilter::registerMessageEventHandler
(
MessageEventHandler
* meh )
103
{
104
m_messageEventHandler = meh;
105
}
106
107
void
MessageEventFilter::removeMessageEventHandler
()
108
{
109
m_messageEventHandler = 0;
110
}
111
112
}
Generated on Thu Jun 27 2013 13:02:36 for gloox by
1.8.1.2