aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorChristian Schneppe <christian@pix-art.de>2018-11-23 08:58:55 +0100
committerChristian Schneppe <christian@pix-art.de>2018-11-23 08:58:55 +0100
commitfce2177268b9bcdf3c8bccea161450db63d651a8 (patch)
treeb6299a237c12f76eb4e22360c57b9305b7081f1f /src
parent35d5d97544cd6abc45809a19324898dfbf457467 (diff)
basic phone number sync
Diffstat (limited to 'src')
-rw-r--r--src/main/java/de/pixart/messenger/android/AbstractPhoneContact.java2
-rw-r--r--src/main/java/de/pixart/messenger/entities/Contact.java24
-rw-r--r--src/main/java/de/pixart/messenger/entities/Roster.java6
-rw-r--r--src/main/java/de/pixart/messenger/services/XmppConnectionService.java10
4 files changed, 32 insertions, 10 deletions
diff --git a/src/main/java/de/pixart/messenger/android/AbstractPhoneContact.java b/src/main/java/de/pixart/messenger/android/AbstractPhoneContact.java
index abab89aee..32dbfa77e 100644
--- a/src/main/java/de/pixart/messenger/android/AbstractPhoneContact.java
+++ b/src/main/java/de/pixart/messenger/android/AbstractPhoneContact.java
@@ -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;
diff --git a/src/main/java/de/pixart/messenger/entities/Contact.java b/src/main/java/de/pixart/messenger/entities/Contact.java
index fad4806de..e428362c6 100644
--- a/src/main/java/de/pixart/messenger/entities/Contact.java
+++ b/src/main/java/de/pixart/messenger/entities/Contact.java
@@ -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;
}
}
diff --git a/src/main/java/de/pixart/messenger/entities/Roster.java b/src/main/java/de/pixart/messenger/entities/Roster.java
index 2db0c796e..fea3af1f7 100644
--- a/src/main/java/de/pixart/messenger/entities/Roster.java
+++ b/src/main/java/de/pixart/messenger/entities/Roster.java
@@ -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();
}
}
diff --git a/src/main/java/de/pixart/messenger/services/XmppConnectionService.java b/src/main/java/de/pixart/messenger/services/XmppConnectionService.java
index 7238beec2..e9f77b33b 100644
--- a/src/main/java/de/pixart/messenger/services/XmppConnectionService.java
+++ b/src/main/java/de/pixart/messenger/services/XmppConnectionService.java
@@ -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);
}