Search in sources :

Example 6 with MUCItem

use of org.jivesoftware.smackx.muc.packet.MUCItem in project xabber-android by redsolution.

the class RoomChat method createOccupant.

/**
     * Warning: this method should be placed with packet provider.
     *
     * @return New occupant based on presence information.
     */
private Occupant createOccupant(String resource, Presence presence) {
    Occupant occupant = new Occupant(resource);
    String jid = null;
    Affiliation affiliation = Affiliation.none;
    Role role = Role.none;
    StatusMode statusMode = StatusMode.unavailable;
    String statusText = null;
    MUCUser mucUser = MUC.getMUCUserExtension(presence);
    if (mucUser != null) {
        MUCItem item = mucUser.getItem();
        if (item != null) {
            jid = item.getJid();
            try {
                affiliation = Affiliation.fromString(item.getAffiliation().toString());
            } catch (NoSuchElementException e) {
            }
            try {
                role = Role.fromString(item.getRole().toString());
            } catch (NoSuchElementException e) {
            }
            statusMode = StatusMode.createStatusMode(presence);
            statusText = presence.getStatus();
        }
    }
    if (statusText == null) {
        statusText = "";
    }
    occupant.setJid(jid);
    occupant.setAffiliation(affiliation);
    occupant.setRole(role);
    occupant.setStatusMode(statusMode);
    occupant.setStatusText(statusText);
    return occupant;
}
Also used : Role(com.xabber.xmpp.muc.Role) MUCItem(org.jivesoftware.smackx.muc.packet.MUCItem) StatusMode(com.xabber.android.data.account.StatusMode) MUCUser(org.jivesoftware.smackx.muc.packet.MUCUser) NoSuchElementException(java.util.NoSuchElementException) Affiliation(com.xabber.xmpp.muc.Affiliation)

Example 7 with MUCItem

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

the class GroupChatParticipantList method setChatRoom.

public void setChatRoom(final ChatRoom chatRoom) {
    this.groupChatRoom = (GroupChatRoom) chatRoom;
    chat = groupChatRoom.getMultiUserChat();
    chat.addInvitationRejectionListener((jid1, message) -> {
        String nickname = userManager.getUserNicknameFromJID(jid1);
        userHasLeft(nickname);
        chatRoom.getTranscriptWindow().insertNotificationMessage(nickname + " has rejected the invitation.", ChatManager.NOTIFICATION_COLOR);
    });
    listener = p -> SwingUtilities.invokeLater(() -> {
        if (p.getError() != null) {
            if (p.getError().getCondition().equals(XMPPError.Condition.conflict.toString())) {
                return;
            }
        }
        final String userid = p.getFrom();
        String displayName = XmppStringUtils.parseResource(userid);
        userMap.put(displayName, userid);
        if (p.getType() == Presence.Type.available) {
            addParticipant(userid, p);
            agentInfoPanel.setVisible(true);
            groupChatRoom.validate();
        } else {
            removeUser(displayName);
        }
        // When joining a room, check if the current user is an owner/admin. If so, the UI should allow the current
        // user to change settings of this MUC.
        final MUCUser mucUserEx = p.getExtension(MUCUser.ELEMENT, MUCUser.NAMESPACE);
        if (// 110 = Inform user that presence refers to itself
        mucUserEx != null && mucUserEx.getStatus().contains(MUCUser.Status.create(110))) {
            final MUCItem item = mucUserEx.getItem();
            if (item != null) {
                if (item.getAffiliation() == MUCAffiliation.admin || item.getAffiliation() == MUCAffiliation.owner) {
                    groupChatRoom.notifySettingsAccessRight();
                }
            }
        }
    });
    chat.addParticipantListener(listener);
    ServiceDiscoveryManager disco = ServiceDiscoveryManager.getInstanceFor(SparkManager.getConnection());
    try {
        roomInformation = disco.discoverInfo(chat.getRoom());
    } catch (XMPPException | SmackException e) {
        Log.debug("Unable to retrieve room information for " + chat.getRoom());
    }
}
Also used : MUCItem(org.jivesoftware.smackx.muc.packet.MUCItem) MUCUser(org.jivesoftware.smackx.muc.packet.MUCUser) SmackException(org.jivesoftware.smack.SmackException) XMPPException(org.jivesoftware.smack.XMPPException) ServiceDiscoveryManager(org.jivesoftware.smackx.disco.ServiceDiscoveryManager)

Example 8 with MUCItem

use of org.jivesoftware.smackx.muc.packet.MUCItem 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 9 with MUCItem

use of org.jivesoftware.smackx.muc.packet.MUCItem 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)

Example 10 with MUCItem

use of org.jivesoftware.smackx.muc.packet.MUCItem in project xabber-android by redsolution.

the class RoomChat method createOccupant.

/**
 * Warning: this method should be placed with packet provider.
 *
 * @return New occupant based on presence information.
 */
private Occupant createOccupant(Resourcepart resource, Presence presence) {
    Occupant occupant = new Occupant(resource);
    org.jxmpp.jid.Jid jid = null;
    MUCAffiliation affiliation = MUCAffiliation.none;
    MUCRole role = MUCRole.none;
    StatusMode statusMode = StatusMode.unavailable;
    String statusText = null;
    MUCUser mucUser = MUCUser.from(presence);
    if (mucUser != null) {
        MUCItem item = mucUser.getItem();
        if (item != null) {
            jid = item.getJid();
            try {
                affiliation = item.getAffiliation();
            } catch (NoSuchElementException e) {
            }
            try {
                role = item.getRole();
            } catch (NoSuchElementException e) {
            }
            statusMode = StatusMode.createStatusMode(presence);
            statusText = presence.getStatus();
        }
    }
    if (statusText == null) {
        statusText = "";
    }
    occupant.setJid(jid);
    occupant.setAffiliation(affiliation);
    occupant.setRole(role);
    occupant.setStatusMode(statusMode);
    occupant.setStatusText(statusText);
    return occupant;
}
Also used : MUCItem(org.jivesoftware.smackx.muc.packet.MUCItem) MUCAffiliation(org.jivesoftware.smackx.muc.MUCAffiliation) StatusMode(com.xabber.android.data.account.StatusMode) MUCUser(org.jivesoftware.smackx.muc.packet.MUCUser) MUCRole(org.jivesoftware.smackx.muc.MUCRole) NoSuchElementException(java.util.NoSuchElementException)

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