Search in sources :

Example 16 with AccountJid

use of com.xabber.android.data.entity.AccountJid in project xabber-android by redsolution.

the class AvatarManager method onStanza.

@Override
public void onStanza(ConnectionItem connection, Stanza stanza) {
    if (!(stanza instanceof Presence)) {
        return;
    }
    AccountJid account = ((AccountItem) connection).getAccount();
    Presence presence = (Presence) stanza;
    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()) {
                try {
                    onPhotoReady(account, UserJid.from(stanza.getFrom()), vCardUpdate);
                } catch (UserJid.UserJidCreateException e) {
                    LogManager.exception(this, e);
                }
            }
        }
    }
}
Also used : AccountItem(com.xabber.android.data.account.AccountItem) AccountJid(com.xabber.android.data.entity.AccountJid) ExtensionElement(org.jivesoftware.smack.packet.ExtensionElement) Presence(org.jivesoftware.smack.packet.Presence) UserJid(com.xabber.android.data.entity.UserJid) VCardUpdate(com.xabber.xmpp.vcardupdate.VCardUpdate)

Example 17 with AccountJid

use of com.xabber.android.data.entity.AccountJid in project xabber-android by redsolution.

the class CapabilitiesManager method onPresence.

public void onPresence(final AccountJid accountJid, final Presence presence) {
    final Jid from = presence.getFrom();
    discoverInfoCache.remove(from);
    clientInfoCache.remove(from);
    DiscoverInfo discoverInfoByUser = EntityCapsManager.getDiscoverInfoByUser(from);
    if (discoverInfoByUser != null) {
        return;
    }
    Application.getInstance().runInBackground(new Runnable() {

        @Override
        public void run() {
            updateClientInfo(accountJid, from);
        }
    });
}
Also used : DiscoverInfo(org.jivesoftware.smackx.disco.packet.DiscoverInfo) Jid(org.jxmpp.jid.Jid) AccountJid(com.xabber.android.data.entity.AccountJid)

Example 18 with AccountJid

use of com.xabber.android.data.entity.AccountJid in project xabber-android by redsolution.

the class ChatStateManager method onStanza.

