Search in sources :

Example 31 with AccountItem

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

the class AttentionManager method onSettingsChanged.

public void onSettingsChanged() {
    synchronized (enabledLock) {
        for (AccountJid account : AccountManager.getInstance().getEnabledAccounts()) {
            AccountItem accountItem = AccountManager.getInstance().getAccount(account);
            if (accountItem == null) {
                continue;
            }
            ServiceDiscoveryManager manager = ServiceDiscoveryManager.getInstanceFor(accountItem.getConnection());
            if (manager == null) {
                continue;
            }
            boolean contains = false;
            for (String feature : manager.getFeatures()) {
                if (AttentionExtension.NAMESPACE.equals(feature)) {
                    contains = true;
                }
            }
            if (SettingsManager.chatsAttention() == contains) {
                continue;
            }
            if (SettingsManager.chatsAttention()) {
                manager.addFeature(AttentionExtension.NAMESPACE);
            } else {
                manager.removeFeature(AttentionExtension.NAMESPACE);
            }
        }
        AccountManager.getInstance().resendPresence();
    }
}
Also used : AccountItem(com.xabber.android.data.account.AccountItem) AccountJid(com.xabber.android.data.entity.AccountJid) ServiceDiscoveryManager(org.jivesoftware.smackx.disco.ServiceDiscoveryManager)

Example 32 with AccountItem

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

the class ChatMarkerManager method isClientSupportChatMarkers.

private boolean isClientSupportChatMarkers(AccountJid account, UserJid user) {
    AccountItem accountItem = AccountManager.getInstance().getAccount(account);
    if (accountItem == null)
        return false;
    XMPPConnection connection = accountItem.getConnection();
    final List<Presence> allPresences = RosterManager.getInstance().getPresences(account, user.getJid());
    boolean isChatMarkersSupport = false;
    for (Presence presence : allPresences) {
        Jid fromJid = presence.getFrom();
        DiscoverInfo discoverInfo = null;
        try {
            discoverInfo = ServiceDiscoveryManager.getInstanceFor(connection).discoverInfo(fromJid);
        } catch (SmackException.NoResponseException | XMPPException.XMPPErrorException | SmackException.NotConnectedException | InterruptedException | ClassCastException e) {
            e.printStackTrace();
        }
        isChatMarkersSupport = discoverInfo != null && discoverInfo.containsFeature(ChatMarkersElements.NAMESPACE);
        if (isChatMarkersSupport)
            break;
    }
    return isChatMarkersSupport;
}
Also used : DiscoverInfo(org.jivesoftware.smackx.disco.packet.DiscoverInfo) UserJid(com.xabber.android.data.entity.UserJid) AccountJid(com.xabber.android.data.entity.AccountJid) Jid(org.jxmpp.jid.Jid) AccountItem(com.xabber.android.data.account.AccountItem) XMPPConnection(org.jivesoftware.smack.XMPPConnection) Presence(org.jivesoftware.smack.packet.Presence)

Example 33 with AccountItem

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

the class AvatarManager method onStanza.

@Override
public void onStanza(ConnectionItem connection, Stanza stanza) {
    if (!(stanza instanceof Presence)) {
        return;
    }
    AccountJid account = ((AccountItem) connection).getAccount();
    Presence presence = (Presence) stanza;
    if (presence.getType() == Presence.Type.error) {
        return;
    }
    for (ExtensionElement packetExtension : presence.getExtensions()) {
        if (packetExtension instanceof VCardUpdate) {
            VCardUpdate vCardUpdate = (VCardUpdate) packetExtension;
            if (vCardUpdate.isValid() && vCardUpdate.isPhotoReady()) {
                try {
                    onPhotoReady(account, UserJid.from(stanza.getFrom()), vCardUpdate);
                } catch (UserJid.UserJidCreateException e) {
                    LogManager.exception(this, e);
                }
            }
        }
    }
}
Also used : AccountItem(com.xabber.android.data.account.AccountItem) AccountJid(com.xabber.android.data.entity.AccountJid) ExtensionElement(org.jivesoftware.smack.packet.ExtensionElement) Presence(org.jivesoftware.smack.packet.Presence) UserJid(com.xabber.android.data.entity.UserJid) VCardUpdate(com.xabber.xmpp.vcardupdate.VCardUpdate)

Example 34 with AccountItem

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

the class BookmarksManager method getConferencesFromBookmarks.

@NonNull
public List<BookmarkedConference> getConferencesFromBookmarks(AccountJid accountJid) throws SmackException.NoResponseException, SmackException.NotConnectedException, InterruptedException, XMPPException.XMPPErrorException {
    AccountItem accountItem = AccountManager.getInstance().getAccount(accountJid);
    List<BookmarkedConference> conferences = Collections.emptyList();
    if (accountItem != null) {
        BookmarkManager bookmarkManager = BookmarkManager.getBookmarkManager(accountItem.getConnection());
        conferences = bookmarkManager.getBookmarkedConferences();
    }
    return conferences;
}
Also used : AccountItem(com.xabber.android.data.account.AccountItem) BookmarkedConference(org.jivesoftware.smackx.bookmarks.BookmarkedConference) BookmarkManager(org.jivesoftware.smackx.bookmarks.BookmarkManager) NonNull(androidx.annotation.NonNull)

Example 35 with AccountItem

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

the class PrivateStorageManager method setPrivateData.

private void setPrivateData(AccountJid accountJid, PrivateData privateData) {
    AccountItem accountItem = AccountManager.getInstance().getAccount(accountJid);
    if (accountItem == null || !accountItem.isEnabled())
        return;
    XMPPTCPConnection connection = accountItem.getConnection();
    PrivateDataManager privateDataManager = PrivateDataManager.getInstanceFor(connection);
    try {
        if (!privateDataManager.isSupported())
            return;
        privateDataManager.setPrivateData(privateData);
    } catch (SmackException.NoResponseException | XMPPException.XMPPErrorException | SmackException.NotConnectedException | InterruptedException | IllegalArgumentException e) {
        e.printStackTrace();
    }
}
Also used : XMPPTCPConnection(com.xabber.xmpp.smack.XMPPTCPConnection) AccountItem(com.xabber.android.data.account.AccountItem) PrivateDataManager(org.jivesoftware.smackx.iqprivate.PrivateDataManager)

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