wire up MessageAckProcessor with DB

This commit is contained in:
Daniel Gultsch 2023-01-14 07:41:53 +01:00
parent 2c32f9738c
commit 49bf92f7ca
No known key found for this signature in database
GPG key ID: F43D18AD2A0982C2
6 changed files with 54 additions and 6 deletions

View file

@ -6,6 +6,7 @@ import androidx.room.Room;
import androidx.room.RoomDatabase; import androidx.room.RoomDatabase;
import androidx.room.TypeConverters; import androidx.room.TypeConverters;
import im.conversations.android.database.dao.AccountDao; import im.conversations.android.database.dao.AccountDao;
import im.conversations.android.database.dao.MessageDao;
import im.conversations.android.database.dao.PresenceDao; import im.conversations.android.database.dao.PresenceDao;
import im.conversations.android.database.entity.AccountEntity; import im.conversations.android.database.entity.AccountEntity;
import im.conversations.android.database.entity.BlockedItemEntity; import im.conversations.android.database.entity.BlockedItemEntity;
@ -68,4 +69,6 @@ public abstract class ConversationsDatabase extends RoomDatabase {
public abstract AccountDao accountDao(); public abstract AccountDao accountDao();
public abstract PresenceDao presenceDao(); public abstract PresenceDao presenceDao();
public abstract MessageDao messageDao();
} }

View file

@ -0,0 +1,39 @@
package im.conversations.android.database.dao;
import androidx.annotation.NonNull;
import androidx.room.Dao;
import androidx.room.Query;
import eu.siacs.conversations.xmpp.Jid;
import im.conversations.android.database.model.Account;
@Dao
public abstract class MessageDao {
@Query(
"UPDATE message SET acknowledged=1 WHERE messageId=:messageId AND bareTo=:bareTo AND"
+ " toResource=NULL AND chatId IN (SELECT id FROM chat WHERE accountId=:account)")
abstract int acknowledge(long account, String messageId, final String bareTo);
@Query(
"UPDATE message SET acknowledged=1 WHERE messageId=:messageId AND bareTo=:bareTo AND"
+ " toResource=:toResource AND chatId IN (SELECT id FROM chat WHERE"
+ " accountId=:account)")
abstract int acknowledge(
long account, final String messageId, final String bareTo, final String toResource);
public boolean acknowledge(
final Account account, @NonNull final String messageId, @NonNull final Jid to) {
return acknowledge(account.id, messageId, to);
}
public boolean acknowledge(
final long account, @NonNull final String messageId, @NonNull final Jid to) {
if (to.isBareJid()) {
return acknowledge(account, messageId, to.toEscapedString()) > 0;
} else {
return acknowledge(
account, messageId, to.asBareJid().toEscapedString(), to.getResource())
> 0;
}
}
}

View file

@ -35,4 +35,6 @@ public class MessageEntity {
public String messageId; public String messageId;
public String stanzaId; public String stanzaId;
public boolean acknowledged = false;
} }

View file

@ -5,12 +5,12 @@ import im.conversations.android.database.ConversationsDatabase;
import im.conversations.android.database.model.Account; import im.conversations.android.database.model.Account;
import im.conversations.android.xmpp.XmppConnection; import im.conversations.android.xmpp.XmppConnection;
abstract class BaseProcessor { abstract class AbstractBaseProcessor {
protected final Context context; protected final Context context;
protected final XmppConnection connection; protected final XmppConnection connection;
BaseProcessor(final Context context, final XmppConnection connection) { AbstractBaseProcessor(final Context context, final XmppConnection connection) {
this.context = context; this.context = context;
this.connection = connection; this.connection = connection;
} }

View file

@ -10,7 +10,7 @@ import eu.siacs.conversations.xmpp.stanzas.IqPacket;
import im.conversations.android.xmpp.XmppConnection; import im.conversations.android.xmpp.XmppConnection;
import java.util.function.Consumer; import java.util.function.Consumer;
public class BindProcessor extends BaseProcessor implements Consumer<Jid> { public class BindProcessor extends AbstractBaseProcessor implements Consumer<Jid> {
public BindProcessor(final Context context, final XmppConnection connection) { public BindProcessor(final Context context, final XmppConnection connection) {
super(context, connection); super(context, connection);

View file

@ -5,12 +5,16 @@ import eu.siacs.conversations.xmpp.Jid;
import im.conversations.android.xmpp.XmppConnection; import im.conversations.android.xmpp.XmppConnection;
import java.util.function.BiFunction; import java.util.function.BiFunction;
public class MessageAcknowledgeProcessor implements BiFunction<Jid, String, Boolean> { public class MessageAcknowledgeProcessor extends AbstractBaseProcessor
implements BiFunction<Jid, String, Boolean> {
public MessageAcknowledgeProcessor(final Context context, final XmppConnection connection) {} public MessageAcknowledgeProcessor(final Context context, final XmppConnection connection) {
super(context, connection);
}
@Override @Override
public Boolean apply(final Jid to, final String id) { public Boolean apply(final Jid to, final String id) {
return null; final var account = getAccount();
return getDatabase().messageDao().acknowledge(account, id, to);
} }
} }