Search in sources :

Example 36 with AccountItem

use of com.xabber.android.data.account.AccountItem in project xabber-android by redsolution.

the class ReceiptManager method onStanza.

@Override
public void onStanza(ConnectionItem connection, Stanza packet) {
    if (!(connection instanceof AccountItem)) {
        return;
    }
    final AccountJid account = ((AccountItem) connection).getAccount();
    final Jid from = packet.getFrom();
    if (from == null) {
        return;
    }
    if (!(packet instanceof Message)) {
        return;
    }
    final Message message = (Message) packet;
    if (message.getType() == Message.Type.error) {
        Application.getInstance().runInBackgroundUserRequest(new Runnable() {

            @Override
            public void run() {
                markAsError(account, message);
            }
        });
    } else {
        // TODO setDefaultAutoReceiptMode should be used
        for (ExtensionElement packetExtension : message.getExtensions()) {
            if (packetExtension instanceof DeliveryReceiptRequest) {
                String id = AbstractChat.getStanzaId(message);
                if (id == null) {
                    continue;
                }
                Message receipt = new Message(from);
                receipt.addExtension(new DeliveryReceipt(id));
                // the key problem is Thread - smack does not keep it in auto reply
                receipt.setThread(message.getThread());
                receipt.setType(Message.Type.chat);
                try {
                    StanzaSender.sendStanza(account, receipt);
                } catch (NetworkException e) {
                    LogManager.exception(this, e);
                }
            }
        }
    }
}
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) DeliveryReceiptRequest(org.jivesoftware.smackx.receipts.DeliveryReceiptRequest) AccountJid(com.xabber.android.data.entity.AccountJid) DeliveryReceipt(org.jivesoftware.smackx.receipts.DeliveryReceipt) ExtensionElement(org.jivesoftware.smack.packet.ExtensionElement) NetworkException(com.xabber.android.data.NetworkException)

Example 37 with AccountItem

use of com.xabber.android.data.account.AccountItem 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)

Example 38 with AccountItem

use of com.xabber.android.data.account.AccountItem in project xabber-android by redsolution.

the class VCardManager method onStanza.

@Override
public void onStanza(ConnectionItem connection, Stanza stanza) {
    if (!(connection instanceof AccountItem)) {
        return;
    }
    AccountJid account = connection.getAccount();
    if (stanza instanceof Presence && ((Presence) stanza).getType() != Presence.Type.error) {
        Jid from = stanza.getFrom();
        if (from == null) {
            return;
        }
        Jid addressForVcard = from;
        if (MUCManager.getInstance().hasRoom(account, from.asEntityBareJidIfPossible())) {
            addressForVcard = from;
        }
        // Request vCard for new users
        if (!names.containsKey(addressForVcard)) {
            if (SettingsManager.connectionLoadVCard()) {
                request(account, addressForVcard);
            }
        }
    }
    if (stanza instanceof VCard) {
        Jid from = stanza.getFrom();
        if (from == null)
            return;
        onVCardReceived(account, from, (VCard) stanza);
    }
}
Also used : UserJid(com.xabber.android.data.entity.UserJid) AccountJid(com.xabber.android.data.entity.AccountJid) EntityBareJid(org.jxmpp.jid.EntityBareJid) Jid(org.jxmpp.jid.Jid) BareJid(org.jxmpp.jid.BareJid) AccountItem(com.xabber.android.data.account.AccountItem) AccountJid(com.xabber.android.data.entity.AccountJid) Presence(org.jivesoftware.smack.packet.Presence) VCard(org.jivesoftware.smackx.vcardtemp.packet.VCard)

Example 39 with AccountItem

use of com.xabber.android.data.account.AccountItem in project xabber-android by redsolution.

the class VCardManager method saveVCard.

public void saveVCard(final AccountJid account, final VCard vCard) {
    AccountItem accountItem = AccountManager.getInstance().getAccount(account);
    if (accountItem == null) {
        onVCardSaveFailed(account);
        return;
    }
    final AbstractXMPPConnection xmppConnection = accountItem.getConnection();
    final CustomVCardManager vCardManager = CustomVCardManager.getInstanceFor(xmppConnection);
    Application.getInstance().runInBackgroundUserRequest(new Runnable() {

        @Override
        public void run() {
            boolean isSuccess = true;
            xmppConnection.setPacketReplyTimeout(120000);
            vCardSaveRequests.add(account);
            try {
                vCardManager.saveVCard(vCard);
                String avatarHash = null;
                try {
                    avatarHash = vCard.getAvatarHash();
                // "bad base-64" error happen sometimes
                } catch (IllegalArgumentException e) {
                    LogManager.exception(this, e);
                }
                if (avatarHash == null) {
                    avatarHash = AvatarManager.EMPTY_HASH;
                }
                PresenceManager.getInstance().sendVCardUpdatePresence(account, avatarHash);
            } catch (SmackException.NoResponseException | XMPPException.XMPPErrorException | SmackException.NotConnectedException | NetworkException | InterruptedException e) {
                LogManager.w(this, "Error saving vCard: " + e.getMessage());
                isSuccess = false;
            }
            vCardSaveRequests.remove(account);
            xmppConnection.setPacketReplyTimeout(ConnectionManager.PACKET_REPLY_TIMEOUT);
            final boolean finalIsSuccess = isSuccess;
            Application.getInstance().runOnUiThread(new Runnable() {

                @Override
                public void run() {
                    if (finalIsSuccess) {
                        onVCardSaveSuccess(account);
                    } else {
                        onVCardSaveFailed(account);
                    }
                }
            });
        }
    });
}
Also used : AccountItem(com.xabber.android.data.account.AccountItem) SmackException(org.jivesoftware.smack.SmackException) XMPPException(org.jivesoftware.smack.XMPPException) AbstractXMPPConnection(org.jivesoftware.smack.AbstractXMPPConnection)

