add models for Displayed and replace
This commit is contained in:
parent
a43160b13d
commit
dc371d7017
|
@ -26,6 +26,8 @@ public class MessageEntity {
|
||||||
public Instant receivedAt;
|
public Instant receivedAt;
|
||||||
public Instant sentAt;
|
public Instant sentAt;
|
||||||
|
|
||||||
|
public boolean outgoing;
|
||||||
|
|
||||||
public String bareTo;
|
public String bareTo;
|
||||||
public String toResource;
|
public String toResource;
|
||||||
public String bareFrom;
|
public String bareFrom;
|
||||||
|
@ -35,6 +37,8 @@ public class MessageEntity {
|
||||||
|
|
||||||
public String messageId;
|
public String messageId;
|
||||||
public String stanzaId;
|
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;
|
public boolean acknowledged = false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,12 +1,15 @@
|
||||||
package im.conversations.android.transformer;
|
package im.conversations.android.transformer;
|
||||||
|
|
||||||
|
import com.google.common.collect.Collections2;
|
||||||
import com.google.common.collect.ImmutableList;
|
import com.google.common.collect.ImmutableList;
|
||||||
|
import com.google.common.collect.Iterables;
|
||||||
import eu.siacs.conversations.xmpp.Jid;
|
import eu.siacs.conversations.xmpp.Jid;
|
||||||
import im.conversations.android.xmpp.model.DeliveryReceiptRequest;
|
import im.conversations.android.xmpp.model.DeliveryReceiptRequest;
|
||||||
import im.conversations.android.xmpp.model.Extension;
|
import im.conversations.android.xmpp.model.Extension;
|
||||||
import im.conversations.android.xmpp.model.axolotl.Encrypted;
|
import im.conversations.android.xmpp.model.axolotl.Encrypted;
|
||||||
import im.conversations.android.xmpp.model.jabber.Body;
|
import im.conversations.android.xmpp.model.jabber.Body;
|
||||||
import im.conversations.android.xmpp.model.jabber.Thread;
|
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 im.conversations.android.xmpp.model.stanza.Message;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
@ -15,7 +18,7 @@ import java.util.List;
|
||||||
public class Transformation {
|
public class Transformation {
|
||||||
|
|
||||||
private static final List<Class<? extends Extension>> EXTENSION_FOR_TRANSFORMATION =
|
private static final List<Class<? extends Extension>> 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 to;
|
||||||
public final Jid from;
|
public final Jid from;
|
||||||
|
@ -48,6 +51,16 @@ public class Transformation {
|
||||||
return this.extensions.size() > 0;
|
return this.extensions.size() > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public <E extends Extension> E getExtension(final Class<E> clazz) {
|
||||||
|
final var extension = Iterables.find(this.extensions, clazz::isInstance, null);
|
||||||
|
return extension == null ? null : clazz.cast(extension);
|
||||||
|
}
|
||||||
|
|
||||||
|
public <E extends Extension> Collection<E> getExtensions(final Class<E> clazz) {
|
||||||
|
return Collections2.transform(
|
||||||
|
Collections2.filter(this.extensions, clazz::isInstance), clazz::cast);
|
||||||
|
}
|
||||||
|
|
||||||
public static Transformation of(final Message message, final String stanzaId) {
|
public static Transformation of(final Message message, final String stanzaId) {
|
||||||
final var to = message.getTo();
|
final var to = message.getTo();
|
||||||
final var from = message.getFrom();
|
final var from = message.getFrom();
|
||||||
|
|
|
@ -2,6 +2,9 @@ package im.conversations.android.transformer;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import im.conversations.android.database.model.Account;
|
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 {
|
public class Transformer {
|
||||||
|
|
||||||
|
@ -13,7 +16,23 @@ public class Transformer {
|
||||||
this.account = account;
|
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) {
|
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;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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);
|
||||||
|
}
|
||||||
|
}
|
|
@ -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);
|
||||||
|
}
|
||||||
|
}
|
|
@ -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();
|
||||||
|
}
|
||||||
|
}
|
|
@ -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);
|
||||||
|
}
|
||||||
|
}
|
|
@ -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;
|
Loading…
Reference in a new issue