Search in sources :

Example 61 with AccountJid

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

the class NotificationManager method onMessageNotification.

public void onMessageNotification(MessageItem messageItem) {
    MessageNotification messageNotification = getMessageNotification(messageItem.getAccount(), messageItem.getUser());
    if (messageNotification == null) {
        messageNotification = new MessageNotification(messageItem.getAccount(), messageItem.getUser(), null, null, 0);
    } else {
        messageNotifications.remove(messageNotification);
    }
    messageNotification.addMessage(messageItem.getText());
    messageNotifications.add(messageNotification);
    final AccountJid account = messageNotification.getAccount();
    final UserJid user = messageNotification.getUser();
    final String text = messageNotification.getText();
    final Date timestamp = messageNotification.getTimestamp();
    final int count = messageNotification.getCount();
    Application.getInstance().runInBackgroundUserRequest(new Runnable() {

        @Override
        public void run() {
            NotificationTable.getInstance().write(account.toString(), user.toString(), text, timestamp, count);
        }
    });
    updateMessageNotification(messageItem);
}
Also used : AccountJid(com.xabber.android.data.entity.AccountJid) UserJid(com.xabber.android.data.entity.UserJid) Date(java.util.Date) SuppressLint(android.annotation.SuppressLint)

Example 62 with AccountJid

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

the class PresenceManager method onStanza.

@Override
public void onStanza(ConnectionItem connection, Stanza stanza) {
    if (!(connection instanceof AccountItem)) {
        return;
    }
    if (!(stanza instanceof Presence)) {
        return;
    }
    Presence presence = (Presence) stanza;
    UserJid from;
    try {
        from = UserJid.from(stanza.getFrom());
    } catch (UserJid.UserJidCreateException e) {
        LogManager.exception(this, e);
        return;
    }
    if (presence.getType() == Presence.Type.subscribe) {
        AccountJid account = connection.getAccount();
        // reject all subscribe-requests
        if (SettingsManager.spamFilterMode() == SettingsManager.SpamFilterMode.noAuth) {
            // send a warning message to sender
            MessageManager.getInstance().sendMessageWithoutChat(from.getJid(), StringUtils.randomString(12), account, Application.getInstance().getResources().getString(R.string.spam_filter_ban_subscription));
            // and discard subscription
            try {
                discardSubscription(account, UserJid.from(from.toString()));
            } catch (NetworkException | UserJid.UserJidCreateException e) {
                e.printStackTrace();
            }
            return;
        }
        // require captcha for subscription
        if (SettingsManager.spamFilterMode() == SettingsManager.SpamFilterMode.authCaptcha) {
            Captcha captcha = CaptchaManager.getInstance().getCaptcha(account, from);
            // if captcha for this user already exist, check expires time and discard if need
            if (captcha != null) {
                if (captcha.getExpiresDate() < System.currentTimeMillis()) {
                    // discard subscription
                    try {
                        discardSubscription(account, UserJid.from(from.toString()));
                    } catch (NetworkException | UserJid.UserJidCreateException e) {
                        e.printStackTrace();
                    }
                    return;
                }
                // skip subscription, waiting for captcha in messageManager
                return;
            } else {
                // generate captcha
                String captchaQuestion = CaptchaManager.getInstance().generateAndSaveCaptcha(account, from);
                // send captcha message to sender
                MessageManager.getInstance().sendMessageWithoutChat(from.getJid(), StringUtils.randomString(12), account, Application.getInstance().getResources().getString(R.string.spam_filter_limit_subscription) + " " + captchaQuestion);
                // and skip subscription, waiting for captcha in messageManager
                return;
            }
        }
        // subscription request
        handleSubscriptionRequest(account, from);
    }
}
Also used : Captcha(com.xabber.android.data.extension.captcha.Captcha) AccountItem(com.xabber.android.data.account.AccountItem) AccountJid(com.xabber.android.data.entity.AccountJid) Presence(org.jivesoftware.smack.packet.Presence) UserJid(com.xabber.android.data.entity.UserJid) NetworkException(com.xabber.android.data.NetworkException)

