From d9e89187270d3d7a48f7b4cff30a8e4a3e3552f4 Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Sat, 11 Mar 2023 09:57:51 +0100 Subject: [PATCH] add TODO on how to use RangeAfter --- .../android/database/dao/ArchiveDao.java | 10 +++++++- .../android/database/dao/BaseDao.java | 14 +++++++++++ .../android/database/dao/DiscoDao.java | 9 +------ .../conversations/android/xml/Namespace.java | 2 ++ .../android/xmpp/RangeAfter.java | 24 +++++++++++++++++++ 5 files changed, 50 insertions(+), 9 deletions(-) create mode 100644 app/src/main/java/im/conversations/android/database/dao/BaseDao.java create mode 100644 app/src/main/java/im/conversations/android/xmpp/RangeAfter.java diff --git a/app/src/main/java/im/conversations/android/database/dao/ArchiveDao.java b/app/src/main/java/im/conversations/android/database/dao/ArchiveDao.java index 6fd792d7e..e2152c15b 100644 --- a/app/src/main/java/im/conversations/android/database/dao/ArchiveDao.java +++ b/app/src/main/java/im/conversations/android/database/dao/ArchiveDao.java @@ -10,6 +10,7 @@ import com.google.common.collect.ImmutableList; import im.conversations.android.database.entity.ArchivePageEntity; import im.conversations.android.database.model.Account; import im.conversations.android.database.model.StanzaId; +import im.conversations.android.xml.Namespace; import im.conversations.android.xmpp.Range; import im.conversations.android.xmpp.manager.ArchiveManager; import java.util.List; @@ -19,12 +20,19 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; @Dao -public abstract class ArchiveDao { +public abstract class ArchiveDao extends BaseDao { private static final Logger LOGGER = LoggerFactory.getLogger(ArchiveDao.class); @Transaction public List resetLivePage(final Account account, final Jid archive) { + // if the server support extended MAM or catch-up query from (live)page.end to now can use + // after-id reverse towards that (this means newer messages will be fetched earlier); if and + // when we support this we also need a new page type called END that will eventually be + // deleted once we need page.end + final boolean emitRangeAfter = + hasDiscoItemFeature( + account.id, archive, Namespace.MESSAGE_ARCHIVE_MANAGEMENT_EXTENDED); final var page = getPage( account.id, diff --git a/app/src/main/java/im/conversations/android/database/dao/BaseDao.java b/app/src/main/java/im/conversations/android/database/dao/BaseDao.java new file mode 100644 index 000000000..18539f5df --- /dev/null +++ b/app/src/main/java/im/conversations/android/database/dao/BaseDao.java @@ -0,0 +1,14 @@ +package im.conversations.android.database.dao; + +import androidx.room.Query; +import org.jxmpp.jid.Jid; + +public abstract class BaseDao { + + @Query( + "SELECT EXISTS (SELECT disco_item.id FROM disco_item JOIN disco_feature on" + + " disco_item.discoId=disco_feature.discoId WHERE accountId=:account AND" + + " address=:entity AND feature=:feature)") + protected abstract boolean hasDiscoItemFeature( + final long account, final Jid entity, final String feature); +} diff --git a/app/src/main/java/im/conversations/android/database/dao/DiscoDao.java b/app/src/main/java/im/conversations/android/database/dao/DiscoDao.java index 0dabf3fbc..be3f93575 100644 --- a/app/src/main/java/im/conversations/android/database/dao/DiscoDao.java +++ b/app/src/main/java/im/conversations/android/database/dao/DiscoDao.java @@ -33,7 +33,7 @@ import org.jxmpp.jid.Jid; import org.jxmpp.jid.parts.Resourcepart; @Dao -public abstract class DiscoDao { +public abstract class DiscoDao extends BaseDao { @Insert(onConflict = OnConflictStrategy.IGNORE) protected abstract void insertDiscoItems(Collection items); @@ -190,13 +190,6 @@ public abstract class DiscoDao { @Query("SELECT id FROM disco WHERE accountId=:accountId AND capsHash=:capsHash") protected abstract Long getDiscoIdByCapsHash(final long accountId, final byte[] capsHash); - @Query( - "SELECT EXISTS (SELECT disco_item.id FROM disco_item JOIN disco_feature on" - + " disco_item.discoId=disco_feature.discoId WHERE accountId=:account AND" - + " address=:entity AND feature=:feature)") - protected abstract boolean hasDiscoItemFeature( - final long account, final Jid entity, final String feature); - @Query( "SELECT EXISTS (SELECT presence.id FROM presence JOIN disco_feature on" + " presence.discoId=disco_feature.discoId WHERE accountId=:account AND" diff --git a/app/src/main/java/im/conversations/android/xml/Namespace.java b/app/src/main/java/im/conversations/android/xml/Namespace.java index dae27be1b..273a66726 100644 --- a/app/src/main/java/im/conversations/android/xml/Namespace.java +++ b/app/src/main/java/im/conversations/android/xml/Namespace.java @@ -68,6 +68,8 @@ public final class Namespace { public static final String JINGLE_TRANSPORT_ICE_UDP = "urn:xmpp:jingle:transports:ice-udp:1"; public static final String LAST_MESSAGE_CORRECTION = "urn:xmpp:message-correct:0"; public static final String MESSAGE_ARCHIVE_MANAGEMENT = "urn:xmpp:mam:2"; + public static final String MESSAGE_ARCHIVE_MANAGEMENT_EXTENDED = + MESSAGE_ARCHIVE_MANAGEMENT + "#extended"; public static final String MUC = "http://jabber.org/protocol/muc"; public static final String MUC_USER = MUC + "#user"; public static final String NICK = "http://jabber.org/protocol/nick"; diff --git a/app/src/main/java/im/conversations/android/xmpp/RangeAfter.java b/app/src/main/java/im/conversations/android/xmpp/RangeAfter.java new file mode 100644 index 000000000..56f68eeba --- /dev/null +++ b/app/src/main/java/im/conversations/android/xmpp/RangeAfter.java @@ -0,0 +1,24 @@ +package im.conversations.android.xmpp; + +import androidx.annotation.NonNull; +import com.google.common.base.MoreObjects; + +public class RangeAfter extends Range { + + public final String afterId; + + public RangeAfter(final String afterId, final String id) { + super(Order.REVERSE, id); + this.afterId = afterId; + } + + @NonNull + @Override + public String toString() { + return MoreObjects.toStringHelper(this) + .add("afterId", afterId) + .add("order", order) + .add("id", id) + .toString(); + } +}