Search in sources :

Example 1 with MUCUser

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

the class MultiUserChatManager method decline.

/**
     * Informs the sender of an invitation that the invitee declines the invitation. The rejection will be sent to the
     * room which in turn will forward the rejection to the inviter.
     *
     * @param room the room that sent the original invitation.
     * @param inviter the inviter of the declined invitation.
     * @param reason the reason why the invitee is declining the invitation.
     * @throws NotConnectedException
     * @throws InterruptedException 
     */
public void decline(EntityBareJid room, EntityBareJid inviter, String reason) throws NotConnectedException, InterruptedException {
    Message message = new Message(room);
    // Create the MUCUser packet that will include the rejection
    MUCUser mucUser = new MUCUser();
    MUCUser.Decline decline = new MUCUser.Decline(reason, inviter);
    mucUser.setDecline(decline);
    // Add the MUCUser packet that includes the rejection
    message.addExtension(mucUser);
    connection().sendStanza(message);
}
Also used : MUCUser(org.jivesoftware.smackx.muc.packet.MUCUser) Message(org.jivesoftware.smack.packet.Message)

Example 2 with MUCUser

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

the class MultiUserChat method createOrJoin.

/**
     * Like {@link #create(Resourcepart)}, but will return a {@link MucCreateConfigFormHandle} if the room creation was acknowledged by
     * the service (with an 201 status code). It's up to the caller to decide, based on the return
     * value, if he needs to continue sending the room configuration. If {@code null} is returned, the room
     * already existed and the user is able to join right away, without sending a form.
     *
     * @param mucEnterConfiguration the configuration used to enter the MUC.
     * @return A {@link MucCreateConfigFormHandle} if the room was created while joining, or {@code null} if the room was just joined.
     * @throws XMPPErrorException if the room couldn't be created for some reason (e.g. 405 error if
     *         the user is not allowed to create the room)
     * @throws NoResponseException if there was no response from the server.
     * @throws InterruptedException 
     * @throws MucAlreadyJoinedException if the MUC is already joined
     * @throws NotConnectedException 
     * @throws NotAMucServiceException 
     */
public synchronized MucCreateConfigFormHandle createOrJoin(MucEnterConfiguration mucEnterConfiguration) throws NoResponseException, XMPPErrorException, InterruptedException, MucAlreadyJoinedException, NotConnectedException, NotAMucServiceException {
    if (joined) {
        throw new MucAlreadyJoinedException();
    }
    Presence presence = enter(mucEnterConfiguration);
    // Look for confirmation of room creation from the server
    MUCUser mucUser = MUCUser.from(presence);
    if (mucUser != null && mucUser.getStatus().contains(Status.ROOM_CREATED_201)) {
        // Room was created and the user has joined the room
        return new MucCreateConfigFormHandle();
    }
    return null;
}
Also used : MucAlreadyJoinedException(org.jivesoftware.smackx.muc.MultiUserChatException.MucAlreadyJoinedException) MUCUser(org.jivesoftware.smackx.muc.packet.MUCUser) Presence(org.jivesoftware.smack.packet.Presence) MUCInitialPresence(org.jivesoftware.smackx.muc.packet.MUCInitialPresence)

Example 3 with MUCUser

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

the class MUCManager method invite.

/**
     * Sends invitation.
     *
     * @throws NetworkException
     */
public void invite(String account, String room, String user) throws NetworkException {
    RoomChat roomChat = getRoomChat(account, room);
    if (roomChat == null || roomChat.getState() != RoomState.available) {
        Application.getInstance().onError(R.string.NOT_CONNECTED);
        return;
    }
    Message message = new Message(room);
    MUCUser mucUser = new MUCUser();
    MUCUser.Invite invite = new MUCUser.Invite();
    invite.setTo(user);
    invite.setReason("");
    mucUser.setInvite(invite);
    message.addExtension(mucUser);
    ConnectionManager.getInstance().sendStanza(account, message);
    roomChat.putInvite(message.getPacketID(), user);
    roomChat.newAction(roomChat.getNickname(), user, ChatAction.invite_sent);
}
Also used : MUCUser(org.jivesoftware.smackx.muc.packet.MUCUser) Message(org.jivesoftware.smack.packet.Message)

Example 4 with MUCUser

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

the class RoomChat method onPacket.