Example 63 with AccountJid

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

the class RosterManager method onContactsDeleted.

void onContactsDeleted(AccountJid account, Collection<Jid> addresses) {
    Collection<RosterContact> removedContacts = new ArrayList<>(addresses.size());
    for (Jid jid : addresses) {
        RosterContact contact = rosterContacts.remove(account.toString(), jid.asBareJid().toString());
        if (contact != null) {
            removedContacts.add(contact);
        }
    }
    onContactsChanged(removedContacts);
}
Also used : UserJid(com.xabber.android.data.entity.UserJid) AccountJid(com.xabber.android.data.entity.AccountJid) Jid(org.jxmpp.jid.Jid) BareJid(org.jxmpp.jid.BareJid) ArrayList(java.util.ArrayList)

Example 64 with AccountJid

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

the class RosterManager method onContactsAdded.

void onContactsAdded(AccountJid account, Collection<Jid> addresses) {
    final Roster roster = RosterManager.getInstance().getRoster(account);
    Collection<RosterContact> newContacts = new ArrayList<>(addresses.size());
    for (Jid jid : addresses) {
        RosterEntry entry = roster.getEntry(jid.asBareJid());
        try {
            RosterContact contact = convertRosterEntryToRosterContact(account, roster, entry);
            rosterContacts.put(account.toString(), contact.getUser().getBareJid().toString(), contact);
            newContacts.add(contact);
        } catch (UserJid.UserJidCreateException e) {
            LogManager.exception(LOG_TAG, e);
        }
    }
    onContactsChanged(newContacts);
}
Also used : Roster(org.jivesoftware.smack.roster.Roster) UserJid(com.xabber.android.data.entity.UserJid) AccountJid(com.xabber.android.data.entity.AccountJid) Jid(org.jxmpp.jid.Jid) BareJid(org.jxmpp.jid.BareJid) ArrayList(java.util.ArrayList) UserJid(com.xabber.android.data.entity.UserJid) RosterEntry(org.jivesoftware.smack.roster.RosterEntry)

Example 65 with AccountJid

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

the class XabberAccountManager method updateLocalAccount.

public void updateLocalAccount(XMPPAccountSettings account) {
    // if account synced
    if (isAccountSynchronize(account.getJid()) || SettingsManager.isSyncAllAccounts()) {
        AccountJid accountJid = getExistingAccount(account.getJid());
        // create new xmpp-account
        if (accountJid == null && !account.isDeleted()) {
            try {
                AccountJid jid = AccountManager.getInstance().addAccount(account.getJid(), "", account.getToken(), false, true, true, false, false, true);
                AccountManager.getInstance().setColor(jid, ColorManager.getInstance().convertColorNameToIndex(account.getColor()));
                AccountManager.getInstance().setOrder(jid, account.getOrder());
                AccountManager.getInstance().setTimestamp(jid, account.getTimestamp());
                AccountManager.getInstance().onAccountChanged(jid);
            } catch (NetworkException e) {
                Application.getInstance().onError(e);
            }
        // update existing xmpp-account
        // now we are updated only color of account
        } else if (accountJid != null && !account.isDeleted()) {
            AccountManager.getInstance().setOrder(accountJid, account.getOrder());
            AccountManager.getInstance().setTimestamp(accountJid, account.getTimestamp());
            AccountManager.getInstance().setColor(accountJid, ColorManager.getInstance().convertColorNameToIndex(account.getColor()));
            AccountManager.getInstance().onAccountChanged(accountJid);
        // delete existing account
        } else if (accountJid != null && account.isDeleted()) {
            AccountManager.getInstance().removeAccountWithoutSync(accountJid);
        }
    }
}
Also used : AccountJid(com.xabber.android.data.entity.AccountJid) NetworkException(com.xabber.android.data.NetworkException)

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