From acf80bddd07d5579cdb20a888b3f9e99e53030a5 Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Fri, 28 Feb 2014 18:46:01 +0100 Subject: rebranding --- src/eu/siacs/conversations/entities/Presences.java | 76 ++++++++++++++++++++++ 1 file changed, 76 insertions(+) create mode 100644 src/eu/siacs/conversations/entities/Presences.java (limited to 'src/eu/siacs/conversations/entities/Presences.java') diff --git a/src/eu/siacs/conversations/entities/Presences.java b/src/eu/siacs/conversations/entities/Presences.java new file mode 100644 index 000000000..af7926a8b --- /dev/null +++ b/src/eu/siacs/conversations/entities/Presences.java @@ -0,0 +1,76 @@ +package eu.siacs.conversations.entities; + +import java.util.Hashtable; +import java.util.Iterator; +import java.util.Map.Entry; + +import org.json.JSONArray; +import org.json.JSONException; +import org.json.JSONObject; + +public class Presences { + + public static final int CHAT = -1; + public static final int ONLINE = 0; + public static final int AWAY = 1; + public static final int XA = 2; + public static final int DND = 3; + public static final int OFFLINE = 4; + + private Hashtable presences = new Hashtable(); + + public Hashtable getPresences() { + return this.presences; + } + + public void updatePresence(String resource, int status) { + this.presences.put(resource, status); + } + + public void removePresence(String resource) { + this.presences.remove(resource); + } + + public int getMostAvailableStatus() { + int status = OFFLINE; + Iterator> it = presences.entrySet().iterator(); + while (it.hasNext()) { + Entry entry = it.next(); + if (entry.getValue()> it = presences.entrySet().iterator(); + + while (it.hasNext()) { + Entry entry = it.next(); + JSONObject jObj = new JSONObject(); + try { + jObj.put("resource", entry.getKey()); + jObj.put("status", entry.getValue()); + } catch (JSONException e) { + + } + json.put(jObj); + } + return json.toString(); + } + + public static Presences fromJsonString(String jsonString) { + Presences presences = new Presences(); + try { + JSONArray json = new JSONArray(jsonString); + for (int i = 0; i < json.length(); ++i) { + JSONObject jObj = json.getJSONObject(i); + presences.updatePresence(jObj.getString("resource"), + jObj.getInt("status")); + } + } catch (JSONException e1) { + + } + return presences; + } +} -- cgit v1.2.3