use of com.xabber.android.data.roster.RosterContact in project xabber-android by redsolution.
the class NextMamManager method loadLastMessagesAsync.
private void loadLastMessagesAsync(AccountItem accountItem) {
if (accountItem.getLoadHistorySettings() != LoadHistorySettings.all || !isSupported(accountItem.getAccount()))
return;
LogManager.d(LOG_TAG, "load last messages in each chat");
Collection<RosterContact> contacts = RosterManager.getInstance().getAccountRosterContacts(accountItem.getAccount());
for (RosterContact contact : contacts) {
AbstractChat chat = MessageManager.getInstance().getOrCreateChat(contact.getAccount(), contact.getUser());
requestLastMessageAsync(accountItem, chat);
}
}
use of com.xabber.android.data.roster.RosterContact in project xabber-android by redsolution.
the class NextMamManager method loadLastMessagesInMissedChatsAsync.
/**
* MAIN
*/
/**
* For load messages that was missed because of errors or crash
*/
private void loadLastMessagesInMissedChatsAsync(Realm realm, AccountItem accountItem) {
if (accountItem.getLoadHistorySettings() != LoadHistorySettings.all || !isSupported(accountItem.getAccount()))
return;
Collection<RosterContact> contacts = RosterManager.getInstance().getAccountRosterContacts(accountItem.getAccount());
for (RosterContact contact : contacts) {
AbstractChat chat = MessageManager.getInstance().getOrCreateChat(contact.getAccount(), contact.getUser());
if (getFirstMessage(chat, realm) == null && !chat.isHistoryRequestedAtStart()) {
LogManager.d(LOG_TAG, "load missed messages in: " + contact.getUser());
requestLastMessageAsync(accountItem, chat);
}
}
}
use of com.xabber.android.data.roster.RosterContact in project xabber-android by redsolution.
the class VCardManager method onRosterReceived.
@Override
public void onRosterReceived(AccountItem accountItem) {
AccountJid account = accountItem.getAccount();
if (!accountRequested.contains(account) && SettingsManager.connectionLoadVCard()) {
BareJid bareAddress = accountItem.getRealJid().asBareJid();
if (bareAddress != null && !names.containsKey(bareAddress)) {
request(account, bareAddress);
accountRequested.add(account);
}
}
Collection<RosterContact> accountRosterContacts = RosterManager.getInstance().getAccountRosterContacts(account);
// Request vCards for new contacts.
for (RosterContact contact : accountRosterContacts) {
if (!names.containsKey(contact.getUser().getJid())) {
request(account, contact.getUser().getJid());
}
}
}
use of com.xabber.android.data.roster.RosterContact in project xabber-android by redsolution.
the class VCardManager method onVCardReceived.
@SuppressWarnings("WeakerAccess")
void onVCardReceived(final AccountJid account, final Jid bareAddress, final VCard vCard) {
final StructuredName name;
if (vCard.getType() == Type.error) {
onVCardFailed(account, bareAddress);
if (names.containsKey(bareAddress)) {
return;
}
name = EMPTY_STRUCTURED_NAME;
} else {
try {
String hash = vCard.getAvatarHash();
byte[] avatar = vCard.getAvatar();
AvatarManager.getInstance().onAvatarReceived(bareAddress, hash, avatar);
// "bad base-64" error happen sometimes
} catch (IllegalArgumentException e) {
LogManager.exception(this, e);
}
name = new StructuredName(vCard.getNickName(), vCard.getField(VCardProperty.FN.name()), vCard.getFirstName(), vCard.getMiddleName(), vCard.getLastName());
// try {
// if (account.getFullJid().asBareJid().equals(bareAddress.asBareJid())) {
// PresenceManager.getInstance().resendPresence(account);
// }
// } catch (NetworkException e) {
// LogManager.exception(this, e);
// }
}
names.put(bareAddress, name);
RosterContact rosterContact = RosterManager.getInstance().getRosterContact(account, bareAddress.asBareJid());
for (OnRosterChangedListener listener : Application.getInstance().getManagers(OnRosterChangedListener.class)) {
listener.onContactStructuredInfoChanged(rosterContact, name);
}
Application.getInstance().runInBackground(new Runnable() {
@Override
public void run() {
VCardTable.getInstance().write(bareAddress.toString(), name);
}
});
if (vCard.getFrom() == null) {
// account it self
AccountManager.getInstance().onAccountChanged(account);
} else {
try {
RosterManager.onContactChanged(account, UserJid.from(bareAddress));
} catch (UserJid.UserJidCreateException e) {
LogManager.exception(this, e);
}
}
for (OnVCardListener listener : Application.getInstance().getUIListeners(OnVCardListener.class)) {
listener.onVCardReceived(account, bareAddress, vCard);
}
}
Aggregations