gloox  1.0.28
chatstate.cpp
1 /*
2  Copyright (c) 2007-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 "chatstate.h"
14 #include "tag.h"
15 #include "util.h"
16 
17 namespace gloox
18 {
19 
20  /* chat state type values */
21  static const char* stateValues [] = {
22  "active",
23  "composing",
24  "paused",
25  "inactive",
26  "gone"
27  };
28 
29  static inline ChatStateType chatStateType( const std::string& type )
30  {
31  return static_cast<ChatStateType>( util::lookup2( type, stateValues ) );
32  }
33 
34  ChatState::ChatState( const Tag* tag )
36  m_state( ChatStateInvalid )
37  {
38  if( tag )
39  m_state = chatStateType( tag->name() );
40  }
41 
42  const std::string& ChatState::filterString() const
43  {
44  static const std::string filter =
45  "/message/active[@xmlns='" + XMLNS_CHAT_STATES + "']"
46  "|/message/composing[@xmlns='" + XMLNS_CHAT_STATES + "']"
47  "|/message/paused[@xmlns='" + XMLNS_CHAT_STATES + "']"
48  "|/message/inactive[@xmlns='" + XMLNS_CHAT_STATES + "']"
49  "|/message/gone[@xmlns='" + XMLNS_CHAT_STATES + "']";
50  return filter;
51  }
52 
54  {
55  if( m_state == ChatStateInvalid )
56  return 0;
57 
58  return new Tag( util::lookup2( m_state, stateValues ), XMLNS, XMLNS_CHAT_STATES );
59  }
60 
61 }
ChatState(const Tag *tag)
Definition: chatstate.cpp:34
virtual const std::string & filterString() const
Definition: chatstate.cpp:42
Tag * tag() const
Definition: chatstate.cpp:53
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 std::string & name() const
Definition: tag.h:394
The namespace for the gloox library.
Definition: adhoc.cpp:28
ChatStateType
Definition: gloox.h:1105
@ ChatStateInvalid
Definition: gloox.h:1112
const std::string XMLNS
Definition: gloox.cpp:122
@ ExtChatState
const std::string XMLNS_CHAT_STATES
Definition: gloox.cpp:30