diff options
Diffstat (limited to 'src/main/java/eu/siacs/conversations/entities/Presence.java')
-rw-r--r-- | src/main/java/eu/siacs/conversations/entities/Presence.java | 57 |
1 files changed, 35 insertions, 22 deletions
diff --git a/src/main/java/eu/siacs/conversations/entities/Presence.java b/src/main/java/eu/siacs/conversations/entities/Presence.java index 442f1bca..e9f6d0d1 100644 --- a/src/main/java/eu/siacs/conversations/entities/Presence.java +++ b/src/main/java/eu/siacs/conversations/entities/Presence.java @@ -17,42 +17,47 @@ public class Presence implements Comparable { 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"); + public static Status fromShowString(String show) { if (show == null) { - return new Presence(Status.ONLINE, ver, hash); + return ONLINE; } else { switch (show.toLowerCase(Locale.US)) { case "away": - return new Presence(Status.AWAY, ver, hash); + return AWAY; case "xa": - return new Presence(Status.XA, ver, hash); + return XA; case "dnd": - return new Presence(Status.DND, ver, hash); + return DND; case "chat": - return new Presence(Status.CHAT, ver, hash); + return CHAT; default: - return new Presence(Status.ONLINE, ver, hash); + return ONLINE; } } } + } + + private final Status status; + private ServiceDiscoveryResult disco; + private final String ver; + private final String hash; + private final String message; + + private Presence(Status status, String ver, String hash, String message) { + this.status = status; + this.ver = ver; + this.hash = hash; + this.message = message; + } + + public static Presence parse(String show, Element caps, String message) { + final String hash = caps == null ? null : caps.getAttribute("hash"); + final String ver = caps == null ? null : caps.getAttribute("ver"); + return new Presence(Status.fromShowString(show), ver, hash, message); + } public int compareTo(Object other) { return this.status.compareTo(((Presence)other).status); @@ -74,7 +79,15 @@ public class Presence implements Comparable { return this.hash; } + public String getMessage() { + return this.message; + } + public void setServiceDiscoveryResult(ServiceDiscoveryResult disco) { this.disco = disco; } + + public ServiceDiscoveryResult getServiceDiscoveryResult() { + return disco; + } } |