From b8e85a284635584ce6b18c85ab129e6b9b6d2047 Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Fri, 21 Feb 2014 21:35:23 +0100 Subject: subscription mgmt works --- src/de/gultsch/chat/entities/Contact.java | 60 ++++++++++++++++++++++++++----- 1 file changed, 51 insertions(+), 9 deletions(-) (limited to 'src/de/gultsch/chat/entities') diff --git a/src/de/gultsch/chat/entities/Contact.java b/src/de/gultsch/chat/entities/Contact.java index eff46e53..a01e20b0 100644 --- a/src/de/gultsch/chat/entities/Contact.java +++ b/src/de/gultsch/chat/entities/Contact.java @@ -9,6 +9,8 @@ import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; +import de.gultsch.chat.xml.Element; + import android.content.ContentValues; import android.database.Cursor; @@ -29,7 +31,7 @@ public class Contact extends AbstractEntity implements Serializable { protected String accountUuid; protected String displayName; protected String jid; - protected String subscription; + protected int subscription = 0; protected String systemAccount; protected String photoUri; protected JSONObject keys = new JSONObject(); @@ -52,7 +54,7 @@ public class Contact extends AbstractEntity implements Serializable { } public Contact(String uuid, String account, String displayName, String jid, - String subscription, String photoUri, String systemAccount, + int subscription, String photoUri, String systemAccount, String keys, String presences) { this.uuid = uuid; this.accountUuid = account; @@ -109,18 +111,14 @@ public class Contact extends AbstractEntity implements Serializable { cursor.getString(cursor.getColumnIndex(ACCOUNT)), cursor.getString(cursor.getColumnIndex(DISPLAYNAME)), cursor.getString(cursor.getColumnIndex(JID)), - cursor.getString(cursor.getColumnIndex(SUBSCRIPTION)), + cursor.getInt(cursor.getColumnIndex(SUBSCRIPTION)), cursor.getString(cursor.getColumnIndex(PHOTOURI)), cursor.getString(cursor.getColumnIndex(SYSTEMACCOUNT)), cursor.getString(cursor.getColumnIndex(KEYS)), cursor.getString(cursor.getColumnIndex(PRESENCES))); } - - public void setSubscription(String subscription) { - this.subscription = subscription; - } - - public String getSubscription() { + + public int getSubscription() { return this.subscription; } @@ -220,4 +218,48 @@ public class Contact extends AbstractEntity implements Serializable { } } + + public void setSubscriptionOption(int option) { + this.subscription |= 1 << option; + } + + public void resetSubscriptionOption(int option) { + this.subscription &= ~(1 << option); + } + + public boolean getSubscriptionOption(int option) { + return ((this.subscription & (1 << option)) != 0); + } + + public void parseSubscriptionFromElement(Element item) { + String ask = item.getAttribute("ask"); + String subscription = item.getAttribute("subscription"); + + if (subscription!=null) { + if (subscription.equals("to")) { + this.resetSubscriptionOption(Contact.Subscription.FROM); + this.setSubscriptionOption(Contact.Subscription.TO); + } else if (subscription.equals("from")) { + this.resetSubscriptionOption(Contact.Subscription.TO); + this.setSubscriptionOption(Contact.Subscription.FROM); + } else if (subscription.equals("both")) { + this.setSubscriptionOption(Contact.Subscription.TO); + this.setSubscriptionOption(Contact.Subscription.FROM); + } + } + + if ((ask!=null)&&(ask.equals("subscribe"))) { + this.setSubscriptionOption(Contact.Subscription.ASKING); + } else { + this.resetSubscriptionOption(Contact.Subscription.ASKING); + } + } + + + public class Subscription { + public static final int TO = 0; + public static final int FROM = 1; + public static final int ASKING = 2; + public static final int PREEMPTIVE_GRANT = 4; + } } -- cgit v1.2.3