mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-11 18:29:05 +01:00
Better explain why messages could not be deleted
This also fixes a bug in the IntroductionManager that would allow to delete only part of a session's visible messages.
This commit is contained in:
@@ -17,6 +17,12 @@ import java.util.Set;
|
||||
@NotNullByDefault
|
||||
public interface ConversationManager {
|
||||
|
||||
int DELETE_SESSION_IS_INTRODUCTION = 1;
|
||||
int DELETE_SESSION_IS_INVITATION = 1 << 1;
|
||||
int DELETE_SESSION_INCOMPLETE = 1 << 2;
|
||||
int DELETE_SESSION_IN_PROGRESS = 1 << 3;
|
||||
int DELETE_NOT_DOWNLOADED = 1 << 4;
|
||||
|
||||
/**
|
||||
* Clients that present messages in a private conversation need to
|
||||
* register themselves here.
|
||||
@@ -39,17 +45,13 @@ public interface ConversationManager {
|
||||
|
||||
/**
|
||||
* Deletes all messages exchanged with the given contact.
|
||||
*
|
||||
* @return true if all messages could be deleted, false otherwise
|
||||
*/
|
||||
boolean deleteAllMessages(ContactId c) throws DbException;
|
||||
DeletionResult 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)
|
||||
DeletionResult deleteMessages(ContactId c, Collection<MessageId> messageIds)
|
||||
throws DbException;
|
||||
|
||||
@NotNullByDefault
|
||||
@@ -75,10 +77,8 @@ public interface ConversationManager {
|
||||
|
||||
/**
|
||||
* Deletes all messages associated with the given contact.
|
||||
*
|
||||
* @return true if all messages could be deleted, false otherwise
|
||||
*/
|
||||
boolean deleteAllMessages(Transaction txn,
|
||||
DeletionResult deleteAllMessages(Transaction txn,
|
||||
ContactId c) throws DbException;
|
||||
|
||||
/**
|
||||
@@ -86,10 +86,8 @@ public interface ConversationManager {
|
||||
* <p>
|
||||
* The set of message IDs must only include message IDs returned by
|
||||
* {@link #getMessageIds}.
|
||||
*
|
||||
* @return true if all messages could be deleted, false otherwise
|
||||
*/
|
||||
boolean deleteMessages(Transaction txn, ContactId c,
|
||||
DeletionResult deleteMessages(Transaction txn, ContactId c,
|
||||
Set<MessageId> messageIds) throws DbException;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,67 @@
|
||||
package org.briarproject.briar.api.conversation;
|
||||
|
||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||
|
||||
import javax.annotation.concurrent.NotThreadSafe;
|
||||
|
||||
import static org.briarproject.briar.api.conversation.ConversationManager.DELETE_NOT_DOWNLOADED;
|
||||
import static org.briarproject.briar.api.conversation.ConversationManager.DELETE_SESSION_INCOMPLETE;
|
||||
import static org.briarproject.briar.api.conversation.ConversationManager.DELETE_SESSION_IN_PROGRESS;
|
||||
import static org.briarproject.briar.api.conversation.ConversationManager.DELETE_SESSION_IS_INTRODUCTION;
|
||||
import static org.briarproject.briar.api.conversation.ConversationManager.DELETE_SESSION_IS_INVITATION;
|
||||
|
||||
@NotThreadSafe
|
||||
@NotNullByDefault
|
||||
public class DeletionResult {
|
||||
|
||||
private int result = 0;
|
||||
|
||||
public void addDeletionResult(DeletionResult deletionResult) {
|
||||
result |= deletionResult.result;
|
||||
}
|
||||
|
||||
public void addInvitationNotAllSelected() {
|
||||
result |= DELETE_SESSION_INCOMPLETE | DELETE_SESSION_IS_INVITATION;
|
||||
}
|
||||
|
||||
public void addInvitationSessionInProgress() {
|
||||
result |= DELETE_SESSION_IN_PROGRESS | DELETE_SESSION_IS_INVITATION;
|
||||
}
|
||||
|
||||
public void addIntroductionNotAllSelected() {
|
||||
result |= DELETE_SESSION_INCOMPLETE | DELETE_SESSION_IS_INTRODUCTION;
|
||||
}
|
||||
|
||||
public void addIntroductionSessionInProgress() {
|
||||
result |= DELETE_SESSION_IN_PROGRESS | DELETE_SESSION_IS_INTRODUCTION;
|
||||
}
|
||||
|
||||
public void addNotFullyDownloaded() {
|
||||
result |= DELETE_NOT_DOWNLOADED;
|
||||
}
|
||||
|
||||
public boolean allDeleted() {
|
||||
return result == 0;
|
||||
}
|
||||
|
||||
public boolean hasIntroduction() {
|
||||
return (result & DELETE_SESSION_IS_INTRODUCTION) != 0;
|
||||
}
|
||||
|
||||
public boolean hasInvitation() {
|
||||
return (result & DELETE_SESSION_IS_INVITATION) != 0;
|
||||
}
|
||||
|
||||
public boolean hasSessionInProgress() {
|
||||
return (result & DELETE_SESSION_IN_PROGRESS) != 0;
|
||||
}
|
||||
|
||||
public boolean hasNotAllSelected() {
|
||||
return (result & DELETE_SESSION_INCOMPLETE) != 0;
|
||||
}
|
||||
|
||||
public boolean hasNotFullyDownloaded() {
|
||||
return (result & DELETE_NOT_DOWNLOADED) != 0;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user