gloox
1.0.22
src
messageevent.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
#include "messageevent.h"
14
#include "tag.h"
15
#include "util.h"
16
17
namespace
gloox
18
{
19
20
/* chat state type values */
21
static
const
char
* eventValues [] = {
22
"offline"
,
23
"delivered"
,
24
"displayed"
,
25
"composing"
26
};
27
28
MessageEvent::MessageEvent
(
const
Tag
* tag )
29
:
StanzaExtension
(
ExtMessageEvent
), m_event(
MessageEventCancel
)
30
{
31
if
( !
tag
)
32
return
;
33
34
const
TagList
& l =
tag
->
children
();
35
TagList::const_iterator it = l.begin();
36
int
event
= 0;
37
for
( ; it != l.end(); ++it )
38
{
39
event
|= util::lookup2( (*it)->name(), eventValues );
40
if
( (*it)->name() ==
"id"
)
41
m_id = (*it)->cdata();
42
}
43
if
(
event
)
44
m_event =
event
;
45
}
46
47
const
std::string&
MessageEvent::filterString
()
const
48
{
49
static
const
std::string filter =
"/message/x[@xmlns='"
+
XMLNS_X_EVENT
+
"']"
;
50
return
filter;
51
}
52
53
Tag
*
MessageEvent::tag
()
const
54
{
55
Tag
* x =
new
Tag
(
"x"
,
XMLNS
,
XMLNS_X_EVENT
);
56
57
if
( m_event &
MessageEventOffline
)
58
new
Tag
( x,
"offline"
);
59
if
( m_event &
MessageEventDelivered
)
60
new
Tag
( x,
"delivered"
);
61
if
( m_event &
MessageEventDisplayed
)
62
new
Tag
( x,
"displayed"
);
63
if
( m_event &
MessageEventComposing
)
64
new
Tag
( x,
"composing"
);
65
66
if
( !m_id.empty() )
67
new
Tag
( x,
"id"
, m_id );
68
69
return
x;
70
}
71
72
}
gloox::XMLNS
const std::string XMLNS
Definition:
gloox.cpp:122
gloox::StanzaExtension
This class abstracts a stanza extension, which is usually an XML child element in a specific namespac...
Definition:
stanzaextension.h:203
gloox::TagList
std::list< Tag * > TagList
Definition:
tag.h:26
gloox::XMLNS_X_EVENT
const std::string XMLNS_X_EVENT
Definition:
gloox.cpp:50
gloox::MessageEventOffline
@ MessageEventOffline
Definition:
gloox.h:1091
gloox::MessageEvent::tag
Tag * tag() const
Definition:
messageevent.cpp:53
gloox::MessageEventDelivered
@ MessageEventDelivered
Definition:
gloox.h:1093
gloox::MessageEventComposing
@ MessageEventComposing
Definition:
gloox.h:1096
gloox::Tag::children
const TagList & children() const
Definition:
tag.cpp:510
gloox::MessageEvent::MessageEvent
MessageEvent(const Tag *tag)
Definition:
messageevent.cpp:28
gloox::MessageEventCancel
@ MessageEventCancel
Definition:
gloox.h:1098
gloox
The namespace for the gloox library.
Definition:
adhoc.cpp:27
gloox::Tag
This is an abstraction of an XML element.
Definition:
tag.h:46
gloox::MessageEvent::filterString
virtual const std::string & filterString() const
Definition:
messageevent.cpp:47
gloox::MessageEvent::event
int event() const
Definition:
messageevent.h:60
gloox::MessageEventDisplayed
@ MessageEventDisplayed
Definition:
gloox.h:1095
gloox::ExtMessageEvent
@ ExtMessageEvent
Definition:
stanzaextension.h:51
Generated on Tue Mar 24 2020 14:04:23 for gloox by
1.8.17