diff options
author | Daniel Gultsch <daniel@gultsch.de> | 2016-02-03 10:40:02 +0100 |
---|---|---|
committer | Daniel Gultsch <daniel@gultsch.de> | 2016-02-03 10:40:02 +0100 |
commit | f0798216d568bca30051ba5392263da31e78eb98 (patch) | |
tree | 11e55953a1d71d1a15d06e88cfc65e7c20bdb29b /src/main/java/eu/siacs/conversations/entities/Presence.java | |
parent | 4a1a59f0c8ce99fd42909fb472179daec5065625 (diff) |
refactored disco cache. avoid making duplicate call. check hash
Diffstat (limited to 'src/main/java/eu/siacs/conversations/entities/Presence.java')
-rw-r--r-- | src/main/java/eu/siacs/conversations/entities/Presence.java | 42 |
1 files changed, 33 insertions, 9 deletions
diff --git a/src/main/java/eu/siacs/conversations/entities/Presence.java b/src/main/java/eu/siacs/conversations/entities/Presence.java index d31bb69d..69cde832 100644 --- a/src/main/java/eu/siacs/conversations/entities/Presence.java +++ b/src/main/java/eu/siacs/conversations/entities/Presence.java @@ -22,23 +22,31 @@ public class Presence implements Comparable { } protected final Status status; - protected final ServiceDiscoveryResult disco; + protected ServiceDiscoveryResult disco; + protected final String ver; + protected final String hash; - public Presence(Element show, ServiceDiscoveryResult disco) { - this.disco = disco; + 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)) { - this.status = Status.ONLINE; + return new Presence(Status.ONLINE, ver, hash); } else if (show.getContent().equals("away")) { - this.status = Status.AWAY; + return new Presence(Status.AWAY, ver, hash); } else if (show.getContent().equals("xa")) { - this.status = Status.XA; + return new Presence(Status.XA, ver, hash); } else if (show.getContent().equals("chat")) { - this.status = Status.CHAT; + return new Presence(Status.CHAT, ver, hash); } else if (show.getContent().equals("dnd")) { - this.status = Status.DND; + return new Presence(Status.DND, ver, hash); } else { - this.status = Status.OFFLINE; + return new Presence(Status.OFFLINE, ver, hash); } } @@ -49,4 +57,20 @@ public class Presence implements Comparable { 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; + } } |