add TODO on how to use RangeAfter

This commit is contained in:
Daniel Gultsch 2023-03-11 09:57:51 +01:00
parent 97f54b6673
commit d9e8918727
No known key found for this signature in database
GPG key ID: F43D18AD2A0982C2
5 changed files with 50 additions and 9 deletions

View file

@ -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<Range> 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,

View file

@ -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);
}

View file

@ -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<DiscoItemEntity> 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"

View file

@ -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";

View file

@ -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();
}
}