aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/eu/siacs/conversations/parser/AbstractParser.java
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/main/java/eu/siacs/conversations/parser/AbstractParser.java41
1 files changed, 20 insertions, 21 deletions
diff --git a/src/main/java/eu/siacs/conversations/parser/AbstractParser.java b/src/main/java/eu/siacs/conversations/parser/AbstractParser.java
index 6f73f24d..7b3eb7e9 100644
--- a/src/main/java/eu/siacs/conversations/parser/AbstractParser.java
+++ b/src/main/java/eu/siacs/conversations/parser/AbstractParser.java
@@ -11,6 +11,7 @@ import eu.siacs.conversations.entities.Contact;
import eu.siacs.conversations.services.XmppConnectionService;
import eu.siacs.conversations.xml.Element;
import eu.siacs.conversations.xmpp.jid.Jid;
+import eu.siacs.conversations.xmpp.stanzas.MessagePacket;
public abstract class AbstractParser {
@@ -20,22 +21,23 @@ public abstract class AbstractParser {
this.mXmppConnectionService = service;
}
- protected long getTimestamp(Element packet) {
- long now = System.currentTimeMillis();
- Element delay = packet.findChild("delay");
- if (delay == null) {
- return now;
- }
- String stamp = delay.getAttribute("stamp");
- if (stamp == null) {
- return now;
- }
- try {
- long time = parseTimestamp(stamp).getTime();
- return now < time ? now : time;
- } catch (ParseException e) {
- return now;
+ public static Long getTimestamp(Element element, Long defaultValue) {
+ Element delay = element.findChild("delay");
+ if (delay != null) {
+ String stamp = delay.getAttribute("stamp");
+ if (stamp != null) {
+ try {
+ return AbstractParser.parseTimestamp(delay.getAttribute("stamp")).getTime();
+ } catch (ParseException e) {
+ return defaultValue;
+ }
+ }
}
+ return defaultValue;
+ }
+
+ protected long getTimestamp(Element packet) {
+ return getTimestamp(packet,System.currentTimeMillis());
}
public static Date parseTimestamp(String timestamp) throws ParseException {
@@ -46,14 +48,11 @@ public abstract class AbstractParser {
return dateFormat.parse(timestamp);
}
- protected void updateLastseen(final Element packet, final Account account,
- final boolean presenceOverwrite) {
- final Jid from = packet.getAttributeAsJid("from");
- updateLastseen(packet, account, from, presenceOverwrite);
+ protected void updateLastseen(final Element packet, final Account account, final boolean presenceOverwrite) {
+ updateLastseen(packet, account, packet.getAttributeAsJid("from"), presenceOverwrite);
}
- protected void updateLastseen(final Element packet, final Account account, final Jid from,
- final boolean presenceOverwrite) {
+ protected void updateLastseen(final Element packet, final Account account, final Jid from, final boolean presenceOverwrite) {
final String presence = from == null || from.isBareJid() ? "" : from.getResourcepart();
final Contact contact = account.getRoster().getContact(from);
final long timestamp = getTimestamp(packet);