setup stub transformer
This commit is contained in:
parent
458f0ef280
commit
a43160b13d
|
@ -0,0 +1,64 @@
|
|||
package im.conversations.android.transformer;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
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.stanza.Message;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
public class Transformation {
|
||||
|
||||
private static final List<Class<? extends Extension>> EXTENSION_FOR_TRANSFORMATION =
|
||||
Arrays.asList(Body.class, Thread.class, Encrypted.class);
|
||||
|
||||
public final Jid to;
|
||||
public final Jid from;
|
||||
public final Message.Type type;
|
||||
public final String messageId;
|
||||
public final String stanzaId;
|
||||
|
||||
private final List<Extension> extensions;
|
||||
|
||||
public final Collection<DeliveryReceiptRequest> deliveryReceiptRequests;
|
||||
|
||||
private Transformation(
|
||||
final Jid to,
|
||||
final Jid from,
|
||||
final Message.Type type,
|
||||
final String messageId,
|
||||
final String stanzaId,
|
||||
final List<Extension> extensions,
|
||||
final Collection<DeliveryReceiptRequest> deliveryReceiptRequests) {
|
||||
this.to = to;
|
||||
this.from = from;
|
||||
this.type = type;
|
||||
this.messageId = messageId;
|
||||
this.stanzaId = stanzaId;
|
||||
this.extensions = extensions;
|
||||
this.deliveryReceiptRequests = deliveryReceiptRequests;
|
||||
}
|
||||
|
||||
public boolean isAnythingToTransform() {
|
||||
return this.extensions.size() > 0;
|
||||
}
|
||||
|
||||
public static Transformation of(final Message message, final String stanzaId) {
|
||||
final var to = message.getTo();
|
||||
final var from = message.getFrom();
|
||||
final var type = message.getType();
|
||||
final var messageId = message.getId();
|
||||
final ImmutableList.Builder<Extension> extensionListBuilder = new ImmutableList.Builder<>();
|
||||
for (final Class<? extends Extension> clazz : EXTENSION_FOR_TRANSFORMATION) {
|
||||
extensionListBuilder.addAll(message.getExtensions(clazz));
|
||||
}
|
||||
final var requests = message.getExtensions(DeliveryReceiptRequest.class);
|
||||
return new Transformation(
|
||||
to, from, type, messageId, stanzaId, extensionListBuilder.build(), requests);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,19 @@
|
|||
package im.conversations.android.transformer;
|
||||
|
||||
import android.content.Context;
|
||||
import im.conversations.android.database.model.Account;
|
||||
|
||||
public class Transformer {
|
||||
|
||||
private final Context context;
|
||||
private final Account account;
|
||||
|
||||
public Transformer(final Context context, final Account account) {
|
||||
this.context = context;
|
||||
this.account = account;
|
||||
}
|
||||
|
||||
public boolean transform(final Transformation transformation) {
|
||||
return true;
|
||||
}
|
||||
}
|
|
@ -2,6 +2,7 @@ package im.conversations.android.xmpp.manager;
|
|||
|
||||
import android.content.Context;
|
||||
import com.google.common.base.Preconditions;
|
||||
import im.conversations.android.transformer.Transformation;
|
||||
import im.conversations.android.xmpp.XmppConnection;
|
||||
import im.conversations.android.xmpp.mam.Result;
|
||||
import im.conversations.android.xmpp.model.stanza.Message;
|
||||
|
@ -20,13 +21,18 @@ public class ArchiveManager extends AbstractManager {
|
|||
final var result = message.getExtension(Result.class);
|
||||
Preconditions.checkArgument(result != null, "The message needs to contain a MAM result");
|
||||
final var from = message.getFrom();
|
||||
final var stanzaId = result.getId();
|
||||
final var queryId = result.getQueryId();
|
||||
final var forwarded = result.getForwarded();
|
||||
final var forwardedMessage = forwarded == null ? null : forwarded.getMessage();
|
||||
if (forwardedMessage == null || queryId == null) {
|
||||
if (forwardedMessage == null || queryId == null || stanzaId == null) {
|
||||
LOGGER.info("Received invalid MAM result from {} ", from);
|
||||
return;
|
||||
}
|
||||
// TODO
|
||||
// TODO get query based on queryId and from
|
||||
|
||||
final var transformation = Transformation.of(forwardedMessage, stanzaId);
|
||||
|
||||
// TODO create transformation; add transformation to Query.Transformer
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,12 @@
|
|||
package im.conversations.android.xmpp.model.axolotl;
|
||||
|
||||
import im.conversations.android.annotation.XmlElement;
|
||||
import im.conversations.android.xmpp.model.Extension;
|
||||
|
||||
@XmlElement
|
||||
public class Encrypted extends Extension {
|
||||
|
||||
public Encrypted() {
|
||||
super(Encrypted.class);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,12 @@
|
|||
package im.conversations.android.xmpp.model.axolotl;
|
||||
|
||||
import im.conversations.android.annotation.XmlElement;
|
||||
import im.conversations.android.xmpp.model.Extension;
|
||||
|
||||
@XmlElement
|
||||
public class Header extends Extension {
|
||||
|
||||
public Header() {
|
||||
super(Header.class);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,12 @@
|
|||
package im.conversations.android.xmpp.model.axolotl;
|
||||
|
||||
import im.conversations.android.annotation.XmlElement;
|
||||
import im.conversations.android.xmpp.model.Extension;
|
||||
|
||||
@XmlElement
|
||||
public class Payload extends Extension {
|
||||
|
||||
public Payload() {
|
||||
super(Payload.class);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,12 @@
|
|||
package im.conversations.android.xmpp.model.jabber;
|
||||
|
||||
import im.conversations.android.annotation.XmlElement;
|
||||
import im.conversations.android.xmpp.model.Extension;
|
||||
|
||||
@XmlElement
|
||||
public class Body extends Extension {
|
||||
|
||||
public Body() {
|
||||
super(Body.class);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,10 @@
|
|||
package im.conversations.android.xmpp.model.jabber;
|
||||
|
||||
import im.conversations.android.xmpp.model.Extension;
|
||||
|
||||
public class Thread extends Extension {
|
||||
|
||||
public Thread() {
|
||||
super(Thread.class);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,5 @@
|
|||
@XmlPackage(namespace = Namespace.JABBER_CLIENT)
|
||||
package im.conversations.android.xmpp.model.jabber;
|
||||
|
||||
import eu.siacs.conversations.xml.Namespace;
|
||||
import im.conversations.android.annotation.XmlPackage;
|
|
@ -1,7 +1,8 @@
|
|||
package im.conversations.android.xmpp.processor;
|
||||
|
||||
import android.content.Context;
|
||||
import eu.siacs.conversations.xmpp.Jid;
|
||||
import im.conversations.android.transformer.Transformation;
|
||||
import im.conversations.android.transformer.Transformer;
|
||||
import im.conversations.android.xmpp.XmppConnection;
|
||||
import im.conversations.android.xmpp.mam.Result;
|
||||
import im.conversations.android.xmpp.manager.ArchiveManager;
|
||||
|
@ -10,7 +11,6 @@ import im.conversations.android.xmpp.manager.ChatStateManager;
|
|||
import im.conversations.android.xmpp.manager.PubSubManager;
|
||||
import im.conversations.android.xmpp.manager.ReceiptManager;
|
||||
import im.conversations.android.xmpp.manager.StanzaIdManager;
|
||||
import im.conversations.android.xmpp.model.DeliveryReceiptRequest;
|
||||
import im.conversations.android.xmpp.model.carbons.Received;
|
||||
import im.conversations.android.xmpp.model.carbons.Sent;
|
||||
import im.conversations.android.xmpp.model.pubsub.event.Event;
|
||||
|
@ -59,25 +59,26 @@ public class MessageProcessor extends XmppConnection.Delegate implements Consume
|
|||
return;
|
||||
}
|
||||
|
||||
final String id = message.getId();
|
||||
final String stanzaId = getManager(StanzaIdManager.class).getStanzaId(message);
|
||||
final Jid from = message.getFrom();
|
||||
|
||||
LOGGER.info("Message with stanza-id {} received: {}", stanzaId, message.getExtensionIds());
|
||||
|
||||
// TODO only do this if transformation was successful or nothing to transform
|
||||
final var requests = message.getExtensions(DeliveryReceiptRequest.class);
|
||||
getManager(ReceiptManager.class).received(from, id, requests);
|
||||
|
||||
final var from = message.getFrom();
|
||||
final var id = message.getId();
|
||||
final var stanzaId = getManager(StanzaIdManager.class).getStanzaId(message);
|
||||
final var transformation = Transformation.of(message, stanzaId);
|
||||
final boolean sendReceipts;
|
||||
if (transformation.isAnythingToTransform()) {
|
||||
final var transformer = new Transformer(context, getAccount());
|
||||
sendReceipts = transformer.transform(transformation);
|
||||
} else {
|
||||
sendReceipts = true;
|
||||
}
|
||||
if (sendReceipts) {
|
||||
getManager(ReceiptManager.class)
|
||||
.received(from, id, transformation.deliveryReceiptRequests);
|
||||
}
|
||||
final var chatState = message.getExtension(ChatStateNotification.class);
|
||||
if (chatState != null) {
|
||||
getManager(ChatStateManager.class).handle(from, chatState);
|
||||
}
|
||||
|
||||
|
||||
// TODO collect Extensions that require transformation (everything that will end up in the
|
||||
// message tables)
|
||||
|
||||
// TODO pass JMI to JingleManager
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue