Search in sources :

Example 1 with MUCItem

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

the class MultiUserChat method getAffiliatesByAdmin.

/**
 * Returns a collection of <code>Affiliate</code> that have the specified room affiliation
 * sending a request in the admin 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 XMPPErrorException if 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<Affiliate> getAffiliatesByAdmin(MUCAffiliation affiliation) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
    MUCAdmin iq = new MUCAdmin();
    iq.setTo(room);
    iq.setType(IQ.Type.get);
    // Set the specified affiliation. This may request the list of owners/admins/members/outcasts.
    MUCItem item = new MUCItem(affiliation);
    iq.addItem(item);
    MUCAdmin answer = (MUCAdmin) connection.sendIqRequestAndWaitForResponse(iq);
    // Get the list of affiliates from the server's answer
    List<Affiliate> affiliates = new ArrayList<Affiliate>();
    for (MUCItem mucadminItem : answer.getItems()) {
        affiliates.add(new Affiliate(mucadminItem));
    }
    return affiliates;
}
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 2 with MUCItem

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

the class MultiUserChat method changeAffiliationByAdmin.

private void changeAffiliationByAdmin(Collection<? extends Jid> jids, MUCAffiliation affiliation) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
    MUCAdmin iq = new MUCAdmin();
    iq.setTo(room);
    iq.setType(IQ.Type.set);
    for (Jid jid : jids) {
        // Set the new affiliation.
        MUCItem item = new MUCItem(affiliation, jid);
        iq.addItem(item);
    }
    connection.sendIqRequestAndWaitForResponse(iq);
}
Also used : MUCItem(org.jivesoftware.smackx.muc.packet.MUCItem) EntityJid(org.jxmpp.jid.EntityJid) DomainBareJid(org.jxmpp.jid.DomainBareJid) EntityBareJid(org.jxmpp.jid.EntityBareJid) Jid(org.jxmpp.jid.Jid) EntityFullJid(org.jxmpp.jid.EntityFullJid) MUCAdmin(org.jivesoftware.smackx.muc.packet.MUCAdmin)

Example 3 with MUCItem

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

the class MultiUserChat method changeAffiliationByAdmin.

/**
 * Tries to change the affiliation with an 'muc#admin' namespace
 *
 * @param jid TODO javadoc me please
 * @param affiliation TODO javadoc me please
 * @param reason the reason for the affiliation change (optional)
 * @throws XMPPErrorException if there was an XMPP error returned.
 * @throws NoResponseException if there was no response from the remote entity.
 * @throws NotConnectedException if the XMPP connection is not connected.
 * @throws InterruptedException if the calling thread was interrupted.
 */
private void changeAffiliationByAdmin(Jid jid, MUCAffiliation affiliation, String reason) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
    MUCAdmin iq = new MUCAdmin();
    iq.setTo(room);
    iq.setType(IQ.Type.set);
    // Set the new affiliation.
    MUCItem item = new MUCItem(affiliation, jid, reason);
    iq.addItem(item);
    connection.sendIqRequestAndWaitForResponse(iq);
}
Also used : MUCItem(org.jivesoftware.smackx.muc.packet.MUCItem) MUCAdmin(org.jivesoftware.smackx.muc.packet.MUCAdmin)

Example 4 with MUCItem

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

the class MultiUserChat method changeRole.

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

Example 5 with MUCItem

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

the class MUCParserUtils method parseItem.

public static MUCItem parseItem(XmlPullParser parser) throws XmlPullParserException, IOException {
    int initialDepth = parser.getDepth();
    MUCAffiliation affiliation = MUCAffiliation.fromString(parser.getAttributeValue("", "affiliation"));
    Resourcepart nick = ParserUtils.getResourcepartAttribute(parser, "nick");
    MUCRole role = MUCRole.fromString(parser.getAttributeValue("", "role"));
    Jid jid = ParserUtils.getJidAttribute(parser);
    Jid actor = null;
    Resourcepart actorNick = null;
    String reason = null;
    outerloop: while (true) {
        XmlPullParser.Event eventType = parser.next();
        switch(eventType) {
            case START_ELEMENT:
                String name = parser.getName();
                switch(name) {
                    case "actor":
                        actor = ParserUtils.getJidAttribute(parser);
                        // TODO change to
                        // actorNick = Resourcepart.from(parser.getAttributeValue("", "nick"));
                        // once a newer version of JXMPP is used that supports from(null).
                        String actorNickString = parser.getAttributeValue("", "nick");
                        if (actorNickString != null) {
                            actorNick = Resourcepart.from(actorNickString);
                        }
                        break;
                    case "reason":
                        reason = parser.nextText();
                        break;
                }
                break;
            case END_ELEMENT:
                if (parser.getDepth() == initialDepth) {
                    break outerloop;
                }
                break;
            default:
                // Catch all for incomplete switch (MissingCasesInEnumSwitch) statement.
                break;
        }
    }
    return new MUCItem(affiliation, role, actor, reason, jid, nick, actorNick);
}
Also used : MUCItem(org.jivesoftware.smackx.muc.packet.MUCItem) MUCAffiliation(org.jivesoftware.smackx.muc.MUCAffiliation) MUCRole(org.jivesoftware.smackx.muc.MUCRole) Jid(org.jxmpp.jid.Jid) EntityBareJid(org.jxmpp.jid.EntityBareJid) Resourcepart(org.jxmpp.jid.parts.Resourcepart)

Aggregations

MUCItem (org.jivesoftware.smackx.muc.packet.MUCItem)10 MUCAdmin (org.jivesoftware.smackx.muc.packet.MUCAdmin)6 MUCUser (org.jivesoftware.smackx.muc.packet.MUCUser)3 StatusMode (com.xabber.android.data.account.StatusMode)2 ArrayList (java.util.ArrayList)2 NoSuchElementException (java.util.NoSuchElementException)2 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)2 MUCAffiliation (org.jivesoftware.smackx.muc.MUCAffiliation)2 MUCRole (org.jivesoftware.smackx.muc.MUCRole)2 EntityBareJid (org.jxmpp.jid.EntityBareJid)2 Jid (org.jxmpp.jid.Jid)2 Resourcepart (org.jxmpp.jid.parts.Resourcepart)2 Affiliation (com.xabber.xmpp.muc.Affiliation)1 Role (com.xabber.xmpp.muc.Role)1 SmackException (org.jivesoftware.smack.SmackException)1 XMPPException (org.jivesoftware.smack.XMPPException)1 ServiceDiscoveryManager (org.jivesoftware.smackx.disco.ServiceDiscoveryManager)1 DomainBareJid (org.jxmpp.jid.DomainBareJid)1 EntityFullJid (org.jxmpp.jid.EntityFullJid)1 EntityJid (org.jxmpp.jid.EntityJid)1