messageevent.cpp
/*
Copyright (c) 2005-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 "messageevent.h"
#include "tag.h"
#include "util.h"
namespace gloox
{
/* message event type values */
static const char* eventValues [] = {
"offline",
"delivered",
"displayed",
"composing"
};
MessageEvent::MessageEvent( const Tag* tag )
: StanzaExtension( ExtMessageEvent ), m_event( MessageEventCancel )
{
if( !tag )
return;
const TagList& l = tag->children();
TagList::const_iterator it = l.begin();
int event = 0;
for( ; it != l.end(); ++it )
{
event |= util::lookup2( (*it)->name(), eventValues );
if( (*it)->name() == "id" )
m_id = (*it)->cdata();
}
if( event )
m_event = event;
}
const std::string& MessageEvent::filterString() const
{
static const std::string filter = "/message/x[@xmlns='" + XMLNS_X_EVENT + "']";
return filter;
}
Tag* MessageEvent::tag() const
{
Tag* x = new Tag( "x", XMLNS, XMLNS_X_EVENT );
if( m_event & MessageEventOffline )
new Tag( x, "offline" );
if( m_event & MessageEventDelivered )
new Tag( x, "delivered" );
if( m_event & MessageEventDisplayed )
new Tag( x, "displayed" );
if( m_event & MessageEventComposing )
new Tag( x, "composing" );
if( !m_id.empty() )
new Tag( x, "id", m_id );
return x;
}
}
gloox::MessageEvent::MessageEvent
MessageEvent(const Tag *tag)
Definition messageevent.cpp:28
gloox::MessageEvent::filterString
virtual const std::string & filterString() const
Definition messageevent.cpp:47
gloox::MessageEvent::event
int event() const
Definition messageevent.h:60
gloox::MessageEvent::tag
Tag * tag() const
Definition messageevent.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::TagList
std::list< Tag * > TagList
Definition tag.h:31
gloox::XMLNS_X_EVENT
const std::string XMLNS_X_EVENT
Definition gloox.cpp:50
gloox::MessageEventComposing
@ MessageEventComposing
Definition gloox.h:1096
gloox::MessageEventCancel
@ MessageEventCancel
Definition gloox.h:1098
gloox::MessageEventDisplayed
@ MessageEventDisplayed
Definition gloox.h:1095
gloox::MessageEventOffline
@ MessageEventOffline
Definition gloox.h:1091
gloox::MessageEventDelivered
@ MessageEventDelivered
Definition gloox.h:1093
gloox::XMLNS
const std::string XMLNS
Definition gloox.cpp:122
gloox::ExtMessageEvent
@ ExtMessageEvent
Definition stanzaextension.h:51