@Override
public void onStanza(ConnectionItem connection, Stanza stanza) {
    if (stanza.getFrom() == null) {
        return;
    }
    final Resourcepart resource = stanza.getFrom().getResourceOrNull();
    if (resource == null) {
        return;
    }
    final AccountJid account = ((AccountItem) connection).getAccount();
    final UserJid bareUserJid;
    try {
        bareUserJid = UserJid.from(stanza.getFrom()).getBareUserJid();
    } catch (UserJid.UserJidCreateException e) {
        return;
    }
    if (stanza instanceof Presence) {
        Presence presence = (Presence) stanza;
        if (presence.getType() != Type.unavailable) {
            return;
        }
        chatStates.remove(account.toString(), bareUserJid.toString(), resource);
        removeCallback(account, bareUserJid.getBareJid(), resource);
        supports.remove(account.toString(), bareUserJid.toString(), resource);
    } else if (stanza instanceof Message) {
        boolean support = false;
        for (ExtensionElement extension : stanza.getExtensions()) if (extension instanceof ChatStateExtension) {
            removeCallback(account, bareUserJid.getBareJid(), resource);
            ChatState chatState = ((ChatStateExtension) extension).getChatState();
            chatStates.put(account.toString(), bareUserJid.toString(), resource, chatState);
            if (chatState != ChatState.active) {
                Runnable runnable = new Runnable() {

                    @Override
                    public void run() {
                        if (this != stateCleaners.get(account.toString(), bareUserJid.toString(), resource)) {
                            return;
                        }
                        chatStates.remove(account.toString(), bareUserJid.toString(), resource);
                        removeCallback(account, bareUserJid.getBareJid(), resource);
                        RosterManager.onChatStateChanged(account, bareUserJid);
                    }
                };
                handler.postDelayed(runnable, REMOVE_STATE_DELAY);
                stateCleaners.put(account.toString(), bareUserJid.toString(), resource, runnable);
            }
            RosterManager.onChatStateChanged(account, bareUserJid);
            support = true;
            break;
        }
        Message message = (Message) stanza;
        if (message.getType() != Message.Type.chat && message.getType() != Message.Type.groupchat) {
            return;
        }
        if (support) {
            supports.put(account.toString(), bareUserJid.toString(), resource, true);
        } else if (supports.get(account.toString(), bareUserJid.toString(), resource) == null) {
            // Disable only if there no information about support.
            supports.put(account.toString(), bareUserJid.toString(), 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) AccountJid(com.xabber.android.data.entity.AccountJid) ExtensionElement(org.jivesoftware.smack.packet.ExtensionElement) UserJid(com.xabber.android.data.entity.UserJid) Presence(org.jivesoftware.smack.packet.Presence) Resourcepart(org.jxmpp.jid.parts.Resourcepart)

Example 19 with AccountJid

use of com.xabber.android.data.entity.AccountJid in project xabber-android by redsolution.

the class ChatStateManager method onDisconnect.

@Override
public void onDisconnect(ConnectionItem connection) {
    if (!(connection instanceof AccountItem))
        return;
    AccountJid account = ((AccountItem) connection).getAccount();
    chatStates.clear(account.toString());
    for (Map<Resourcepart, Runnable> map : stateCleaners.getNested(account.toString()).values()) {
        for (Runnable runnable : map.values()) {
            handler.removeCallbacks(runnable);
        }
    }
    stateCleaners.clear(account.toString());
    supports.clear(account.toString());
    sent.clear(account.toString());
    for (PendingIntent pendingIntent : pauseIntents.getNested(account.toString()).values()) {
        alarmManager.cancel(pendingIntent);
    }
    pauseIntents.clear(account.toString());
}
Also used : AccountItem(com.xabber.android.data.account.AccountItem) AccountJid(com.xabber.android.data.entity.AccountJid) PendingIntent(android.app.PendingIntent) Resourcepart(org.jxmpp.jid.parts.Resourcepart)

Example 20 with AccountJid

use of com.xabber.android.data.entity.AccountJid in project xabber-android by redsolution.

the class SSNManager method onStanza.

@Override
public void onStanza(ConnectionItem connection, Stanza stanza) {
    Jid from = stanza.getFrom();
    if (from == null) {
        return;
    }
    if (!(connection instanceof AccountItem) || !(stanza instanceof Message)) {
        return;
    }
    AccountJid account = ((AccountItem) connection).getAccount();
    Message message = (Message) stanza;
    String session = message.getThread();
    if (session == null) {
        return;
    }
    for (ExtensionElement packetExtension : stanza.getExtensions()) {
        if (packetExtension instanceof Feature) {
            Feature feature = (Feature) packetExtension;
            if (!feature.isValid()) {
                continue;
            }
            DataForm.Type dataFormType = feature.getDataFormType();
            if (dataFormType == DataForm.Type.form) {
                onFormReceived(account, from, session, feature);
            } else if (dataFormType == DataForm.Type.submit) {
                onSubmitReceived(account, from, session, feature);
            } else if (dataFormType == DataForm.Type.result) {
                onResultReceived(account, session, feature);
            }
        }
    }
}
Also used : Jid(org.jxmpp.jid.Jid) AccountJid(com.xabber.android.data.entity.AccountJid) Message(org.jivesoftware.smack.packet.Message) AccountItem(com.xabber.android.data.account.AccountItem) AccountJid(com.xabber.android.data.entity.AccountJid) ExtensionElement(org.jivesoftware.smack.packet.ExtensionElement) DataForm(org.jivesoftware.smackx.xdata.packet.DataForm) Feature(com.xabber.xmpp.ssn.Feature)

Aggregations

AccountJid (com.xabber.android.data.entity.AccountJid)74 UserJid (com.xabber.android.data.entity.UserJid)38 AccountItem (com.xabber.android.data.account.AccountItem)21 Jid (org.jxmpp.jid.Jid)13 Intent (android.content.Intent)11 ArrayList (java.util.ArrayList)11 View (android.view.View)10 NetworkException (com.xabber.android.data.NetworkException)9 AbstractChat (com.xabber.android.data.message.AbstractChat)7 Message (org.jivesoftware.smack.packet.Message)7 Presence (org.jivesoftware.smack.packet.Presence)7 ExtensionElement (org.jivesoftware.smack.packet.ExtensionElement)6 TextView (android.widget.TextView)5 StatusMode (com.xabber.android.data.account.StatusMode)5 Resourcepart (org.jxmpp.jid.parts.Resourcepart)5 ImageView (android.widget.ImageView)4 AccountManager (com.xabber.android.data.account.AccountManager)4 RosterContact (com.xabber.android.data.roster.RosterContact)4 ContactVO (com.xabber.android.presentation.ui.contactlist.viewobjects.ContactVO)4 BarPainter (com.xabber.android.ui.color.BarPainter)4