basic phone number sync

This commit is contained in:
Christian Schneppe 2018-11-23 08:58:55 +01:00
parent 35d5d97544
commit fce2177268
4 changed files with 32 additions and 10 deletions

View file

@ -5,7 +5,7 @@ import android.net.Uri;
import android.provider.ContactsContract;
import android.text.TextUtils;
abstract class AbstractPhoneContact {
public abstract class AbstractPhoneContact {
private final Uri lookupUri;
private final String displayName;

View file

@ -20,6 +20,7 @@ import java.util.Locale;
import de.pixart.messenger.Config;
import de.pixart.messenger.R;
import de.pixart.messenger.android.AbstractPhoneContact;
import de.pixart.messenger.utils.JidHelper;
import de.pixart.messenger.utils.UIHelper;
import de.pixart.messenger.xml.Element;
@ -579,6 +580,27 @@ public class Contact implements ListItem, Blockable {
return serverName;
}
public synchronized boolean setPhoneContact(AbstractPhoneContact phoneContact) {
setOption(getOption(phoneContact.getClass()));
setSystemAccount(phoneContact.getLookupUri());
boolean changed = setSystemName(phoneContact.getDisplayName());
changed |= setPhotoUri(phoneContact.getPhotoUri());
return changed;
}
public synchronized boolean unsetPhoneContact(Class<?extends AbstractPhoneContact> clazz) {
resetOption(getOption(clazz));
boolean changed = false;
if (!getOption(Options.SYNCED_VIA_ADDRESSBOOK) && !getOption(Options.SYNCED_VIA_OTHER)) {
setSystemAccount(null);
changed |= setPhotoUri(null);
changed |= setSystemName(null);
}
return changed;
}
public static int getOption(Class<? extends AbstractPhoneContact> clazz) {
return Options.SYNCED_VIA_OTHER;
}
public final class Options {
public static final int TO = 0;
public static final int FROM = 1;
@ -588,5 +610,7 @@ public class Contact implements ListItem, Blockable {
public static final int PENDING_SUBSCRIPTION_REQUEST = 5;
public static final int DIRTY_PUSH = 6;
public static final int DIRTY_DELETE = 7;
private static final int SYNCED_VIA_ADDRESSBOOK = 8;
private static final int SYNCED_VIA_OTHER = 9;
}
}

View file

@ -5,6 +5,7 @@ import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import de.pixart.messenger.android.AbstractPhoneContact;
import rocks.xmpp.addr.Jid;
public class Roster {
@ -54,11 +55,12 @@ public class Roster {
}
}
public List<Contact> getWithSystemAccounts() {
public List<Contact> getWithSystemAccounts(Class<?extends AbstractPhoneContact> clazz) {
int option = Contact.getOption(clazz);
List<Contact> with = getContacts();
for (Iterator<Contact> iterator = with.iterator(); iterator.hasNext(); ) {
Contact contact = iterator.next();
if (contact.getSystemAccount() == null) {
if (!contact.getOption(option)) {
iterator.remove();
}
}

View file

@ -1726,21 +1726,17 @@ public class XmppConnectionService extends Service {
Map<Jid, JabberIdContact> contacts = JabberIdContact.load(this);
Log.d(Config.LOGTAG, "start merging phone contacts with roster");
for (Account account : accounts) {
List<Contact> withSystemAccounts = account.getRoster().getWithSystemAccounts();
List<Contact> withSystemAccounts = account.getRoster().getWithSystemAccounts(JabberIdContact.class);
for (JabberIdContact jidContact : contacts.values()) {
final Contact contact = account.getRoster().getContact(jidContact.getJid());
contact.setSystemAccount(jidContact.getLookupUri());
boolean needsCacheClean = contact.setPhotoUri(jidContact.getPhotoUri());
needsCacheClean |= contact.setSystemName(jidContact.getDisplayName());
boolean needsCacheClean = contact.setPhoneContact(jidContact);
if (needsCacheClean) {
getAvatarService().clear(contact);
}
withSystemAccounts.remove(contact);
}
for (Contact contact : withSystemAccounts) {
contact.setSystemAccount(null);
boolean needsCacheClean = contact.setPhotoUri(null);
needsCacheClean |= contact.setSystemName(null);
boolean needsCacheClean = contact.unsetPhoneContact(JabberIdContact.class);
if (needsCacheClean) {
getAvatarService().clear(contact);
}