Search in sources :

Example 1 with BlockingCommandManager

use of org.jivesoftware.smackx.blocking.BlockingCommandManager 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)

Example 2 with BlockingCommandManager

use of org.jivesoftware.smackx.blocking.BlockingCommandManager 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)

Aggregations

AccountJid (com.xabber.android.data.entity.AccountJid)2 UserJid (com.xabber.android.data.entity.UserJid)2 ArrayList (java.util.ArrayList)2 BlockingCommandManager (org.jivesoftware.smackx.blocking.BlockingCommandManager)2 Jid (org.jxmpp.jid.Jid)2