parse all delayed tags. use min date

This commit is contained in:
Daniel Gultsch 2017-05-30 08:39:04 +02:00
parent e973117aed
commit 6ccdd1227e
2 changed files with 22 additions and 12 deletions

View File

@ -22,18 +22,26 @@ public abstract class AbstractParser {
}
public static Long parseTimestamp(Element element, Long d) {
Element delay = element.findChild("delay","urn:xmpp:delay");
if (delay != null) {
String stamp = delay.getAttribute("stamp");
if (stamp != null) {
try {
return AbstractParser.parseTimestamp(delay.getAttribute("stamp"));
} catch (ParseException e) {
return d;
long min = Long.MAX_VALUE;
boolean returnDefault = true;
for(Element child : element.getChildren()) {
if ("delay".equals(child.getName()) && "urn:xmpp:delay".equals(child.getNamespace())) {
String stamp = child.getAttribute("stamp");
if (stamp != null) {
try {
min = Math.min(min,AbstractParser.parseTimestamp(stamp));
returnDefault = false;
} catch (ParseException e) {
//ignore
}
}
}
}
return d;
if (returnDefault) {
return d;
} else {
return min;
}
}
public static long parseTimestamp(Element element) {

View File

@ -215,12 +215,14 @@ public class PresenceParser extends AbstractParser implements
final Element idle = packet.findChild("idle", Namespace.IDLE);
if (idle != null) {
contact.flagInactive();
final String since = idle.getAttribute("since");
try {
final String since = idle.getAttribute("since");
contact.setLastseen(AbstractParser.parseTimestamp(since));
contact.flagInactive();
} catch (NullPointerException | ParseException e) {
contact.setLastseen(System.currentTimeMillis());
if (contact.setLastseen(AbstractParser.parseTimestamp(packet))) {
contact.flagActive();
}
}
} else {
if (contact.setLastseen(AbstractParser.parseTimestamp(packet))) {