aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristian Schneppe <christian@pix-art.de>2017-05-31 21:30:38 +0200
committerChristian Schneppe <christian@pix-art.de>2017-05-31 21:30:38 +0200
commitf1f5b9fd701499487cbe4e828c45e440ece44e41 (patch)
tree36aed063e752ae7b9eb85160be9338fb706f97e9
parent7b5d5165d18042dcb99570e2b3e66afa011e7546 (diff)
parse all delayed tags. use min date
-rw-r--r--src/main/java/de/pixart/messenger/parser/AbstractParser.java26
-rw-r--r--src/main/java/de/pixart/messenger/parser/PresenceParser.java8
2 files changed, 22 insertions, 12 deletions
diff --git a/src/main/java/de/pixart/messenger/parser/AbstractParser.java b/src/main/java/de/pixart/messenger/parser/AbstractParser.java
index 21da7fe67..8fd106922 100644
--- a/src/main/java/de/pixart/messenger/parser/AbstractParser.java
+++ b/src/main/java/de/pixart/messenger/parser/AbstractParser.java
@@ -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) {
diff --git a/src/main/java/de/pixart/messenger/parser/PresenceParser.java b/src/main/java/de/pixart/messenger/parser/PresenceParser.java
index 8e1b0b006..a4534439e 100644
--- a/src/main/java/de/pixart/messenger/parser/PresenceParser.java
+++ b/src/main/java/de/pixart/messenger/parser/PresenceParser.java
@@ -213,12 +213,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))) {