Search in sources :

Example 21 with RosterContact

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);
    }
}
Also used : RosterContact(com.xabber.android.data.roster.RosterContact) AbstractChat(com.xabber.android.data.message.AbstractChat)

Example 22 with RosterContact

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);
        }
    }
}
Also used : RosterContact(com.xabber.android.data.roster.RosterContact) AbstractChat(com.xabber.android.data.message.AbstractChat)

Example 23 with RosterContact

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());
        }
    }
}
Also used : RosterContact(com.xabber.android.data.roster.RosterContact) EntityBareJid(org.jxmpp.jid.EntityBareJid) BareJid(org.jxmpp.jid.BareJid) AccountJid(com.xabber.android.data.entity.AccountJid)

Example 24 with RosterContact

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);
    }
}
Also used : OnRosterChangedListener(com.xabber.android.data.roster.OnRosterChangedListener) RosterContact(com.xabber.android.data.roster.RosterContact) UserJid(com.xabber.android.data.entity.UserJid) StructuredName(com.xabber.android.data.roster.StructuredName)

Aggregations

RosterContact (com.xabber.android.data.roster.RosterContact)24 AbstractChat (com.xabber.android.data.message.AbstractChat)11 ArrayList (java.util.ArrayList)8 RoomChat (com.xabber.android.data.extension.muc.RoomChat)6 AccountJid (com.xabber.android.data.entity.AccountJid)5 UserJid (com.xabber.android.data.entity.UserJid)5 RoomContact (com.xabber.android.data.extension.muc.RoomContact)5 ChatContact (com.xabber.android.data.message.ChatContact)5 AbstractContact (com.xabber.android.data.roster.AbstractContact)5 AlertDialog (android.app.AlertDialog)3 DialogInterface (android.content.DialogInterface)3 EditText (android.widget.EditText)3 CommonState (com.xabber.android.data.account.CommonState)3 EntityIntentBuilder (com.xabber.android.data.intent.EntityIntentBuilder)3 Collection (java.util.Collection)3 Map (java.util.Map)3 TreeMap (java.util.TreeMap)3 Intent (android.content.Intent)2 MessageItem (com.xabber.android.data.database.messagerealm.MessageItem)2 BaseEntity (com.xabber.android.data.entity.BaseEntity)2