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);
}
});
}
});
}
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);
}
});
}
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();
}
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;
}
}
});
}
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);
}
}
});
}
}
Aggregations