14 #include "clientbase.h"
15 #include "rostermanager.h"
17 #include "rosteritem.h"
18 #include "rosteritemdata.h"
19 #include "rosterlistener.h"
20 #include "privatexml.h"
22 #include "stanzaextension.h"
23 #include "capabilities.h"
30 RosterManager::Query::Query(
const JID& jid,
const std::string& name,
const StringList& groups )
33 m_roster.push_back(
new RosterItemData( jid, name, groups ) );
36 RosterManager::Query::Query(
const JID& jid )
39 m_roster.push_back(
new RosterItemData( jid ) );
42 RosterManager::Query::Query(
const Tag* tag )
45 if( !tag || tag->name() !=
"query" || tag->xmlns() !=
XMLNS_ROSTER )
48 const ConstTagList& l = tag->findTagList(
"query/item" );
49 ConstTagList::const_iterator it = l.begin();
50 for( ; it != l.end(); ++it )
53 const ConstTagList& g = (*it)->findTagList(
"item/group" );
54 ConstTagList::const_iterator it_g = g.begin();
55 for( ; it_g != g.end(); ++it_g )
56 groups.push_back( (*it_g)->cdata() );
58 const std::string sub = (*it)->findAttribute(
"subscription" );
60 m_roster.push_back(
new RosterItemData( JID( (*it)->findAttribute(
"jid" ) ) ) );
63 RosterItemData* rid =
new RosterItemData( JID( (*it)->findAttribute(
"jid" ) ),
64 (*it)->findAttribute(
"name" ),
66 rid->setSubscription( sub, (*it)->findAttribute(
"ask" ) );
67 m_roster.push_back( rid );
72 RosterManager::Query::~Query()
77 const std::string& RosterManager::Query::filterString()
const
79 static const std::string filter =
"/iq/query[@xmlns='" +
XMLNS_ROSTER +
"']";
83 Tag* RosterManager::Query::tag()
const
85 Tag* t =
new Tag(
"query" );
88 RosterData::const_iterator it = m_roster.begin();
89 for( ; it != m_roster.end(); ++it )
90 t->addChild( (*it)->tag() );
95 StanzaExtension* RosterManager::Query::clone()
const
97 Query* q =
new Query();
98 RosterData::const_iterator it = m_roster.begin();
99 for( ; it != m_roster.end(); ++it )
101 q->m_roster.push_back(
new RosterItemData( *(*it) ) );
109 : m_rosterListener( 0 ), m_parent( parent ), m_privateXML( 0 ),
110 m_syncSubscribeReq( false )
154 m_parent->
send( iq,
this, RequestRoster );
164 if( q && q->roster().size() )
165 mergePush( q->roster() );
168 m_parent->
send( re );
178 mergeRoster( q->roster() );
180 if( context == RequestRoster )
183 m_parent->rosterFilled();
185 if( m_rosterListener )
191 if( context == RequestRoster && m_parent )
192 m_parent->rosterFilled();
194 if( m_rosterListener )
205 Roster::iterator it = m_roster.find( presence.
from().
bare() );
206 if( it != m_roster.end() || (
self = ( presence.
from().
bareJID() == m_self->
jidJID() ) ) )
208 RosterItem* ri =
self ? m_self : (*it).second;
209 const std::string& resource = presence.
from().
resource();
221 if( m_rosterListener && !
self )
224 else if( m_rosterListener &&
self )
230 if( m_rosterListener )
236 const StringList& groups,
const std::string& msg )
241 add( jid, name, groups );
256 m_parent->
send( iq,
this, AddRosterItem );
279 m_parent->
send( iq,
this, RemoveRosterItem );
284 Roster::const_iterator it = m_roster.begin();
285 for( ; it != m_roster.end(); ++it )
287 if( !(*it).second->changed() )
291 iq.
addExtension(
new Query( (*it).second->jidJID(), (*it).second->name(), (*it).second->groups() ) );
292 m_parent->
send( iq,
this, SynchronizeRoster );
305 if( !m_rosterListener )
313 if( m_syncSubscribeReq )
331 if( m_syncSubscribeReq && answer )
349 m_syncSubscribeReq = syncSubscribeReq;
350 m_rosterListener = rl;
355 m_syncSubscribeReq =
false;
356 m_rosterListener = 0;
362 Tag* t =
new Tag(
"roster", m_delimiter );
370 m_delimiter = xml->
cdata();
379 Roster::const_iterator it = m_roster.find( jid.
bare() );
380 return it != m_roster.end() ? (*it).second : 0;
383 void RosterManager::mergePush(
const RosterData& data )
385 RosterData::const_iterator it = data.begin();
386 for( ; it != data.end(); ++it )
388 Roster::iterator itr = m_roster.find( (*it)->jidJID().full() );
389 if( itr != m_roster.end() )
391 if( (*it)->remove() )
393 if( m_rosterListener )
395 delete (*itr).second;
396 m_roster.erase( itr );
400 (*itr).second->setData( *(*it) );
401 if( m_rosterListener )
405 else if( !(*it)->remove() )
407 m_roster.insert( std::make_pair( (*it)->jidJID().full(),
new RosterItem( *(*it) ) ) );
408 if( m_rosterListener )
414 void RosterManager::mergeRoster(
const RosterData& data )
416 RosterData::const_iterator it = data.begin();
417 for( ; it != data.end(); ++it )
418 m_roster.insert( std::make_pair( (*it)->jidJID().full(),
new RosterItem( *(*it) ) ) );