Example 40 with AccountItem

use of com.xabber.android.data.account.AccountItem in project xabber-android by redsolution.

the class XabberAccountManager method createSyncList.

/**
 * @param remoteList is list of settings from cloud
 * @return list of settings for displaying in sync-dialog
 */
public List<XMPPAccountSettings> createSyncList(List<XMPPAccountSettings> remoteList) {
    List<XMPPAccountSettings> resultList = new ArrayList<>();
    // add remote accounts to list
    for (XMPPAccountSettings remoteItem : remoteList) {
        XMPPAccountSettings.SyncStatus status = XMPPAccountSettings.SyncStatus.remote;
        // if account already exist
        AccountJid accountJid = getExistingAccount(remoteItem.getJid());
        if (accountJid != null) {
            AccountItem localItem = AccountManager.getInstance().getAccount(accountJid);
            if (localItem != null) {
                if (remoteItem.getTimestamp() == localItem.getTimestamp())
                    status = XMPPAccountSettings.SyncStatus.localEqualsRemote;
                else if (remoteItem.getTimestamp() > localItem.getTimestamp())
                    status = XMPPAccountSettings.SyncStatus.remoteNewer;
                else {
                    status = XMPPAccountSettings.SyncStatus.localNewer;
                    remoteItem.setTimestamp(localItem.getTimestamp());
                }
                remoteItem.setSyncNotAllowed(localItem.isSyncNotAllowed());
            }
            remoteItem.setStatus(status);
            remoteItem.setSynchronization(isAccountSynchronize(remoteItem.getJid()));
            resultList.add(remoteItem);
        } else if (!remoteItem.isDeleted()) {
            remoteItem.setStatus(status);
            remoteItem.setSynchronization(isAccountSynchronize(remoteItem.getJid()));
            resultList.add(remoteItem);
        }
    }
    // add local accounts to list
    Collection<AccountItem> localAccounts = AccountManager.getInstance().getAllAccountItems();
    for (AccountItem localAccount : localAccounts) {
        String localJid = localAccount.getAccount().getFullJid().asBareJid().toString();
        boolean exist = false;
        for (XMPPAccountSettings remoteItem : remoteList) {
            if (localJid.equals(remoteItem.getJid())) {
                exist = true;
            }
        }
        if (!exist) {
            XMPPAccountSettings localItem = new XMPPAccountSettings(localJid, false, localAccount.getTimestamp());
            localItem.setOrder(remoteList.size() + localAccount.getOrder());
            localItem.setColor(ColorManager.getInstance().convertIndexToColorName(localAccount.getColorIndex()));
            localItem.setStatus(XMPPAccountSettings.SyncStatus.local);
            localItem.setSynchronization(isAccountSynchronize(localItem.getJid()));
            localItem.setSyncNotAllowed(localAccount.isSyncNotAllowed());
            resultList.add(localItem);
        }
    }
    return resultList;
}
Also used : AccountItem(com.xabber.android.data.account.AccountItem) AccountJid(com.xabber.android.data.entity.AccountJid) ArrayList(java.util.ArrayList)

Aggregations

AccountItem (com.xabber.android.data.account.AccountItem)96 AccountJid (com.xabber.android.data.entity.AccountJid)24 UserJid (com.xabber.android.data.entity.UserJid)14 View (android.view.View)12 NetworkException (com.xabber.android.data.NetworkException)11 ArrayList (java.util.ArrayList)11 SmackException (org.jivesoftware.smack.SmackException)11 ExtensionElement (org.jivesoftware.smack.packet.ExtensionElement)11 Message (org.jivesoftware.smack.packet.Message)11 Presence (org.jivesoftware.smack.packet.Presence)10 TextView (android.widget.TextView)9 XMPPException (org.jivesoftware.smack.XMPPException)9 Jid (org.jxmpp.jid.Jid)9 ImageView (android.widget.ImageView)8 StatusMode (com.xabber.android.data.account.StatusMode)6 ConnectionState (com.xabber.android.data.connection.ConnectionState)5 MessageItem (com.xabber.android.data.database.messagerealm.MessageItem)5 Realm (io.realm.Realm)5 ColorDrawable (android.graphics.drawable.ColorDrawable)4 AccountManager (com.xabber.android.data.account.AccountManager)4