diff options
author | Daniel Gultsch <daniel.gultsch@rwth-aachen.de> | 2014-02-21 21:35:23 +0100 |
---|---|---|
committer | Daniel Gultsch <daniel.gultsch@rwth-aachen.de> | 2014-02-21 21:35:23 +0100 |
commit | b8e85a284635584ce6b18c85ab129e6b9b6d2047 (patch) | |
tree | d7fab70d6ee1cd86317316a172c48683b93bf9c9 /src/de/gultsch/chat/entities | |
parent | b71bfbaa9d483d0fd00801fffa1e2a7c7fa32656 (diff) |
subscription mgmt works
Diffstat (limited to 'src/de/gultsch/chat/entities')
-rw-r--r-- | src/de/gultsch/chat/entities/Contact.java | 60 |
1 files changed, 51 insertions, 9 deletions
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; + } } |