mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-16 12:49:55 +01:00
Add ConversationManager method for deleting all messages
Note that this does not yet delete special conversation messages such as invitations or introductions and their responses.
This commit is contained in:
@@ -24,7 +24,7 @@ public interface ConversationManager {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the headers of all messages in the given private conversation.
|
* Returns the headers of all messages in the given private conversation.
|
||||||
*
|
* <p>
|
||||||
* Only {@link MessagingManager} returns only headers.
|
* Only {@link MessagingManager} returns only headers.
|
||||||
* The others also return the message text.
|
* The others also return the message text.
|
||||||
*/
|
*/
|
||||||
@@ -36,6 +36,13 @@ public interface ConversationManager {
|
|||||||
*/
|
*/
|
||||||
GroupCount getGroupCount(ContactId c) throws DbException;
|
GroupCount getGroupCount(ContactId c) throws DbException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Deletes all messages exchanged with the given contact.
|
||||||
|
*
|
||||||
|
* @return true if all messages could be deleted, false otherwise
|
||||||
|
*/
|
||||||
|
boolean deleteAllMessages(ContactId c) throws DbException;
|
||||||
|
|
||||||
@NotNullByDefault
|
@NotNullByDefault
|
||||||
interface ConversationClient {
|
interface ConversationClient {
|
||||||
|
|
||||||
@@ -49,6 +56,14 @@ public interface ConversationManager {
|
|||||||
|
|
||||||
void setReadFlag(GroupId g, MessageId m, boolean read)
|
void setReadFlag(GroupId g, MessageId m, boolean read)
|
||||||
throws DbException;
|
throws DbException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Deletes all messages associated with the given contact.
|
||||||
|
*
|
||||||
|
* @return true if all messages could be deleted, false otherwise
|
||||||
|
*/
|
||||||
|
boolean deleteAllMessages(Transaction txn,
|
||||||
|
ContactId c) throws DbException;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -45,6 +45,7 @@ import java.util.HashMap;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
import javax.annotation.concurrent.Immutable;
|
import javax.annotation.concurrent.Immutable;
|
||||||
@@ -557,6 +558,26 @@ class IntroductionManagerImpl extends ConversationClientImpl
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean deleteAllMessages(Transaction txn, ContactId c)
|
||||||
|
throws DbException {
|
||||||
|
// TODO actually delete messages (#1627 and #1629)
|
||||||
|
return getMessageIds(txn, c).size() == 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Set<MessageId> getMessageIds(Transaction txn, ContactId c)
|
||||||
|
throws DbException {
|
||||||
|
GroupId g = getContactGroup(db.getContact(txn, c)).getId();
|
||||||
|
BdfDictionary query = messageParser.getMessagesVisibleInUiQuery();
|
||||||
|
try {
|
||||||
|
Map<MessageId, BdfDictionary> results =
|
||||||
|
clientHelper.getMessageMetadataAsDictionary(txn, g, query);
|
||||||
|
return results.keySet();
|
||||||
|
} catch (FormatException e) {
|
||||||
|
throw new DbException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private static class StoredSession {
|
private static class StoredSession {
|
||||||
|
|
||||||
private final MessageId storageId;
|
private final MessageId storageId;
|
||||||
|
|||||||
@@ -73,4 +73,15 @@ class ConversationManagerImpl implements ConversationManager {
|
|||||||
return new GroupCount(msgCount, unreadCount, latestTime);
|
return new GroupCount(msgCount, unreadCount, latestTime);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean deleteAllMessages(ContactId c) throws DbException {
|
||||||
|
return db.transactionWithResult(false, txn -> {
|
||||||
|
boolean allDeleted = true;
|
||||||
|
for (ConversationClient client : clients) {
|
||||||
|
allDeleted = client.deleteAllMessages(txn, c) && allDeleted;
|
||||||
|
}
|
||||||
|
return allDeleted;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -404,4 +404,17 @@ class MessagingManagerImpl implements MessagingManager, IncomingMessageHook,
|
|||||||
return minorVersion > 0;
|
return minorVersion > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean deleteAllMessages(Transaction txn, ContactId c)
|
||||||
|
throws DbException {
|
||||||
|
GroupId g = getContactGroup(db.getContact(txn, c)).getId();
|
||||||
|
// this indiscriminately deletes all raw messages in this group
|
||||||
|
// also attachments
|
||||||
|
for (MessageId messageId : db.getMessageIds(txn, g)) {
|
||||||
|
db.deleteMessage(txn, messageId);
|
||||||
|
db.deleteMessageMetadata(txn, messageId);
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -43,6 +43,7 @@ import java.util.HashMap;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
import javax.annotation.concurrent.Immutable;
|
import javax.annotation.concurrent.Immutable;
|
||||||
@@ -629,6 +630,26 @@ class GroupInvitationManagerImpl extends ConversationClientImpl
|
|||||||
return m;
|
return m;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean deleteAllMessages(Transaction txn, ContactId c)
|
||||||
|
throws DbException {
|
||||||
|
// TODO actually delete messages (#1627 and #1629)
|
||||||
|
return getMessageIds(txn, c).size() == 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Set<MessageId> getMessageIds(Transaction txn, ContactId c)
|
||||||
|
throws DbException {
|
||||||
|
GroupId g = getContactGroup(db.getContact(txn, c)).getId();
|
||||||
|
BdfDictionary query = messageParser.getMessagesVisibleInUiQuery();
|
||||||
|
try {
|
||||||
|
Map<MessageId, BdfDictionary> results =
|
||||||
|
clientHelper.getMessageMetadataAsDictionary(txn, g, query);
|
||||||
|
return results.keySet();
|
||||||
|
} catch (FormatException e) {
|
||||||
|
throw new DbException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private static class StoredSession {
|
private static class StoredSession {
|
||||||
|
|
||||||
private final MessageId storageId;
|
private final MessageId storageId;
|
||||||
|
|||||||
@@ -40,6 +40,7 @@ import java.util.HashMap;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
@@ -537,6 +538,26 @@ abstract class SharingManagerImpl<S extends Shareable>
|
|||||||
return m;
|
return m;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean deleteAllMessages(Transaction txn, ContactId c)
|
||||||
|
throws DbException {
|
||||||
|
// TODO actually delete messages (#1627 and #1629)
|
||||||
|
return getMessageIds(txn, c).size() == 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Set<MessageId> getMessageIds(Transaction txn, ContactId c)
|
||||||
|
throws DbException {
|
||||||
|
GroupId g = getContactGroup(db.getContact(txn, c)).getId();
|
||||||
|
BdfDictionary query = messageParser.getMessagesVisibleInUiQuery();
|
||||||
|
try {
|
||||||
|
Map<MessageId, BdfDictionary> results =
|
||||||
|
clientHelper.getMessageMetadataAsDictionary(txn, g, query);
|
||||||
|
return results.keySet();
|
||||||
|
} catch (FormatException e) {
|
||||||
|
throw new DbException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private static class StoredSession {
|
private static class StoredSession {
|
||||||
|
|
||||||
private final MessageId storageId;
|
private final MessageId storageId;
|
||||||
|
|||||||
Reference in New Issue
Block a user