Search in sources :

Example 51 with UserJid

use of com.xabber.android.data.entity.UserJid 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 52 with UserJid

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

the class PresenceManager method onPresenceChanged.

public void onPresenceChanged(AccountJid account, Presence presence) {
    UserJid from;
    try {
        from = UserJid.from(presence.getFrom());
    } catch (UserJid.UserJidCreateException e) {
        LogManager.exception(this, e);
        return;
    }
    if (presence.isAvailable()) {
        CapabilitiesManager.getInstance().onPresence(account, presence);
    }
    if (presence.getType() == Presence.Type.unavailable)
        LastActivityInteractor.getInstance().setLastActivityTimeNow(account, from.getBareUserJid());
    for (OnStatusChangeListener listener : Application.getInstance().getManagers(OnStatusChangeListener.class)) {
        listener.onStatusChanged(account, from, StatusMode.createStatusMode(presence), presence.getStatus());
    }
    RosterContact rosterContact = RosterManager.getInstance().getRosterContact(account, from.getBareJid());
    if (rosterContact != null) {
        ArrayList<RosterContact> rosterContacts = new ArrayList<>();
        rosterContacts.add(rosterContact);
        for (OnRosterChangedListener listener : Application.getInstance().getManagers(OnRosterChangedListener.class)) {
            listener.onPresenceChanged(rosterContacts);
        }
    }
    RosterManager.onContactChanged(account, from);
}
Also used : ArrayList(java.util.ArrayList) UserJid(com.xabber.android.data.entity.UserJid)

Example 53 with UserJid

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

the class OccupantListActivity method onItemClick.

@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
    com.xabber.android.data.extension.muc.Occupant occupant = (com.xabber.android.data.extension.muc.Occupant) listAdapter.getItem(position);
    LogManager.i(this, occupant.getNickname().toString());
    UserJid occupantFullJid = null;
    try {
        occupantFullJid = UserJid.from(JidCreate.entityFullFrom(room, occupant.getNickname()));
    } catch (UserJid.UserJidCreateException e) {
        LogManager.exception(this, e);
        return;
    }
    final AbstractChat mucPrivateChat;
    try {
        mucPrivateChat = MessageManager.getInstance().getOrCreatePrivateMucChat(account, occupantFullJid.getJid().asFullJidIfPossible());
    } catch (UserJid.UserJidCreateException e) {
        LogManager.exception(this, e);
        return;
    }
    mucPrivateChat.setIsPrivateMucChatAccepted(true);
    startActivity(ChatActivity.createSpecificChatIntent(this, account, occupantFullJid));
}
Also used : AbstractChat(com.xabber.android.data.message.AbstractChat) UserJid(com.xabber.android.data.entity.UserJid)

Example 54 with UserJid

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

the class BlockingManager method onAuthorized.

public void onAuthorized(final ConnectionItem connection) {
    final AccountJid account = connection.getAccount();
    BlockingCommandManager blockingCommandManager = BlockingCommandManager.getInstanceFor(connection.getConnection());
    try {
        boolean supportedByServer = blockingCommandManager.isSupportedByServer();
        if (supportedByServer) {
            // cache block list inside
            List<UserJid> blockedContacts = new ArrayList<>();
            try {
                List<Jid> blockedJids = blockingCommandManager.getBlockList();
                for (Jid jid : blockedJids) {
                    blockedContacts.add(UserJid.from(jid));
                }
            } catch (SmackException.NoResponseException | XMPPException.XMPPErrorException | InterruptedException | SmackException.NotConnectedException | UserJid.UserJidCreateException e) {
                LogManager.exception(LOG_TAG, e);
            }
            // Cache block inside manager
            // For contact list building used only this list of blocked contacts
            updateCachedBlockedContacts(account, blockedContacts);
        }
        addBlockedListener(blockingCommandManager, account);
        addUnblockedListener(blockingCommandManager, account);
        addUnblockedAllListener(blockingCommandManager, account);
        // block list already cached successfully
        supportForAccounts.put(account, supportedByServer);
        BlockingManager.notify(account);
    } catch (SmackException.NotConnectedException | XMPPException.XMPPErrorException | SmackException.NoResponseException | InterruptedException e) {
        LogManager.exception(this, e);
    }
}
Also used : UserJid(com.xabber.android.data.entity.UserJid) Jid(org.jxmpp.jid.Jid) AccountJid(com.xabber.android.data.entity.AccountJid) ArrayList(java.util.ArrayList) UserJid(com.xabber.android.data.entity.UserJid) BlockingCommandManager(org.jivesoftware.smackx.blocking.BlockingCommandManager) AccountJid(com.xabber.android.data.entity.AccountJid)

Example 55 with UserJid

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

the class BlockingManager method getBlockedContacts.

public List<UserJid> getBlockedContacts(AccountJid account) {
    List<UserJid> blockedContacts = new ArrayList<>();
    Boolean supported = isSupported(account);
    BlockingCommandManager blockingCommandManager = getBlockingCommandManager(account);
    if (blockingCommandManager != null && supported != null && supported) {
        try {
            List<Jid> blockedJids = blockingCommandManager.getBlockList();
            for (Jid jid : blockedJids) {
                blockedContacts.add(UserJid.from(jid));
            }
        } catch (SmackException.NoResponseException | XMPPException.XMPPErrorException | InterruptedException | SmackException.NotConnectedException | UserJid.UserJidCreateException e) {
            LogManager.exception(LOG_TAG, e);
        }
    }
    updateCachedBlockedContacts(account, blockedContacts);
    return blockedContacts;
}
Also used : UserJid(com.xabber.android.data.entity.UserJid) Jid(org.jxmpp.jid.Jid) AccountJid(com.xabber.android.data.entity.AccountJid) ArrayList(java.util.ArrayList) UserJid(com.xabber.android.data.entity.UserJid) BlockingCommandManager(org.jivesoftware.smackx.blocking.BlockingCommandManager)

Aggregations

UserJid (com.xabber.android.data.entity.UserJid)67 AccountJid (com.xabber.android.data.entity.AccountJid)43 AbstractChat (com.xabber.android.data.message.AbstractChat)15 ArrayList (java.util.ArrayList)15 Intent (android.content.Intent)9 Jid (org.jxmpp.jid.Jid)9 Presence (org.jivesoftware.smack.packet.Presence)8 XmppStringprepException (org.jxmpp.stringprep.XmppStringprepException)8 AccountItem (com.xabber.android.data.account.AccountItem)7 AbstractContact (com.xabber.android.data.roster.AbstractContact)6 Message (org.jivesoftware.smack.packet.Message)6 Resourcepart (org.jxmpp.jid.parts.Resourcepart)6 NetworkException (com.xabber.android.data.NetworkException)5 IFlexible (eu.davidea.flexibleadapter.items.IFlexible)5 SmackException (org.jivesoftware.smack.SmackException)5 Uri (android.net.Uri)4 ContactVO (com.xabber.android.presentation.ui.contactlist.viewobjects.ContactVO)4 DomainBareJid (org.jxmpp.jid.DomainBareJid)4 TextView (android.widget.TextView)3 MessageItem (com.xabber.android.data.database.messagerealm.MessageItem)3