Search in sources :

Example 6 with PacketIDFilter

use of org.jivesoftware.smack.filter.PacketIDFilter in project ecf by eclipse.

the class MultiUserChat method changeRole.

private void changeRole(Collection<String> nicknames, String role) throws XMPPException {
    MUCAdmin iq = new MUCAdmin();
    iq.setTo(room);
    iq.setType(IQ.Type.SET);
    for (String nickname : nicknames) {
        // Set the new role.
        MUCAdmin.Item item = new MUCAdmin.Item(null, role);
        item.setNick(nickname);
        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 PacketIDFilter

use of org.jivesoftware.smack.filter.PacketIDFilter in project ecf by eclipse.

the class MultiUserChat method changeAffiliationByOwner.

private void changeAffiliationByOwner(Collection<String> jids, String affiliation) throws XMPPException {
    MUCOwner iq = new MUCOwner();
    iq.setTo(room);
    iq.setType(IQ.Type.SET);
    for (String jid : jids) {
        // Set the new affiliation.
        MUCOwner.Item item = new MUCOwner.Item(affiliation);
        item.setJid(jid);
        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) PacketCollector(org.jivesoftware.smack.PacketCollector) IQ(org.jivesoftware.smack.packet.IQ) MUCOwner(org.jivesoftware.smackx.packet.MUCOwner) XMPPException(org.jivesoftware.smack.XMPPException) PacketIDFilter(org.jivesoftware.smack.filter.PacketIDFilter)

Example 8 with PacketIDFilter

use of org.jivesoftware.smack.filter.PacketIDFilter in project ecf by eclipse.

the class MultiUserChat method getConfigurationForm.

/**
 * Returns the room's configuration form that the room's owner can use or <tt>null</tt> if
 * no configuration is possible. The configuration form allows to set the room's language,
 * enable logging, specify room's type, etc..
 *
 * @return the Form that contains the fields to complete together with the instrucions or
 * <tt>null</tt> if no configuration is possible.
 * @throws XMPPException if an error occurs asking the configuration form for the room.
 */
public Form getConfigurationForm() throws XMPPException {
    MUCOwner iq = new MUCOwner();
    iq.setTo(room);
    iq.setType(IQ.Type.GET);
    // Filter packets looking for an answer from the server.
    PacketFilter responseFilter = new PacketIDFilter(iq.getPacketID());
    PacketCollector response = connection.createPacketCollector(responseFilter);
    // Request the configuration form 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());
    }
    return Form.getFormFrom(answer);
}
Also used : PacketFilter(org.jivesoftware.smack.filter.PacketFilter) PacketCollector(org.jivesoftware.smack.PacketCollector) IQ(org.jivesoftware.smack.packet.IQ) MUCOwner(org.jivesoftware.smackx.packet.MUCOwner) XMPPException(org.jivesoftware.smack.XMPPException) PacketIDFilter(org.jivesoftware.smack.filter.PacketIDFilter)

Example 9 with PacketIDFilter

use of org.jivesoftware.smack.filter.PacketIDFilter in project ecf by eclipse.

the class MultiUserChat method changeAffiliationByOwner.

private void changeAffiliationByOwner(String jid, String affiliation) throws XMPPException {
    MUCOwner iq = new MUCOwner();
    iq.setTo(room);
    iq.setType(IQ.Type.SET);
    // Set the new affiliation.
    MUCOwner.Item item = new MUCOwner.Item(affiliation);
    item.setJid(jid);
    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) PacketCollector(org.jivesoftware.smack.PacketCollector) IQ(org.jivesoftware.smack.packet.IQ) MUCOwner(org.jivesoftware.smackx.packet.MUCOwner) XMPPException(org.jivesoftware.smack.XMPPException) PacketIDFilter(org.jivesoftware.smack.filter.PacketIDFilter)

Example 10 with PacketIDFilter

use of org.jivesoftware.smack.filter.PacketIDFilter in project ecf by eclipse.

the class MultiUserChat method getAffiliatesByOwner.

/**
 * Returns a collection of <code>Affiliate</code> that have the specified room affiliation
 * sending a request in the owner namespace.
 *
 * @param affiliation the affiliation of the users in the room.
 * @return a collection of <code>Affiliate</code> that have the specified room affiliation.
 * @throws XMPPException if an error occured while performing the request to the server or you
 *         don't have enough privileges to get this information.
 */
private Collection<Affiliate> getAffiliatesByOwner(String affiliation) throws XMPPException {
    MUCOwner iq = new MUCOwner();
    iq.setTo(room);
    iq.setType(IQ.Type.GET);
    // Set the specified affiliation. This may request the list of owners/admins/members/outcasts.
    MUCOwner.Item item = new MUCOwner.Item(affiliation);
    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 request to the server.
    connection.sendPacket(iq);
    // Wait up to a certain number of seconds for a reply.
    MUCOwner answer = (MUCOwner) 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());
    }
    // Get the list of affiliates from the server's answer
    List<Affiliate> affiliates = new ArrayList<Affiliate>();
    for (Iterator<MUCOwner.Item> it = answer.getItems(); it.hasNext(); ) {
        affiliates.add(new Affiliate(it.next()));
    }
    return affiliates;
}
Also used : PacketFilter(org.jivesoftware.smack.filter.PacketFilter) PacketCollector(org.jivesoftware.smack.PacketCollector) ArrayList(java.util.ArrayList) MUCOwner(org.jivesoftware.smackx.packet.MUCOwner) XMPPException(org.jivesoftware.smack.XMPPException) PacketIDFilter(org.jivesoftware.smack.filter.PacketIDFilter)

Aggregations

PacketIDFilter (org.jivesoftware.smack.filter.PacketIDFilter)66 IQ (org.jivesoftware.smack.packet.IQ)38 PacketCollector (org.jivesoftware.smack.PacketCollector)36 XMPPException (org.jivesoftware.smack.XMPPException)34 PacketFilter (org.jivesoftware.smack.filter.PacketFilter)22 Packet (org.jivesoftware.smack.packet.Packet)10 AndFilter (org.jivesoftware.smack.filter.AndFilter)7 PacketTypeFilter (org.jivesoftware.smack.filter.PacketTypeFilter)6 Registration (org.jivesoftware.smack.packet.Registration)6 MUCAdmin (org.jivesoftware.smackx.packet.MUCAdmin)6 MUCOwner (org.jivesoftware.smackx.packet.MUCOwner)6 RosterPacket (org.jivesoftware.smack.packet.RosterPacket)4 ArrayList (java.util.ArrayList)3 XMPPConnection (org.jivesoftware.smack.XMPPConnection)3 ActionEvent (java.awt.event.ActionEvent)2 ActionListener (java.awt.event.ActionListener)2 HashMap (java.util.HashMap)2 StanzaCollector (org.jivesoftware.smack.StanzaCollector)2 StanzaListener (org.jivesoftware.smack.StanzaListener)2 Authentication (org.jivesoftware.smack.packet.Authentication)2