aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/de/thedevstack/conversationsplus/entities/Presence.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/de/thedevstack/conversationsplus/entities/Presence.java')
-rw-r--r--src/main/java/de/thedevstack/conversationsplus/entities/Presence.java80
1 files changed, 80 insertions, 0 deletions
diff --git a/src/main/java/de/thedevstack/conversationsplus/entities/Presence.java b/src/main/java/de/thedevstack/conversationsplus/entities/Presence.java
new file mode 100644
index 00000000..d4f2871d
--- /dev/null
+++ b/src/main/java/de/thedevstack/conversationsplus/entities/Presence.java
@@ -0,0 +1,80 @@
+package de.thedevstack.conversationsplus.entities;
+
+import java.lang.Comparable;
+import java.util.Locale;
+
+import de.thedevstack.conversationsplus.xml.Element;
+
+public class Presence implements Comparable {
+
+ public enum Status {
+ CHAT, ONLINE, AWAY, XA, DND, OFFLINE;
+
+ public String toShowString() {
+ switch(this) {
+ case CHAT: return "chat";
+ case AWAY: return "away";
+ case XA: return "xa";
+ case DND: return "dnd";
+ }
+
+ return null;
+ }
+ }
+
+ protected final Status status;
+ protected ServiceDiscoveryResult disco;
+ protected final String ver;
+ protected final String hash;
+
+ private Presence(Status status, String ver, String hash) {
+ this.status = status;
+ this.ver = ver;
+ this.hash = hash;
+ }
+
+ public static Presence parse(String show, Element caps) {
+ final String hash = caps == null ? null : caps.getAttribute("hash");
+ final String ver = caps == null ? null : caps.getAttribute("ver");
+ if (show == null) {
+ return new Presence(Status.ONLINE, ver, hash);
+ } else {
+ switch (show.toLowerCase(Locale.US)) {
+ case "away":
+ return new Presence(Status.AWAY, ver, hash);
+ case "xa":
+ return new Presence(Status.XA, ver, hash);
+ case "dnd":
+ return new Presence(Status.DND, ver, hash);
+ case "chat":
+ return new Presence(Status.CHAT, ver, hash);
+ default:
+ return new Presence(Status.ONLINE, ver, hash);
+ }
+ }
+ }
+
+ public int compareTo(Object other) {
+ return this.status.compareTo(((Presence)other).status);
+ }
+
+ public Status getStatus() {
+ return this.status;
+ }
+
+ public boolean hasCaps() {
+ return ver != null && hash != null;
+ }
+
+ public String getVer() {
+ return this.ver;
+ }
+
+ public String getHash() {
+ return this.hash;
+ }
+
+ public void setServiceDiscoveryResult(ServiceDiscoveryResult disco) {
+ this.disco = disco;
+ }
+}