Search in sources :

Example 6 with MUCAdmin

use of org.jivesoftware.smackx.packet.MUCAdmin in project ecf by eclipse.

the class MultiUserChat method changeAffiliationByAdmin.

/**
 * Tries to change the affiliation with an 'muc#admin' namespace
 *
 * @param jid
 * @param affiliation
 * @param reason the reason for the affiliation change (optional)
 * @throws XMPPException
 */
private void changeAffiliationByAdmin(String jid, String affiliation, String reason) throws XMPPException {
    MUCAdmin iq = new MUCAdmin();
    iq.setTo(room);
    iq.setType(IQ.Type.SET);
    // Set the new affiliation.
    MUCAdmin.Item item = new MUCAdmin.Item(affiliation, null);
    item.setJid(jid);
    item.setReason(reason);
    iq.addItem(item);
    // Wait for a response packet back from the server.
    PacketFilter responseFilter = new PacketIDFilter(iq.getPacketID());
    PacketCollector response = connection.createPacketCollector(responseFilter);
    // Send the change request to the server.
    connection.sendPacket(iq);
    // Wait up to a certain number of seconds for a reply.
    IQ answer = (IQ) response.nextResult(SmackConfiguration.getPacketReplyTimeout());
    // Stop queuing results
    response.cancel();
    if (answer == null) {
        throw new XMPPException("No response from server.");
    } else if (answer.getError() != null) {
        throw new XMPPException(answer.getError());
    }
}
Also used : PacketFilter(org.jivesoftware.smack.filter.PacketFilter) MUCAdmin(org.jivesoftware.smackx.packet.MUCAdmin) PacketCollector(org.jivesoftware.smack.PacketCollector) IQ(org.jivesoftware.smack.packet.IQ) XMPPException(org.jivesoftware.smack.XMPPException) PacketIDFilter(org.jivesoftware.smack.filter.PacketIDFilter)

Example 7 with MUCAdmin

use of org.jivesoftware.smackx.packet.MUCAdmin in project ecf by eclipse.

the class MUCAdminProvider method parseIQ.

public IQ parseIQ(XmlPullParser parser) throws Exception {
    MUCAdmin mucAdmin = new MUCAdmin();
    boolean done = false;
    while (!done) {
        int eventType = parser.next();
        if (eventType == XmlPullParser.START_TAG) {
            if (parser.getName().equals("item")) {
                mucAdmin.addItem(parseItem(parser));
            }
        } else if (eventType == XmlPullParser.END_TAG) {
            if (parser.getName().equals("query")) {
                done = true;
            }
        }
    }
    return mucAdmin;
}
Also used : MUCAdmin(org.jivesoftware.smackx.packet.MUCAdmin)

Aggregations

MUCAdmin (org.jivesoftware.smackx.packet.MUCAdmin)7 PacketCollector (org.jivesoftware.smack.PacketCollector)6 XMPPException (org.jivesoftware.smack.XMPPException)6 PacketFilter (org.jivesoftware.smack.filter.PacketFilter)6 PacketIDFilter (org.jivesoftware.smack.filter.PacketIDFilter)6 IQ (org.jivesoftware.smack.packet.IQ)4 ArrayList (java.util.ArrayList)2