@Override
protected boolean onPacket(String bareAddress, Stanza packet) {
    if (!super.onPacket(bareAddress, packet)) {
        return false;
    }
    MUCUser mucUserExtension = MUC.getMUCUserExtension(packet);
    if (mucUserExtension != null && mucUserExtension.getInvite() != null) {
        return false;
    }
    final String from = packet.getFrom();
    final String resource = XmppStringUtils.parseResource(from);
    if (packet instanceof Message) {
        final Message message = (Message) packet;
        if (message.getType() == Message.Type.error) {
            String invite = invites.remove(message.getPacketID());
            if (invite != null) {
                newAction(nickname, invite, ChatAction.invite_error);
            }
            return true;
        }
        MUCUser mucUser = MUC.getMUCUserExtension(packet);
        if (mucUser != null && mucUser.getDecline() != null) {
            onInvitationDeclined(mucUser.getDecline().getFrom(), mucUser.getDecline().getReason());
            return true;
        }
        if (mucUser != null && mucUser.getStatus() != null && mucUser.getStatus().contains(MUCUser.Status.create("100")) && ChatManager.getInstance().isSuppress100(account, user)) {
            // 'This room is not anonymous'
            return true;
        }
        final String text = message.getBody();
        final String subject = message.getSubject();
        if (text == null && subject == null) {
            return true;
        }
        if (subject != null) {
            if (this.subject.equals(subject)) {
                return true;
            }
            this.subject = subject;
            RosterManager.getInstance().onContactChanged(account, bareAddress);
            newAction(resource, subject, ChatAction.subject);
        } else {
            boolean notify = true;
            String packetID = message.getPacketID();
            Date delay = Delay.getDelay(message);
            if (delay != null) {
                notify = false;
            }
            for (MessageItem messageItem : messages) {
                // Search for duplicates
                if (packetID != null && packetID.equals(messageItem.getPacketID())) {
                    // Server send our own message back
                    messageItem.markAsDelivered();
                    RosterManager.getInstance().onContactChanged(account, user);
                    return true;
                }
                if (delay != null) {
                    if (delay.equals(messageItem.getDelayTimestamp()) && resource.equals(messageItem.getResource()) && text.equals(messageItem.getText())) {
                        return true;
                    }
                }
            }
            if (isSelf(resource)) {
                // Own message from other client
                notify = false;
            }
            updateThreadId(message.getThread());
            MessageItem messageItem = newMessage(resource, text, null, delay, true, notify, false, false, true);
            messageItem.setPacketID(packetID);
        }
    } else if (packet instanceof Presence) {
        String stringPrep = Jid.getStringPrep(resource);
        Presence presence = (Presence) packet;
        if (presence.getType() == Presence.Type.available) {
            Occupant oldOccupant = occupants.get(stringPrep);
            Occupant newOccupant = createOccupant(resource, presence);
            occupants.put(stringPrep, newOccupant);
            if (oldOccupant == null) {
                onAvailable(resource);
                RosterManager.getInstance().onContactChanged(account, user);
            } else {
                boolean changed = false;
                if (oldOccupant.getAffiliation() != newOccupant.getAffiliation()) {
                    changed = true;
                    onAffiliationChanged(resource, newOccupant.getAffiliation());
                }
                if (oldOccupant.getRole() != newOccupant.getRole()) {
                    changed = true;
                    onRoleChanged(resource, newOccupant.getRole());
                }
                if (oldOccupant.getStatusMode() != newOccupant.getStatusMode() || !oldOccupant.getStatusText().equals(newOccupant.getStatusText())) {
                    changed = true;
                    onStatusChanged(resource, newOccupant.getStatusMode(), newOccupant.getStatusText());
                }
                if (changed) {
                    RosterManager.getInstance().onContactChanged(account, user);
                }
            }
        } else if (presence.getType() == Presence.Type.unavailable && state == RoomState.available) {
            occupants.remove(stringPrep);
            MUCUser mucUser = MUC.getMUCUserExtension(presence);
            if (mucUser != null && mucUser.getStatus() != null) {
                if (mucUser.getStatus().contains(MUCUser.Status.KICKED_307)) {
                    onKick(resource, mucUser.getItem().getActor());
                } else if (mucUser.getStatus().contains(MUCUser.Status.BANNED_301)) {
                    onBan(resource, mucUser.getItem().getActor());
                } else if (mucUser.getStatus().contains(MUCUser.Status.NEW_NICKNAME_303)) {
                    String newNick = mucUser.getItem().getNick();
                    if (newNick == null) {
                        return true;
                    }
                    onRename(resource, newNick);
                    Occupant occupant = createOccupant(newNick, presence);
                    occupants.put(Jid.getStringPrep(newNick), occupant);
                } else if (mucUser.getStatus().contains(MUCUser.Status.REMOVED_AFFIL_CHANGE_321)) {
                    onRevoke(resource, mucUser.getItem().getActor());
                }
            } else {
                onLeave(resource);
            }
            RosterManager.getInstance().onContactChanged(account, user);
        }
    }
    return true;
}
Also used : MessageItem(com.xabber.android.data.message.MessageItem) MUCUser(org.jivesoftware.smackx.muc.packet.MUCUser) Message(org.jivesoftware.smack.packet.Message) Presence(org.jivesoftware.smack.packet.Presence) Date(java.util.Date)

