wire up MessageAckProcessor with DB
This commit is contained in:
parent
2c32f9738c
commit
49bf92f7ca
|
@ -6,6 +6,7 @@ import androidx.room.Room;
|
|||
import androidx.room.RoomDatabase;
|
||||
import androidx.room.TypeConverters;
|
||||
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.entity.AccountEntity;
|
||||
import im.conversations.android.database.entity.BlockedItemEntity;
|
||||
|
@ -68,4 +69,6 @@ public abstract class ConversationsDatabase extends RoomDatabase {
|
|||
public abstract AccountDao accountDao();
|
||||
|
||||
public abstract PresenceDao presenceDao();
|
||||
|
||||
public abstract MessageDao messageDao();
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -35,4 +35,6 @@ public class MessageEntity {
|
|||
|
||||
public String messageId;
|
||||
public String stanzaId;
|
||||
|
||||
public boolean acknowledged = false;
|
||||
}
|
||||
|
|
|
@ -5,12 +5,12 @@ import im.conversations.android.database.ConversationsDatabase;
|
|||
import im.conversations.android.database.model.Account;
|
||||
import im.conversations.android.xmpp.XmppConnection;
|
||||
|
||||
abstract class BaseProcessor {
|
||||
abstract class AbstractBaseProcessor {
|
||||
|
||||
protected final Context context;
|
||||
protected final XmppConnection connection;
|
||||
|
||||
BaseProcessor(final Context context, final XmppConnection connection) {
|
||||
AbstractBaseProcessor(final Context context, final XmppConnection connection) {
|
||||
this.context = context;
|
||||
this.connection = connection;
|
||||
}
|
|
@ -10,7 +10,7 @@ import eu.siacs.conversations.xmpp.stanzas.IqPacket;
|
|||
import im.conversations.android.xmpp.XmppConnection;
|
||||
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) {
|
||||
super(context, connection);
|
||||
|
|
|
@ -5,12 +5,16 @@ import eu.siacs.conversations.xmpp.Jid;
|
|||
import im.conversations.android.xmpp.XmppConnection;
|
||||
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
|
||||
public Boolean apply(final Jid to, final String id) {
|
||||
return null;
|
||||
final var account = getAccount();
|
||||
return getDatabase().messageDao().acknowledge(account, id, to);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue