powered by Jive Software

2 fixes that solve poblem if user is in several Groups in Roster

Without this fix people that are in several groups they only appear in the first group and not in all groups: Search for Guido and you see the changes

Class Roster.as

methods:

private function fetchRoster_result( resultIQ:IQ ):Void

{

// Clear out the old roster

rosterItems.removeAll();

// Go through the result IQ and add each item

var ext:RosterExtension = resultIQ.getAllExtensionsByNS( RosterExtension.NS )[0];

var newItems = ext.getAllItems();

for( var i=0; i < newItems.length; i++ ) {

var item = newItems+;

//if a user is in several groups, add it as item for each group. fix by Guido

for( var j=0; j < item.getGroups().length; j++){

addRosterItem( item.jid, item.name, RosterExtension.SHOW_UNAVAILABLE, “Offline”, item.getGroups()[j], item.subscription.toLowerCase() );

}

}

}


private function handlePresence( aPresence:Presence ):Void

{

// Handle based on the type of the presence received

switch( aPresence.type.toLowerCase() )

{

case Presence.SUBSCRIBE_TYPE:

var eventObj:Object = {target:this, type:“subscriptionRequest”, jid:aPresence.from};

dispatchEvent( eventObj );

break;

case Presence.UNSUBSCRIBED_TYPE:

var eventObj:Object = ;

dispatchEvent( eventObj );

break;

case Presence.UNAVAILABLE_TYPE:

var eventObj:Object = ;

dispatchEvent( eventObj );

var l = rosterItems.getLength !== undefined ? rosterItems.getLength() : rosterItems.length;

for( var i = 0; i < l; i++ ) {

var r = rosterItems.getItemAt( i );

if( r.jid.toLowerCase() == aPresence.from.split("/")[0].toLowerCase() ) {

r.show = RosterExtension.SHOW_UNAVAILABLE;

rosterItems.replaceItemAt( i, r );

break;

}

}

break;

// AVAILABLE is the default type, so undefined is also possible

case Presence.AVAILABLE_TYPE:

case undefined:

var eventObj:Object = ;

dispatchEvent( eventObj );

// Change the item on the roster

var l = rosterItems.getLength !== undefined ? rosterItems.getLength() : rosterItems.length;

for( var i = 0; i < l; i++ ) {

if( rosterItems.getItemAt( i ).jid.toLowerCase() == aPresence.from.split("/")[0].toLowerCase() ) {

updateRosterItemPresence( i, aPresence );

trace("roster item: "+rosterItems.getItemAt( i ).jid.toLowerCase());

//removed break, because if user is in several groups only one item gets updated. Bug fix by guido

//break;

}

}

break;

}

}

1 Like

Thanks for posting the fix - multiple group support was just one of those things I never got around to properly implementing. We’'ll definitely want to integrate this feature in the codebase.