diff options
author | Christian S <christian@pix-art.de> | 2016-02-04 18:02:03 +0100 |
---|---|---|
committer | Christian S <christian@pix-art.de> | 2016-02-04 18:02:03 +0100 |
commit | 14b688e0fbe62a0fef0fadcc20763faa21801d7a (patch) | |
tree | 37fc7b87aa21326b0ca7ba97fee84aaf0ea6d3c2 /src/main/java/eu/siacs/conversations/entities/Presence.java | |
parent | 9e96d80e31c5d0455c4b15984eef5709cf1071fc (diff) | |
parent | 91ec4839acef3e395e83815f211dd9771af1287e (diff) |
Merge remote-tracking branch 'siacs/master' into development
Diffstat (limited to 'src/main/java/eu/siacs/conversations/entities/Presence.java')
-rw-r--r-- | src/main/java/eu/siacs/conversations/entities/Presence.java | 76 |
1 files changed, 76 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..69cde8327 --- /dev/null +++ b/src/main/java/eu/siacs/conversations/entities/Presence.java @@ -0,0 +1,76 @@ +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; + 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(Element show, Element caps) { + final String hash = caps == null ? null : caps.getAttribute("hash"); + final String ver = caps == null ? null : caps.getAttribute("ver"); + if ((show == null) || (show.getContent() == null)) { + return new Presence(Status.ONLINE, ver, hash); + } else if (show.getContent().equals("away")) { + return new Presence(Status.AWAY, ver, hash); + } else if (show.getContent().equals("xa")) { + return new Presence(Status.XA, ver, hash); + } else if (show.getContent().equals("chat")) { + return new Presence(Status.CHAT, ver, hash); + } else if (show.getContent().equals("dnd")) { + return new Presence(Status.DND, ver, hash); + } else { + return new Presence(Status.OFFLINE, 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; + } +} |