diff options
author | Christian Schneppe <christian@pix-art.de> | 2017-05-17 21:58:46 +0200 |
---|---|---|
committer | Christian Schneppe <christian@pix-art.de> | 2017-05-17 21:58:46 +0200 |
commit | 5a60dab1d5ead7a94d9d86cecc563210fed4b4bf (patch) | |
tree | 383ecee02d5fd06737fb7d4cfbfb2360c3c441ba /src/main/java/de/pixart/messenger/xmpp | |
parent | d1449161398a099db7f3c5e10ccfc07dd8cffe3b (diff) |
use mam reference instead of timestamp
Diffstat (limited to 'src/main/java/de/pixart/messenger/xmpp')
-rw-r--r-- | src/main/java/de/pixart/messenger/xmpp/mam/MamReference.java | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/src/main/java/de/pixart/messenger/xmpp/mam/MamReference.java b/src/main/java/de/pixart/messenger/xmpp/mam/MamReference.java new file mode 100644 index 000000000..788e04889 --- /dev/null +++ b/src/main/java/de/pixart/messenger/xmpp/mam/MamReference.java @@ -0,0 +1,69 @@ +package de.pixart.messenger.xmpp.mam; + +public class MamReference { + + private final long timestamp; + private final String reference; + + public MamReference(long timestamp) { + this.timestamp = timestamp; + this.reference = null; + } + + public MamReference(long timestamp, String reference) { + this.timestamp = timestamp; + this.reference = reference; + } + + public long getTimestamp() { + return timestamp; + } + + public String getReference() { + return reference; + } + + public boolean greaterThan(MamReference b) { + return timestamp > b.getTimestamp(); + } + + public boolean greaterThan(long b) { + return timestamp > b; + } + + public static MamReference max(MamReference a, MamReference b) { + if (a != null && b != null) { + return a.timestamp > b.timestamp ? a : b; + } else if (a != null) { + return a; + } else { + return b; + } + } + + public static MamReference max(MamReference a, long b) { + return max(a,new MamReference(b)); + } + + public static MamReference fromAttribute(String attr) { + if (attr == null) { + return new MamReference(0); + } else { + String[] attrs = attr.split(":"); + try { + long timestamp = Long.parseLong(attrs[0]); + if (attrs.length >= 2) { + return new MamReference(timestamp,attrs[1]); + } else { + return new MamReference(timestamp); + } + } catch (Exception e) { + return new MamReference(0); + } + } + } + + public MamReference timeOnly() { + return reference == null ? this : new MamReference(timestamp); + } +}
\ No newline at end of file |