Search in sources :

Example 26 with AccountItem

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

the class MUCManager method requestRoomInfo.

public static void requestRoomInfo(final AccountJid account, final EntityBareJid roomJid, final RoomInfoListener listener) {
    AccountItem accountItem = AccountManager.getInstance().getAccount(account);
    if (accountItem == null) {
        listener.onRoomInfoReceived(null);
        return;
    }
    final XMPPConnection xmppConnection = accountItem.getConnection();
    if (!xmppConnection.isAuthenticated()) {
        listener.onRoomInfoReceived(null);
        return;
    }
    Application.getInstance().runInBackgroundUserRequest(new Runnable() {

        @Override
        public void run() {
            RoomInfo roomInfo = null;
            try {
                LogManager.i(MUCManager.class, "Requesting room info " + roomJid);
                roomInfo = MultiUserChatManager.getInstanceFor(xmppConnection).getRoomInfo(roomJid);
            } catch (SmackException.NoResponseException | XMPPException.XMPPErrorException | SmackException.NotConnectedException | InterruptedException e) {
                LogManager.exception(this, e);
            }
            final RoomInfo finalRoomInfo = roomInfo;
            Application.getInstance().runOnUiThread(new Runnable() {

                @Override
                public void run() {
                    listener.onRoomInfoReceived(finalRoomInfo);
                }
            });
        }
    });
}
Also used : AccountItem(com.xabber.android.data.account.AccountItem) SmackException(org.jivesoftware.smack.SmackException) RoomInfo(org.jivesoftware.smackx.muc.RoomInfo) XMPPConnection(org.jivesoftware.smack.XMPPConnection) XMPPException(org.jivesoftware.smack.XMPPException)

Example 27 with AccountItem

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

the class NextMamManager method onRequestUpdatePreferences.

public void onRequestUpdatePreferences(AccountJid accountJid) {
    final AccountItem accountItem = AccountManager.getInstance().getAccount(accountJid);
    if (accountItem == null || !isSupported(accountJid))
        return;
    Application.getInstance().runInBackgroundUserRequest(new Runnable() {

        @Override
        public void run() {
            requestUpdatePreferences(accountItem);
        }
    });
}
Also used : AccountItem(com.xabber.android.data.account.AccountItem)

Example 28 with AccountItem

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

the class NextMamManager method loadFullChatHistory.

public void loadFullChatHistory(AbstractChat chat) {
    final AccountItem accountItem = AccountManager.getInstance().getAccount(chat.getAccount());
    if (accountItem == null || !isSupported(accountItem.getAccount()) || chat.historyIsFull())
        return;
    Realm realm = MessageDatabaseManager.getInstance().getNewBackgroundRealm();
    // if history is empty - load last message
    MessageItem firstMessage = getFirstMessage(chat, realm);
    if (firstMessage == null)
        loadLastMessage(realm, accountItem, chat);
    boolean complete = false;
    while (!complete) {
        complete = loadNextHistory(realm, accountItem, chat);
    }
    realm.close();
}
Also used : MessageItem(com.xabber.android.data.database.messagerealm.MessageItem) AccountItem(com.xabber.android.data.account.AccountItem) Realm(io.realm.Realm)

Example 29 with AccountItem

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

the class NextMamManager method onScrollInChat.

public void onScrollInChat(final AbstractChat chat) {
    final AccountItem accountItem = AccountManager.getInstance().getAccount(chat.getAccount());
    if (accountItem == null || accountItem.getLoadHistorySettings() == LoadHistorySettings.none || !isSupported(accountItem.getAccount()))
        return;
    if (chat.historyIsFull())
        return;
    Application.getInstance().runInBackground(new Runnable() {

        @Override
        public void run() {
            synchronized (lock) {
                if (isRequested)
                    return;
                else
                    isRequested = true;
            }
            EventBus.getDefault().post(new LastHistoryLoadStartedEvent(chat));
            Realm realm = MessageDatabaseManager.getInstance().getNewBackgroundRealm();
            loadNextHistory(realm, accountItem, chat);
            realm.close();
            EventBus.getDefault().post(new LastHistoryLoadFinishedEvent(chat));
            synchronized (lock) {
                isRequested = false;
            }
        }
    });
}
Also used : AccountItem(com.xabber.android.data.account.AccountItem) Realm(io.realm.Realm)

Example 30 with AccountItem

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

the class CapabilitiesManager method updateClientInfo.

@SuppressWarnings("WeakerAccess")
void updateClientInfo(final AccountJid account, final Jid jid) {
    DiscoverInfo discoverInfo = EntityCapsManager.getDiscoverInfoByUser(jid);
    if (discoverInfo != null) {
        return;
    }
    AccountItem accountItem = AccountManager.getInstance().getAccount(account);
    if (accountItem == null) {
        return;
    }
    try {
        discoverInfo = ServiceDiscoveryManager.getInstanceFor(accountItem.getConnection()).discoverInfo(jid);
        EntityCapsManager.NodeVerHash nodeVerHashByJid = EntityCapsManager.getNodeVerHashByJid(jid);
        if (nodeVerHashByJid == null) {
            discoverInfoCache.put(jid, discoverInfo);
        }
        if (discoverInfo != null) {
            clientInfoCache.put(jid, ClientInfo.fromDiscoveryInfo(discoverInfo));
        }
    } catch (SmackException.NoResponseException | XMPPException.XMPPErrorException | InterruptedException | SmackException.NotConnectedException e) {
        LogManager.exception(this, e);
        clientInfoCache.put(jid, ClientInfo.INVALID_CLIENT_INFO);
    }
    RosterContact rosterContact = RosterManager.getInstance().getRosterContact(account, jid.asBareJid());
    if (rosterContact != null) {
        final ArrayList<RosterContact> rosterContacts = new ArrayList<>();
        rosterContacts.add(rosterContact);
        Application.getInstance().runOnUiThread(new Runnable() {

            @Override
            public void run() {
                for (OnContactChangedListener onContactChangedListener : Application.getInstance().getUIListeners(OnContactChangedListener.class)) {
                    onContactChangedListener.onContactsChanged(rosterContacts);
                }
            }
        });
    }
}
Also used : DiscoverInfo(org.jivesoftware.smackx.disco.packet.DiscoverInfo) RosterContact(com.xabber.android.data.roster.RosterContact) AccountItem(com.xabber.android.data.account.AccountItem) ArrayList(java.util.ArrayList) EntityCapsManager(org.jivesoftware.smackx.caps.EntityCapsManager) OnContactChangedListener(com.xabber.android.data.roster.OnContactChangedListener)

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