From 612e0afa633fb7f69688248a9aaff0fb5c0baf69 Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Thu, 1 Jun 2017 16:45:00 +0200 Subject: [PATCH] do not parse delay tag for unavailable presences when it comes form own server --- .../conversations/parser/AbstractParser.java | 18 +++++++++++++++++- .../conversations/parser/PresenceParser.java | 2 +- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/src/main/java/eu/siacs/conversations/parser/AbstractParser.java b/src/main/java/eu/siacs/conversations/parser/AbstractParser.java index 1e8db0f88..384e87d1e 100644 --- a/src/main/java/eu/siacs/conversations/parser/AbstractParser.java +++ b/src/main/java/eu/siacs/conversations/parser/AbstractParser.java @@ -2,6 +2,7 @@ package eu.siacs.conversations.parser; import java.text.ParseException; import java.text.SimpleDateFormat; + import java.util.Locale; import eu.siacs.conversations.entities.Account; @@ -12,6 +13,7 @@ import eu.siacs.conversations.services.XmppConnectionService; import eu.siacs.conversations.xml.Element; import eu.siacs.conversations.xmpp.jid.InvalidJidException; import eu.siacs.conversations.xmpp.jid.Jid; +import eu.siacs.conversations.xmpp.stanzas.AbstractStanza; public abstract class AbstractParser { @@ -22,11 +24,25 @@ public abstract class AbstractParser { } public static Long parseTimestamp(Element element, Long d) { + return parseTimestamp(element,d,false); + } + + public static Long parseTimestamp(Element element, Long d, boolean ignoreCsiAndSm) { long min = Long.MAX_VALUE; boolean returnDefault = true; + final Jid to; + if (ignoreCsiAndSm && element instanceof AbstractStanza) { + to = ((AbstractStanza) element).getTo(); + } else { + to = null; + } for(Element child : element.getChildren()) { if ("delay".equals(child.getName()) && "urn:xmpp:delay".equals(child.getNamespace())) { - String stamp = child.getAttribute("stamp"); + final Jid f = to == null ? null : child.getAttributeAsJid("from"); + if (f != null && (to.toBareJid().equals(f) || to.getDomainpart().equals(f.toString()))) { + continue; + } + final String stamp = child.getAttribute("stamp"); if (stamp != null) { try { min = Math.min(min,AbstractParser.parseTimestamp(stamp)); diff --git a/src/main/java/eu/siacs/conversations/parser/PresenceParser.java b/src/main/java/eu/siacs/conversations/parser/PresenceParser.java index 26eaf127c..2508cf7a7 100644 --- a/src/main/java/eu/siacs/conversations/parser/PresenceParser.java +++ b/src/main/java/eu/siacs/conversations/parser/PresenceParser.java @@ -240,7 +240,7 @@ public class PresenceParser extends AbstractParser implements boolean online = sizeBefore < contact.getPresences().size(); mXmppConnectionService.onContactStatusChanged.onContactStatusChanged(contact, online); } else if (type.equals("unavailable")) { - if (contact.setLastseen(AbstractParser.parseTimestamp(packet))) { + if (contact.setLastseen(AbstractParser.parseTimestamp(packet,0L,true))) { contact.flagInactive(); } if (from.isBareJid()) {