do not parse delay tag for unavailable presences when it comes form own server

This commit is contained in:
Daniel Gultsch 2017-06-01 16:45:00 +02:00
parent ed7882fe69
commit 612e0afa63
2 changed files with 18 additions and 2 deletions

View File

@ -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));

View File

@ -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()) {