All Downloads are FREE. Search and download functionalities are using the official Maven repository.

uk.org.retep.xmpp.muc.logic.MemberQueryLogic Maven / Gradle / Ivy

The newest version!
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package uk.org.retep.xmpp.muc.logic;

import java.util.List;
import org.jabber.protocol.muc_admin.Item;
import org.jabber.protocol.muc_admin.ItemBuilder;
import org.jabber.protocol.muc_admin.Query;
import org.jabber.protocol.muc_admin.QueryBuilder;
import uk.org.retep.util.messaging.MessageException;
import uk.org.retep.xmpp.XMPPServer;
import uk.org.retep.xmpp.logic.AbstractXMPPLogic;
import uk.org.retep.xmpp.logic.XMPPLogic;
import uk.org.retep.xmpp.logic.XMPPProtocolLogic;
import uk.org.retep.xmpp.message.Iq;
import uk.org.retep.xmpp.muc.MucRoom;
import uk.org.retep.xmpp.muc.MucRoomMember;
import uk.org.retep.xmpp.muc.MucService;
import uk.org.retep.xmpp.util.Affiliation;
import uk.org.retep.xmpp.util.Role;

/**
 * XEP-0045 9 Admin Use Cases
 *
 * @author peter
 */
public class MemberQueryLogic
        extends AbstractXMPPLogic
        implements XMPPProtocolLogic
{

    @Override
    public Class getProtocol()
    {
        return Query.class;
    }

    @Override
    public  XMPPLogic process( final XMPPServer server,
                                  final MucService service,
                                  final MucRoom room,
                                  final Iq iq )
            throws MessageException
    {
        // Where to place the results
        final QueryBuilder result = new QueryBuilder();

        // Get the item for the query
        List items = ((Query) iq.getContent()).getItem();
        // FIXME spec says only one, check with techreview team to see if this can be multiple
        if( items.size() == 1 )
        {
            final Item queryItem = items.get( 0 );
            final Affiliation qAff = queryItem.getAffiliation();

            for( MucRoomMember member : room.getMembers() )
            {
                final Affiliation memAff = member.getAffiliation();
                if( qAff != null && qAff.isChildOf( memAff ) )
                {
                    final Role memRole = member.getRole();
                    result.addItem( new ItemBuilder().//
                            setAffiliation( memAff.cloneBuilder() ).
                            setRole( memRole==null?null:memRole.cloneBuilder() ).
                            setJid( member.getJID().cloneBuilder()).
                            setNick( member.getNickname() ) );
                }
            }
        }

        server.send( iq.respondTo().setContent( result ) );

        return null;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy