Search in sources :

Example 6 with MUCAdmin

use of org.jivesoftware.smackx.muc.packet.MUCAdmin in project Smack by igniterealtime.

the class MUCAdminProvider method parse.

@Override
public MUCAdmin parse(XmlPullParser parser, int initialDepth, XmlEnvironment xmlEnvironment) throws XmlPullParserException, IOException {
    MUCAdmin mucAdmin = new MUCAdmin();
    boolean done = false;
    while (!done) {
        XmlPullParser.Event eventType = parser.next();
        if (eventType == XmlPullParser.Event.START_ELEMENT) {
            if (parser.getName().equals("item")) {
                mucAdmin.addItem(MUCParserUtils.parseItem(parser));
            }
        } else if (eventType == XmlPullParser.Event.END_ELEMENT) {
            if (parser.getName().equals("query")) {
                done = true;
            }
        }
    }
    return mucAdmin;
}
Also used : MUCAdmin(org.jivesoftware.smackx.muc.packet.MUCAdmin) XmlPullParser(org.jivesoftware.smack.xml.XmlPullParser)

Example 7 with MUCAdmin

use of org.jivesoftware.smackx.muc.packet.MUCAdmin in project Smack by igniterealtime.

the class MultiUserChat method getOccupants.

/**
 * Returns a list of <code>Occupant</code> that have the specified room role.
 *
 * @param role the role of the occupant in the room.
 * @return a list of <code>Occupant</code> that have the specified room role.
 * @throws XMPPErrorException if an error occurred while performing the request to the server or you
 *         don't have enough privileges to get this information.
 * @throws NoResponseException if there was no response from the server.
 * @throws NotConnectedException if the XMPP connection is not connected.
 * @throws InterruptedException if the calling thread was interrupted.
 */
private List<Occupant> getOccupants(MUCRole role) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
    MUCAdmin iq = new MUCAdmin();
    iq.setTo(room);
    iq.setType(IQ.Type.get);
    // Set the specified role. This may request the list of moderators/participants.
    MUCItem item = new MUCItem(role);
    iq.addItem(item);
    MUCAdmin answer = (MUCAdmin) connection.sendIqRequestAndWaitForResponse(iq);
    // Get the list of participants from the server's answer
    List<Occupant> participants = new ArrayList<Occupant>();
    for (MUCItem mucadminItem : answer.getItems()) {
        participants.add(new Occupant(mucadminItem));
    }
    return participants;
}
Also used : MUCItem(org.jivesoftware.smackx.muc.packet.MUCItem) MUCAdmin(org.jivesoftware.smackx.muc.packet.MUCAdmin) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) ArrayList(java.util.ArrayList)

Example 8 with MUCAdmin

use of org.jivesoftware.smackx.muc.packet.MUCAdmin in project Smack by igniterealtime.

the class MultiUserChat method changeRole.

private void changeRole(Collection<Resourcepart> nicknames, MUCRole role) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
    MUCAdmin iq = new MUCAdmin();
    iq.setTo(room);
    iq.setType(IQ.Type.set);
    for (Resourcepart nickname : nicknames) {
        // Set the new role.
        MUCItem item = new MUCItem(role, nickname);
        iq.addItem(item);
    }
    connection.sendIqRequestAndWaitForResponse(iq);
}
Also used : MUCItem(org.jivesoftware.smackx.muc.packet.MUCItem) MUCAdmin(org.jivesoftware.smackx.muc.packet.MUCAdmin) Resourcepart(org.jxmpp.jid.parts.Resourcepart)

Aggregations

MUCAdmin (org.jivesoftware.smackx.muc.packet.MUCAdmin)8 MUCItem (org.jivesoftware.smackx.muc.packet.MUCItem)6 ArrayList (java.util.ArrayList)2 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)2 XmlPullParser (org.jivesoftware.smack.xml.XmlPullParser)1 DomainBareJid (org.jxmpp.jid.DomainBareJid)1 EntityBareJid (org.jxmpp.jid.EntityBareJid)1 EntityFullJid (org.jxmpp.jid.EntityFullJid)1 EntityJid (org.jxmpp.jid.EntityJid)1 Jid (org.jxmpp.jid.Jid)1 Resourcepart (org.jxmpp.jid.parts.Resourcepart)1