From 49a3f6f281c9a01f9bdaf7f5141c46dd1c6ca2cb Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Fri, 19 Feb 2016 11:09:28 +0100 Subject: [PATCH] never parse show in presences as offline --- .../conversations/entities/Presence.java | 26 +++++++++++-------- .../conversations/parser/PresenceParser.java | 2 +- 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/src/main/java/eu/siacs/conversations/entities/Presence.java b/src/main/java/eu/siacs/conversations/entities/Presence.java index 69cde8327..442f1bcac 100644 --- a/src/main/java/eu/siacs/conversations/entities/Presence.java +++ b/src/main/java/eu/siacs/conversations/entities/Presence.java @@ -1,6 +1,7 @@ package eu.siacs.conversations.entities; import java.lang.Comparable; +import java.util.Locale; import eu.siacs.conversations.xml.Element; @@ -32,21 +33,24 @@ public class Presence implements Comparable { this.hash = hash; } - public static Presence parse(Element show, Element caps) { + 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) || (show.getContent() == null)) { + if (show == 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); + 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); + } } } diff --git a/src/main/java/eu/siacs/conversations/parser/PresenceParser.java b/src/main/java/eu/siacs/conversations/parser/PresenceParser.java index 45c31e2b0..dc02eda8f 100644 --- a/src/main/java/eu/siacs/conversations/parser/PresenceParser.java +++ b/src/main/java/eu/siacs/conversations/parser/PresenceParser.java @@ -186,7 +186,7 @@ public class PresenceParser extends AbstractParser implements } int sizeBefore = contact.getPresences().size(); - final Element show = packet.findChild("show"); + final String show = packet.findChildContent("show"); final Element caps = packet.findChild("c", "http://jabber.org/protocol/caps"); final Presence presence = Presence.parse(show, caps); contact.updatePresence(resource, presence);