chatstate.cpp
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013 #include "chatstate.h"
00014 #include "tag.h"
00015 #include "util.h"
00016
00017 namespace gloox
00018 {
00019
00020
00021 static const char* stateValues [] = {
00022 "active",
00023 "composing",
00024 "paused",
00025 "inactive",
00026 "gone"
00027 };
00028
00029 static inline ChatStateType chatStateType( const std::string& type )
00030 {
00031 return (ChatStateType)util::lookup2( type, stateValues );
00032 }
00033
00034 ChatState::ChatState( const Tag* tag )
00035 : StanzaExtension( ExtChatState )
00036 {
00037 if( tag )
00038 m_state = chatStateType( tag->name() );
00039 }
00040
00041 const std::string& ChatState::filterString() const
00042 {
00043 static const std::string filter =
00044 "/message/active[@xmlns='" + XMLNS_CHAT_STATES + "']"
00045 "|/message/composing[@xmlns='" + XMLNS_CHAT_STATES + "']"
00046 "|/message/paused[@xmlns='" + XMLNS_CHAT_STATES + "']"
00047 "|/message/inactive[@xmlns='" + XMLNS_CHAT_STATES + "']"
00048 "|/message/gone[@xmlns='" + XMLNS_CHAT_STATES + "']";
00049 return filter;
00050 }
00051
00052 Tag* ChatState::tag() const
00053 {
00054 if( m_state == ChatStateInvalid )
00055 return 0;
00056
00057 return new Tag( util::lookup2( m_state, stateValues ), XMLNS, XMLNS_CHAT_STATES );
00058 }
00059
00060 }