aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/eu/siacs/conversations/entities/Presence.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/eu/siacs/conversations/entities/Presence.java')
-rw-r--r--src/main/java/eu/siacs/conversations/entities/Presence.java49
1 files changed, 49 insertions, 0 deletions
diff --git a/src/main/java/eu/siacs/conversations/entities/Presence.java b/src/main/java/eu/siacs/conversations/entities/Presence.java
new file mode 100644
index 000000000..adba74d12
--- /dev/null
+++ b/src/main/java/eu/siacs/conversations/entities/Presence.java
@@ -0,0 +1,49 @@
+package eu.siacs.conversations.entities;
+
+import java.lang.Comparable;
+
+import eu.siacs.conversations.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;
+
+ public Presence(Element show) {
+ if ((show == null) || (show.getContent() == null)) {
+ this.status = Status.ONLINE;
+ } else if (show.getContent().equals("away")) {
+ this.status = Status.AWAY;
+ } else if (show.getContent().equals("xa")) {
+ this.status = Status.XA;
+ } else if (show.getContent().equals("chat")) {
+ this.status = Status.CHAT;
+ } else if (show.getContent().equals("dnd")) {
+ this.status = Status.DND;
+ } else {
+ this.status = Status.OFFLINE;
+ }
+ }
+
+ public int compareTo(Object other) {
+ return this.status.compareTo(((Presence)other).status);
+ }
+
+ public Status getStatus() {
+ return this.status;
+ }
+}