mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-16 12:49:55 +01:00
[core] add method to ConversationManager for deleting a set of messages
This commit is contained in:
@@ -44,6 +44,14 @@ public interface ConversationManager {
|
|||||||
*/
|
*/
|
||||||
boolean deleteAllMessages(ContactId c) throws DbException;
|
boolean deleteAllMessages(ContactId c) throws DbException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Deletes the given set of messages associated with the given contact.
|
||||||
|
*
|
||||||
|
* @return true if all given messages could be deleted, false otherwise
|
||||||
|
*/
|
||||||
|
boolean deleteMessages(ContactId c, Collection<MessageId> messageIds)
|
||||||
|
throws DbException;
|
||||||
|
|
||||||
@NotNullByDefault
|
@NotNullByDefault
|
||||||
interface ConversationClient {
|
interface ConversationClient {
|
||||||
|
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import org.briarproject.bramble.api.db.DatabaseComponent;
|
|||||||
import org.briarproject.bramble.api.db.DbException;
|
import org.briarproject.bramble.api.db.DbException;
|
||||||
import org.briarproject.bramble.api.db.Transaction;
|
import org.briarproject.bramble.api.db.Transaction;
|
||||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||||
|
import org.briarproject.bramble.api.sync.MessageId;
|
||||||
import org.briarproject.briar.api.client.MessageTracker.GroupCount;
|
import org.briarproject.briar.api.client.MessageTracker.GroupCount;
|
||||||
import org.briarproject.briar.api.conversation.ConversationManager;
|
import org.briarproject.briar.api.conversation.ConversationManager;
|
||||||
import org.briarproject.briar.api.conversation.ConversationMessageHeader;
|
import org.briarproject.briar.api.conversation.ConversationMessageHeader;
|
||||||
@@ -84,4 +85,18 @@ class ConversationManagerImpl implements ConversationManager {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean deleteMessages(ContactId c, Collection<MessageId> toDelete)
|
||||||
|
throws DbException {
|
||||||
|
return db.transactionWithResult(false, txn -> {
|
||||||
|
boolean allDeleted = true;
|
||||||
|
for (ConversationClient client : clients) {
|
||||||
|
Set<MessageId> idSet = client.getMessageIds(txn, c);
|
||||||
|
idSet.retainAll(toDelete);
|
||||||
|
allDeleted = client.deleteMessages(txn, c, idSet) && allDeleted;
|
||||||
|
}
|
||||||
|
return allDeleted;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user