[core] add method to ConversationManager for deleting a set of messages

This commit is contained in:
Torsten Grote
2019-10-22 11:16:27 -03:00
parent 5b515d7e18
commit f516dbe34f
2 changed files with 23 additions and 0 deletions

View File

@@ -44,6 +44,14 @@ public interface ConversationManager {
*/
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
interface ConversationClient {

View File

@@ -5,6 +5,7 @@ import org.briarproject.bramble.api.db.DatabaseComponent;
import org.briarproject.bramble.api.db.DbException;
import org.briarproject.bramble.api.db.Transaction;
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.conversation.ConversationManager;
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;
});
}
}