Search in sources :

Example 81 with AccountItem

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

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

the class PresenceManager method sendVCardUpdatePresence.

public void sendVCardUpdatePresence(AccountJid account, String hash) throws NetworkException {
    LogManager.i(this, "sendVCardUpdatePresence: " + account);
    AccountItem accountItem = AccountManager.getInstance().getAccount(account);
    if (accountItem == null) {
        return;
    }
    final Presence presence = accountItem.getPresence();
    final VCardUpdate vCardUpdate = new VCardUpdate();
    vCardUpdate.setPhotoHash(hash);
    presence.addExtension(vCardUpdate);
    StanzaSender.sendStanza(account, presence);
}
Also used : AccountItem(com.xabber.android.data.account.AccountItem) Presence(org.jivesoftware.smack.packet.Presence) VCardUpdate(com.xabber.xmpp.vcardupdate.VCardUpdate)

Example 83 with AccountItem

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

the class PushManager method onStanza.

@Override
public void onStanza(ConnectionItem connection, Stanza packet) {
    if (packet instanceof IQ && ((IQ) packet).getType() != IQ.Type.error) {
        if (waitingIQs.containsKey(packet.getStanzaId())) {
            AccountJid account = connection.getAccount();
            AccountItem accountItem = AccountManager.getInstance().getAccount(account);
            Boolean enable = waitingIQs.get(packet.getStanzaId());
            if (accountItem != null && enable != null) {
                AccountManager.getInstance().setPushWasEnabled(accountItem, enable);
            }
            waitingIQs.remove(packet.getStanzaId());
        }
    }
}
Also used : AccountItem(com.xabber.android.data.account.AccountItem) AccountJid(com.xabber.android.data.entity.AccountJid) EnablePushNotificationsIQ(org.jivesoftware.smackx.push_notifications.element.EnablePushNotificationsIQ) IQ(org.jivesoftware.smack.packet.IQ)

Example 84 with AccountItem

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

the class PushManager method updateEnabledPushNodes.

public void updateEnabledPushNodes() {
    StringBuilder stringBuilder = new StringBuilder();
    for (AccountItem accountItem : AccountManager.getInstance().getAllAccountItems()) {
        String node = accountItem.getPushNode();
        if (accountItem.isEnabled() && accountItem.isPushEnabled() && accountItem.isPushWasEnabled() && node != null && !node.isEmpty()) {
            stringBuilder.append(node);
            stringBuilder.append(" ");
        }
    }
    SettingsManager.setEnabledPushNodes(stringBuilder.toString());
}
Also used : AccountItem(com.xabber.android.data.account.AccountItem)

Example 85 with AccountItem

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

the class AccountVO method convert.

public static AccountVO convert(AccountConfiguration configuration, AccountClickListener listener) {
    String jid;
    String name;
    String status;
    int statusLevel;
    int statusId;
    Drawable avatar;
    int offlineModeLevel;
    int accountColorIndicator;
    int accountColorIndicatorBack;
    String contactCount;
    AccountJid account = configuration.getAccount();
    accountColorIndicator = ColorManager.getInstance().getAccountPainter().getAccountMainColor(account);
    accountColorIndicatorBack = ColorManager.getInstance().getAccountPainter().getAccountIndicatorBackColor(account);
    jid = GroupManager.getInstance().getGroupName(account, configuration.getGroup());
    name = AccountManager.getInstance().getNickName(account);
    contactCount = configuration.getOnline() + "/" + configuration.getTotal();
    AccountItem accountItem = AccountManager.getInstance().getAccount(account);
    status = accountItem.getStatusText().trim();
    statusId = accountItem.getDisplayStatusMode().getStringID();
    avatar = AvatarManager.getInstance().getAccountAvatar(account);
    statusLevel = accountItem.getDisplayStatusMode().getStatusLevel();
    ShowOfflineMode showOfflineMode = configuration.getShowOfflineMode();
    if (showOfflineMode == ShowOfflineMode.normal) {
        if (SettingsManager.contactsShowOffline()) {
            showOfflineMode = ShowOfflineMode.always;
        } else {
            showOfflineMode = ShowOfflineMode.never;
        }
    }
    offlineModeLevel = showOfflineMode.ordinal();
    // custom notification
    boolean isCustomNotification = CustomNotifyPrefsManager.getInstance().isPrefsExist(Key.createKey(account));
    return new AccountVO(accountColorIndicator, accountColorIndicatorBack, name, jid, status, statusLevel, statusId, avatar, offlineModeLevel, contactCount, configuration.getAccount(), configuration.isExpanded(), configuration.getGroup(), isCustomNotification, listener);
}
Also used : AccountItem(com.xabber.android.data.account.AccountItem) AccountJid(com.xabber.android.data.entity.AccountJid) Drawable(android.graphics.drawable.Drawable) ShowOfflineMode(com.xabber.android.data.roster.ShowOfflineMode)

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