gloox 1.0
|
00001 /* 00002 Copyright (c) 2005-2009 by Jakob Schroeter <js@camaya.net> 00003 This file is part of the gloox library. http://camaya.net/gloox 00004 00005 This software is distributed under a license. The full license 00006 agreement can be found in the file LICENSE in this distribution. 00007 This software may not be copied, modified, sold or distributed 00008 other than expressed in the named license agreement. 00009 00010 This software is distributed without any warranty. 00011 */ 00012 00013 #include "messageevent.h" 00014 #include "tag.h" 00015 #include "util.h" 00016 00017 namespace gloox 00018 { 00019 00020 /* chat state type values */ 00021 static const char* eventValues [] = { 00022 "offline", 00023 "delivered", 00024 "displayed", 00025 "composing" 00026 }; 00027 00028 MessageEvent::MessageEvent( const Tag* tag ) 00029 : StanzaExtension( ExtMessageEvent ), m_event( MessageEventCancel ) 00030 { 00031 const TagList& l = tag->children(); 00032 TagList::const_iterator it = l.begin(); 00033 int event = 0; 00034 for( ; it != l.end(); ++it ) 00035 event |= util::lookup2( (*it)->name(), eventValues ); 00036 if( event ) 00037 m_event = event; 00038 } 00039 00040 const std::string& MessageEvent::filterString() const 00041 { 00042 static const std::string filter = "/message/x[@xmlns='" + XMLNS_X_EVENT + "']"; 00043 return filter; 00044 } 00045 00046 Tag* MessageEvent::tag() const 00047 { 00048 Tag* x = new Tag( "x", XMLNS, XMLNS_X_EVENT ); 00049 00050 if( m_event & MessageEventOffline ) 00051 new Tag( x, "offline" ); 00052 if( m_event & MessageEventDelivered ) 00053 new Tag( x, "delivered" ); 00054 if( m_event & MessageEventDisplayed ) 00055 new Tag( x, "displayed" ); 00056 if( m_event & MessageEventComposing ) 00057 new Tag( x, "composing" ); 00058 00059 if( !m_id.empty() ) 00060 new Tag( x, "id", m_id ); 00061 00062 return x; 00063 } 00064 00065 }