Example 5 with MUCUser

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

the class MessageManager method onPacket.

@Override
public void onPacket(ConnectionItem connection, String bareAddress, Stanza packet) {
    if (!(connection instanceof AccountItem)) {
        return;
    }
    String account = ((AccountItem) connection).getAccount();
    if (bareAddress == null) {
        return;
    }
    if (packet instanceof Message && MessageArchiveManager.getInstance().isModificationsSucceed(account) && Delay.isOfflineMessage(Jid.getServer(account), packet)) {
        // archive have been received.
        return;
    }
    String contact = bareAddress;
    if (packet instanceof Message) {
        Message message = (Message) packet;
        if (MUCManager.getInstance().hasRoom(account, bareAddress) && message.getType() != Message.Type.groupchat) {
            contact = packet.getFrom();
        }
    }
    final String user = packet.getFrom();
    boolean processed = false;
    for (AbstractChat chat : chats.getNested(account).values()) {
        if (chat.onPacket(contact, packet)) {
            processed = true;
            break;
        }
    }
    final AbstractChat chat = getChat(account, user);
    if (chat != null && packet instanceof Message) {
        if (chat.isPrivateMucChat() && !chat.isPrivateMucChatAccepted()) {
            if (mucPrivateChatRequestProvider.get(chat.getAccount(), chat.getUser()) == null) {
                if (!PrivateMucChatBlockingManager.getInstance().getBlockedContacts(account).contains(chat.getUser())) {
                    mucPrivateChatRequestProvider.add(new MucPrivateChatNotification(account, user), true);
                }
            }
        }
        return;
    }
    if (!processed && packet instanceof Message) {
        final Message message = (Message) packet;
        final String body = message.getBody();
        if (body == null) {
            return;
        }
        if (message.getType() == Message.Type.chat && MUCManager.getInstance().hasRoom(account, Jid.getBareAddress(user))) {
            createPrivateMucChat(account, user).onPacket(contact, packet);
            if (!PrivateMucChatBlockingManager.getInstance().getBlockedContacts(account).contains(user)) {
                mucPrivateChatRequestProvider.add(new MucPrivateChatNotification(account, user), true);
            }
            return;
        }
        for (ExtensionElement packetExtension : message.getExtensions()) {
            if (packetExtension instanceof MUCUser) {
                return;
            }
        }
        createChat(account, user).onPacket(contact, packet);
    }
}
Also used : MucPrivateChatNotification(com.xabber.android.data.message.chat.MucPrivateChatNotification) MUCUser(org.jivesoftware.smackx.muc.packet.MUCUser) Message(org.jivesoftware.smack.packet.Message) AccountItem(com.xabber.android.data.account.AccountItem) ExtensionElement(org.jivesoftware.smack.packet.ExtensionElement)

Aggregations

MUCUser (org.jivesoftware.smackx.muc.packet.MUCUser)11 Message (org.jivesoftware.smack.packet.Message)8 Presence (org.jivesoftware.smack.packet.Presence)4 AccountItem (com.xabber.android.data.account.AccountItem)2 Map (java.util.Map)2 ExtensionElement (org.jivesoftware.smack.packet.ExtensionElement)2 MetaData (org.jivesoftware.smackx.workgroup.MetaData)2 SessionID (org.jivesoftware.smackx.workgroup.packet.SessionID)2 StatusMode (com.xabber.android.data.account.StatusMode)1 OTRUnencryptedException (com.xabber.android.data.extension.otr.OTRUnencryptedException)1 MessageItem (com.xabber.android.data.message.MessageItem)1 MucPrivateChatNotification (com.xabber.android.data.message.chat.MucPrivateChatNotification)1 Affiliation (com.xabber.xmpp.muc.Affiliation)1 Role (com.xabber.xmpp.muc.Role)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1 NoSuchElementException (java.util.NoSuchElementException)1 OtrException (net.java.otr4j.OtrException)1 StandardExtensionElement (org.jivesoftware.smack.packet.StandardExtensionElement)1 MucAlreadyJoinedException (org.jivesoftware.smackx.muc.MultiUserChatException.MucAlreadyJoinedException)1