use of com.xabber.android.data.database.realm.ContactRealm in project xabber-android by redsolution.
the class RosterCacheManager method removeContacts.
public static void removeContacts(AccountJid account) {
String accountJid = account.getFullJid().asBareJid().toString();
Realm realm = MessageDatabaseManager.getInstance().getRealmUiThread();
RealmResults<ContactRealm> results = realm.where(ContactRealm.class).equalTo(ContactRealm.Fields.ACCOUNT, accountJid).findAll();
realm.beginTransaction();
results.deleteAllFromRealm();
realm.commitTransaction();
}
use of com.xabber.android.data.database.realm.ContactRealm in project xabber-android by redsolution.
the class RosterCacheManager method saveContact.
public static void saveContact(AccountJid accountJid, Collection<RosterContact> contacts) {
Realm realm = MessageDatabaseManager.getInstance().getRealmUiThread();
realm.beginTransaction();
if (contacts.size() > 1) {
RealmResults<ContactRealm> results = realm.where(ContactRealm.class).equalTo(ContactRealm.Fields.ACCOUNT, accountJid.getFullJid().asBareJid().toString()).findAll();
results.deleteAllFromRealm();
}
List<ContactRealm> newContacts = new ArrayList<>();
for (RosterContact contact : contacts) {
String account = contact.getAccount().getFullJid().asBareJid().toString();
String user = contact.getUser().getBareJid().toString();
ContactRealm contactRealm = realm.where(ContactRealm.class).equalTo(ContactRealm.Fields.ID, account + "/" + user).findFirst();
if (contactRealm == null) {
contactRealm = new ContactRealm(account + "/" + user);
}
RealmList<ContactGroup> groups = new RealmList<>();
for (String groupName : contact.getGroupNames()) {
ContactGroup group = realm.copyToRealmOrUpdate(new ContactGroup(groupName));
if (group.isManaged() && group.isValid())
groups.add(group);
}
contactRealm.setGroups(groups);
contactRealm.setAccount(account);
contactRealm.setUser(user);
contactRealm.setName(contact.getName());
contactRealm.setAccountResource(contact.getAccount().getFullJid().getResourcepart().toString());
newContacts.add(contactRealm);
}
realm.copyToRealmOrUpdate(newContacts);
realm.commitTransaction();
}
use of com.xabber.android.data.database.realm.ContactRealm in project xabber-android by redsolution.
the class RosterManager method onPreInitialize.
public void onPreInitialize() {
List<ContactRealm> contacts = RosterCacheManager.loadContacts();
for (ContactRealm contactRealm : contacts) {
try {
AccountJid account = AccountJid.from(contactRealm.getAccount() + "/" + contactRealm.getAccountResource());
UserJid userJid = UserJid.from(contactRealm.getUser());
RosterContact contact = RosterContact.getRosterContact(account, userJid, contactRealm.getName());
for (ContactGroup group : contactRealm.getGroups()) {
contact.addGroupReference(new RosterGroupReference(new RosterGroup(account, group.getGroupName())));
}
rosterContacts.put(contact.getAccount().toString(), contact.getUser().getBareJid().toString(), contact);
MessageItem lastMessage = contactRealm.getLastMessage();
if (lastMessage != null) {
MessageManager.getInstance().getOrCreateChat(contact.getAccount(), contact.getUser(), lastMessage);
} else
MessageManager.getInstance().getOrCreateChat(contact.getAccount(), contact.getUser());
} catch (UserJid.UserJidCreateException e) {
e.printStackTrace();
} catch (XmppStringprepException e) {
e.printStackTrace();
}
}
onContactsChanged(Collections.<RosterContact>emptyList());
}
use of com.xabber.android.data.database.realm.ContactRealm in project xabber-android by redsolution.
the class RosterCacheManager method removeContact.
public static void removeContact(Collection<RosterContact> contacts) {
Realm realm = MessageDatabaseManager.getInstance().getRealmUiThread();
realm.beginTransaction();
for (RosterContact contact : contacts) {
String account = contact.getAccount().getFullJid().asBareJid().toString();
String user = contact.getUser().getBareJid().toString();
ContactRealm contactRealm = realm.where(ContactRealm.class).equalTo(ContactRealm.Fields.ID, account + "/" + user).findFirst();
if (contactRealm != null)
contactRealm.deleteFromRealm();
}
realm.commitTransaction();
}
Aggregations