From dc371d7017cc5f09d22636b21b4d7b10ae9ec8e8 Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Thu, 9 Feb 2023 10:43:21 +0100 Subject: [PATCH] add models for Displayed and replace --- .../database/entity/MessageEntity.java | 4 ++++ .../android/transformer/Transformation.java | 15 ++++++++++++++- .../android/transformer/Transformer.java | 19 +++++++++++++++++++ .../xmpp/model/correction/Replace.java | 10 ++++++++++ .../android/xmpp/model/markers/Displayed.java | 12 ++++++++++++ .../android/xmpp/model/oob/OutOfBandData.java | 17 +++++++++++++++++ .../android/xmpp/model/oob/URL.java | 12 ++++++++++++ .../android/xmpp/model/oob/package-info.java | 5 +++++ 8 files changed, 93 insertions(+), 1 deletion(-) create mode 100644 src/main/java/im/conversations/android/xmpp/model/correction/Replace.java create mode 100644 src/main/java/im/conversations/android/xmpp/model/markers/Displayed.java create mode 100644 src/main/java/im/conversations/android/xmpp/model/oob/OutOfBandData.java create mode 100644 src/main/java/im/conversations/android/xmpp/model/oob/URL.java create mode 100644 src/main/java/im/conversations/android/xmpp/model/oob/package-info.java diff --git a/src/main/java/im/conversations/android/database/entity/MessageEntity.java b/src/main/java/im/conversations/android/database/entity/MessageEntity.java index 69628cfb0..8f69e18a9 100644 --- a/src/main/java/im/conversations/android/database/entity/MessageEntity.java +++ b/src/main/java/im/conversations/android/database/entity/MessageEntity.java @@ -26,6 +26,8 @@ public class MessageEntity { public Instant receivedAt; public Instant sentAt; + public boolean outgoing; + public String bareTo; public String toResource; public String bareFrom; @@ -35,6 +37,8 @@ public class MessageEntity { public String messageId; public String stanzaId; + // the stanza id might not be verified if this MessageEntity was created as a stub parent to attach reactions to or new versions (created by LMC etc) + public String stanzaIdVerified; public boolean acknowledged = false; } diff --git a/src/main/java/im/conversations/android/transformer/Transformation.java b/src/main/java/im/conversations/android/transformer/Transformation.java index 546214063..362c8c72d 100644 --- a/src/main/java/im/conversations/android/transformer/Transformation.java +++ b/src/main/java/im/conversations/android/transformer/Transformation.java @@ -1,12 +1,15 @@ package im.conversations.android.transformer; +import com.google.common.collect.Collections2; import com.google.common.collect.ImmutableList; +import com.google.common.collect.Iterables; import eu.siacs.conversations.xmpp.Jid; import im.conversations.android.xmpp.model.DeliveryReceiptRequest; import im.conversations.android.xmpp.model.Extension; import im.conversations.android.xmpp.model.axolotl.Encrypted; import im.conversations.android.xmpp.model.jabber.Body; import im.conversations.android.xmpp.model.jabber.Thread; +import im.conversations.android.xmpp.model.oob.OutOfBandData; import im.conversations.android.xmpp.model.stanza.Message; import java.util.Arrays; import java.util.Collection; @@ -15,7 +18,7 @@ import java.util.List; public class Transformation { private static final List> EXTENSION_FOR_TRANSFORMATION = - Arrays.asList(Body.class, Thread.class, Encrypted.class); + Arrays.asList(Body.class, Thread.class, Encrypted.class, OutOfBandData.class); public final Jid to; public final Jid from; @@ -48,6 +51,16 @@ public class Transformation { return this.extensions.size() > 0; } + public E getExtension(final Class clazz) { + final var extension = Iterables.find(this.extensions, clazz::isInstance, null); + return extension == null ? null : clazz.cast(extension); + } + + public Collection getExtensions(final Class clazz) { + return Collections2.transform( + Collections2.filter(this.extensions, clazz::isInstance), clazz::cast); + } + public static Transformation of(final Message message, final String stanzaId) { final var to = message.getTo(); final var from = message.getFrom(); diff --git a/src/main/java/im/conversations/android/transformer/Transformer.java b/src/main/java/im/conversations/android/transformer/Transformer.java index 03bbdeafa..02aeb6fd3 100644 --- a/src/main/java/im/conversations/android/transformer/Transformer.java +++ b/src/main/java/im/conversations/android/transformer/Transformer.java @@ -2,6 +2,9 @@ package im.conversations.android.transformer; import android.content.Context; import im.conversations.android.database.model.Account; +import im.conversations.android.xmpp.model.axolotl.Encrypted; +import im.conversations.android.xmpp.model.jabber.Body; +import im.conversations.android.xmpp.model.oob.OutOfBandData; public class Transformer { @@ -13,7 +16,23 @@ public class Transformer { this.account = account; } + /** + * @param transformation + * @return returns true if there is something we want to send a delivery receipt for. Basically + * anything that created a new message in the database. Notably not something that only + * updated a status somewhere + */ public boolean transform(final Transformation transformation) { + final var encrypted = transformation.getExtension(Encrypted.class); + final var bodies = transformation.getExtensions(Body.class); + final var outOfBandData = transformation.getExtensions(OutOfBandData.class); + + // TODO get or create Chat + // TODO create MessageEntity or get existing entity + // TODO for replaced message create a new version; re-target latestVersion + // TODO apply errors, displayed, received etc + // TODO apply reactions + return true; } } diff --git a/src/main/java/im/conversations/android/xmpp/model/correction/Replace.java b/src/main/java/im/conversations/android/xmpp/model/correction/Replace.java new file mode 100644 index 000000000..890311b70 --- /dev/null +++ b/src/main/java/im/conversations/android/xmpp/model/correction/Replace.java @@ -0,0 +1,10 @@ +package im.conversations.android.xmpp.model.correction; + +import im.conversations.android.xmpp.model.Extension; + +public class Replace extends Extension { + + public Replace() { + super(Replace.class); + } +} diff --git a/src/main/java/im/conversations/android/xmpp/model/markers/Displayed.java b/src/main/java/im/conversations/android/xmpp/model/markers/Displayed.java new file mode 100644 index 000000000..5b41a9917 --- /dev/null +++ b/src/main/java/im/conversations/android/xmpp/model/markers/Displayed.java @@ -0,0 +1,12 @@ +package im.conversations.android.xmpp.model.markers; + +import im.conversations.android.annotation.XmlElement; +import im.conversations.android.xmpp.model.Extension; + +@XmlElement +public class Displayed extends Extension { + + public Displayed() { + super(Displayed.class); + } +} diff --git a/src/main/java/im/conversations/android/xmpp/model/oob/OutOfBandData.java b/src/main/java/im/conversations/android/xmpp/model/oob/OutOfBandData.java new file mode 100644 index 000000000..e5c8aa2a0 --- /dev/null +++ b/src/main/java/im/conversations/android/xmpp/model/oob/OutOfBandData.java @@ -0,0 +1,17 @@ +package im.conversations.android.xmpp.model.oob; + +import im.conversations.android.annotation.XmlElement; +import im.conversations.android.xmpp.model.Extension; + +@XmlElement(name = "x") +public class OutOfBandData extends Extension { + + public OutOfBandData() { + super(OutOfBandData.class); + } + + public String getURL() { + final URL url = this.getExtension(URL.class); + return url == null ? null : url.getContent(); + } +} diff --git a/src/main/java/im/conversations/android/xmpp/model/oob/URL.java b/src/main/java/im/conversations/android/xmpp/model/oob/URL.java new file mode 100644 index 000000000..008b08480 --- /dev/null +++ b/src/main/java/im/conversations/android/xmpp/model/oob/URL.java @@ -0,0 +1,12 @@ +package im.conversations.android.xmpp.model.oob; + +import im.conversations.android.annotation.XmlElement; +import im.conversations.android.xmpp.model.Extension; + +@XmlElement(name = "url") +public class URL extends Extension { + + public URL() { + super(URL.class); + } +} diff --git a/src/main/java/im/conversations/android/xmpp/model/oob/package-info.java b/src/main/java/im/conversations/android/xmpp/model/oob/package-info.java new file mode 100644 index 000000000..5ffb31fdf --- /dev/null +++ b/src/main/java/im/conversations/android/xmpp/model/oob/package-info.java @@ -0,0 +1,5 @@ +@XmlPackage(namespace = Namespace.OOB) +package im.conversations.android.xmpp.model.oob; + +import eu.siacs.conversations.xml.Namespace; +import im.conversations.android.annotation.XmlPackage;