chatstate.cpp
/*
Copyright (c) 2007-2023 by Jakob Schröter <js@camaya.net>
This file is part of the gloox library. http://camaya.net/gloox
This software is distributed under a license. The full license
agreement can be found in the file LICENSE in this distribution.
This software may not be copied, modified, sold or distributed
other than expressed in the named license agreement.
This software is distributed without any warranty.
*/
#include "chatstate.h"
#include "tag.h"
#include "util.h"
namespace gloox
{
/* chat state type values */
static const char* stateValues [] = {
"active",
"composing",
"paused",
"inactive",
"gone"
};
static inline ChatStateType chatStateType( const std::string& type )
{
return static_cast<ChatStateType>( util::lookup2( type, stateValues ) );
}
ChatState::ChatState( const Tag* tag )
: StanzaExtension( ExtChatState ),
m_state( ChatStateInvalid )
{
if( tag )
m_state = chatStateType( tag->name() );
}
const std::string& ChatState::filterString() const
{
static const std::string filter =
"/message/active[@xmlns='" + XMLNS_CHAT_STATES + "']"
"|/message/composing[@xmlns='" + XMLNS_CHAT_STATES + "']"
"|/message/paused[@xmlns='" + XMLNS_CHAT_STATES + "']"
"|/message/inactive[@xmlns='" + XMLNS_CHAT_STATES + "']"
"|/message/gone[@xmlns='" + XMLNS_CHAT_STATES + "']";
return filter;
}
Tag* ChatState::tag() const
{
if( m_state == ChatStateInvalid )
return 0;
return new Tag( util::lookup2( m_state, stateValues ), XMLNS, XMLNS_CHAT_STATES );
}
}
gloox::ChatState::ChatState
ChatState(const Tag *tag)
Definition chatstate.cpp:34
gloox::ChatState::filterString
virtual const std::string & filterString() const
Definition chatstate.cpp:42
gloox::ChatState::tag
Tag * tag() const
Definition chatstate.cpp:53
gloox::StanzaExtension::StanzaExtension
StanzaExtension(int type)
Definition stanzaextension.h:211
gloox::Tag
This is an abstraction of an XML element.
Definition tag.h:47
gloox
The namespace for the gloox library.
Definition adhoc.cpp:28
gloox::ChatStateType
ChatStateType
Definition gloox.h:1105
gloox::ChatStateInvalid
@ ChatStateInvalid
Definition gloox.h:1112
gloox::XMLNS
const std::string XMLNS
Definition gloox.cpp:122
gloox::ExtChatState
@ ExtChatState
Definition stanzaextension.h:50
gloox::XMLNS_CHAT_STATES
const std::string XMLNS_CHAT_STATES
Definition gloox.cpp:30