Search in sources :

Example 91 with Presence

use of org.jivesoftware.smack.packet.Presence in project xabber-android by redsolution.

the class PresenceManager method discardSubscription.

/**
     * Discards subscription request from the entity (deny own presence
     * sharing).
     *
     * @param account
     * @param bareAddress
     * @throws NetworkException
     */
public void discardSubscription(String account, String bareAddress) throws NetworkException {
    Presence packet = new Presence(Presence.Type.unsubscribed);
    packet.setTo(bareAddress);
    ConnectionManager.getInstance().sendStanza(account, packet);
    subscriptionRequestProvider.remove(account, bareAddress);
    removeRequestedSubscription(account, bareAddress);
}
Also used : Presence(org.jivesoftware.smack.packet.Presence)

Example 92 with Presence

use of org.jivesoftware.smack.packet.Presence in project xabber-android by redsolution.

the class PresenceManager method getStatusText.

public String getStatusText(String account, String bareAddress) {
    final Occupant occupant = getOccupant(account, bareAddress);
    if (occupant != null) {
        return occupant.getStatusText();
    }
    final Presence presence = RosterManager.getInstance().getPresence(account, bareAddress);
    if (presence == null) {
        return null;
    } else {
        return presence.getStatus();
    }
}
Also used : Occupant(com.xabber.android.data.extension.muc.Occupant) Presence(org.jivesoftware.smack.packet.Presence)

Example 93 with Presence

use of org.jivesoftware.smack.packet.Presence in project xabber-android by redsolution.

the class PresenceManager method acceptSubscription.

/**
     * Accepts subscription request from the entity (share own presence).
     *
     * @param account
     * @param bareAddress
     * @throws NetworkException
     */
public void acceptSubscription(String account, String bareAddress) throws NetworkException {
    Presence packet = new Presence(Presence.Type.subscribed);
    packet.setTo(bareAddress);
    ConnectionManager.getInstance().sendStanza(account, packet);
    subscriptionRequestProvider.remove(account, bareAddress);
    removeRequestedSubscription(account, bareAddress);
}
Also used : Presence(org.jivesoftware.smack.packet.Presence)

Example 94 with Presence

use of org.jivesoftware.smack.packet.Presence in project xabber-android by redsolution.

the class ChatStateManager method onPacket.

@Override
public void onPacket(ConnectionItem connection, final String bareAddress, Stanza packet) {
    if (!(connection instanceof AccountItem))
        return;
    final String resource = Jid.getResource(packet.getFrom());
    if (resource == null)
        return;
    final String account = ((AccountItem) connection).getAccount();
    if (packet instanceof Presence) {
        Presence presence = (Presence) packet;
        if (presence.getType() != Type.unavailable)
            return;
        chatStates.remove(account, bareAddress, resource);
        removeCallback(account, bareAddress, resource);
        supports.remove(account, bareAddress, resource);
    } else if (packet instanceof Message) {
        boolean support = false;
        for (ExtensionElement extension : packet.getExtensions()) if (extension instanceof ChatStateExtension) {
            removeCallback(account, bareAddress, resource);
            ChatState chatState = ((ChatStateExtension) extension).getChatState();
            chatStates.put(account, bareAddress, resource, chatState);
            if (chatState != ChatState.active) {
                Runnable runnable = new Runnable() {

                    @Override
                    public void run() {
                        if (this != stateCleaners.get(account, bareAddress, resource))
                            return;
                        chatStates.remove(account, bareAddress, resource);
                        removeCallback(account, bareAddress, resource);
                        RosterManager.getInstance().onContactChanged(account, bareAddress);
                    }
                };
                handler.postDelayed(runnable, REMOVE_STATE_DELAY);
                stateCleaners.put(account, bareAddress, resource, runnable);
            }
            RosterManager.getInstance().onContactChanged(account, bareAddress);
            support = true;
            break;
        }
        Message message = (Message) packet;
        if (message.getType() != Message.Type.chat && message.getType() != Message.Type.groupchat)
            return;
        if (support)
            supports.put(account, bareAddress, resource, true);
        else if (supports.get(account, bareAddress, resource) == null)
            // Disable only if there no information about support.
            supports.put(account, bareAddress, resource, false);
    }
}
Also used : ChatState(org.jivesoftware.smackx.chatstates.ChatState) Message(org.jivesoftware.smack.packet.Message) ChatStateExtension(org.jivesoftware.smackx.chatstates.packet.ChatStateExtension) AccountItem(com.xabber.android.data.account.AccountItem) ExtensionElement(org.jivesoftware.smack.packet.ExtensionElement) Presence(org.jivesoftware.smack.packet.Presence)

Example 95 with Presence

use of org.jivesoftware.smack.packet.Presence in project xabber-android by redsolution.

the class AvatarManager method onPacket.

@Override
public void onPacket(ConnectionItem connection, String bareAddress, Stanza packet) {
    if (!(packet instanceof Presence) || bareAddress == null) {
        return;
    }
    if (!(connection instanceof AccountItem)) {
        return;
    }
    String account = ((AccountItem) connection).getAccount();
    Presence presence = (Presence) packet;
    if (presence.getType() == Presence.Type.error) {
        return;
    }
    for (ExtensionElement packetExtension : presence.getExtensions()) {
        if (packetExtension instanceof VCardUpdate) {
            VCardUpdate vCardUpdate = (VCardUpdate) packetExtension;
            if (vCardUpdate.isValid() && vCardUpdate.isPhotoReady()) {
                onPhotoReady(account, bareAddress, vCardUpdate);
            }
        }
    }
}
Also used : AccountItem(com.xabber.android.data.account.AccountItem) ExtensionElement(org.jivesoftware.smack.packet.ExtensionElement) Presence(org.jivesoftware.smack.packet.Presence) VCardUpdate(com.xabber.xmpp.avatar.VCardUpdate)

Aggregations

Presence (org.jivesoftware.smack.packet.Presence)103 Message (org.jivesoftware.smack.packet.Message)21 Resourcepart (org.jxmpp.jid.parts.Resourcepart)12 Jid (org.jxmpp.jid.Jid)11 MessageTypeFilter (org.jivesoftware.smack.filter.MessageTypeFilter)10 AccountItem (com.xabber.android.data.account.AccountItem)9 UserJid (com.xabber.android.data.entity.UserJid)9 AccountJid (com.xabber.android.data.entity.AccountJid)7 StanzaCollector (org.jivesoftware.smack.StanzaCollector)7 AndFilter (org.jivesoftware.smack.filter.AndFilter)7 UserPresence (jetbrains.communicator.core.users.UserPresence)6 MUCUser (org.jivesoftware.smackx.muc.packet.MUCUser)6 BareJid (org.jxmpp.jid.BareJid)6 ClientInfo (com.xabber.android.data.extension.capability.ClientInfo)5 ArrayList (java.util.ArrayList)5 Date (java.util.Date)5 StanzaTypeFilter (org.jivesoftware.smack.filter.StanzaTypeFilter)5 MUCInitialPresence (org.jivesoftware.smackx.muc.packet.MUCInitialPresence)5 Test (org.junit.Test)5 EntityFullJid (org.jxmpp.jid.EntityFullJid)5