gloox  1.0.27
messageevent.cpp
1 /*
2  Copyright (c) 2005-2023 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  /* message event type values */
21  static const char* eventValues [] = {
22  "offline",
23  "delivered",
24  "displayed",
25  "composing"
26  };
27 
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 
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 }
MessageEvent(const Tag *tag)
virtual const std::string & filterString() const
int event() const
Definition: messageevent.h:60
Tag * tag() const
This class abstracts a stanza extension, which is usually an XML child element in a specific namespac...
This is an abstraction of an XML element.
Definition: tag.h:47
const TagList & children() const
Definition: tag.cpp:510
The namespace for the gloox library.
Definition: adhoc.cpp:28
std::list< Tag * > TagList
Definition: tag.h:26
const std::string XMLNS_X_EVENT
Definition: gloox.cpp:50
@ MessageEventComposing
Definition: gloox.h:1096
@ MessageEventCancel
Definition: gloox.h:1098
@ MessageEventDisplayed
Definition: gloox.h:1095
@ MessageEventOffline
Definition: gloox.h:1091
@ MessageEventDelivered
Definition: gloox.h:1093
const std::string XMLNS
Definition: gloox.cpp:122
@ ExtMessageEvent