mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-12 10:49:06 +01:00
[core] address feedback for selective conversation message deletion
This commit is contained in:
@@ -561,8 +561,8 @@ class IntroductionManagerImpl extends ConversationClientImpl
|
||||
|
||||
@FunctionalInterface
|
||||
private interface MessageRetriever {
|
||||
Map<MessageId, BdfDictionary> getMessages(GroupId contactGroup)
|
||||
throws DbException;
|
||||
Map<MessageId, BdfDictionary> getMessages(Transaction txn,
|
||||
GroupId contactGroup) throws DbException;
|
||||
}
|
||||
|
||||
@FunctionalInterface
|
||||
@@ -572,17 +572,17 @@ class IntroductionManagerImpl extends ConversationClientImpl
|
||||
* It returns true if the given {@link MessageId} causes a problem
|
||||
* so that the session can not be deleted.
|
||||
*/
|
||||
boolean causesProblem(MessageId messageId) throws DbException;
|
||||
boolean causesProblem(MessageId messageId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean deleteAllMessages(Transaction txn, ContactId c)
|
||||
throws DbException {
|
||||
return deleteMessages(txn, c, g -> {
|
||||
return deleteMessages(txn, c, (txn1, g) -> {
|
||||
// get metadata for all messages in the group
|
||||
Map<MessageId, BdfDictionary> messages;
|
||||
try {
|
||||
messages = clientHelper.getMessageMetadataAsDictionary(txn, g);
|
||||
messages = clientHelper.getMessageMetadataAsDictionary(txn1, g);
|
||||
} catch (FormatException e) {
|
||||
throw new DbException(e);
|
||||
}
|
||||
@@ -593,14 +593,14 @@ class IntroductionManagerImpl extends ConversationClientImpl
|
||||
@Override
|
||||
public boolean deleteMessages(Transaction txn, ContactId c,
|
||||
Set<MessageId> messageIds) throws DbException {
|
||||
return deleteMessages(txn, c, g -> {
|
||||
return deleteMessages(txn, c, (txn1, g) -> {
|
||||
// get metadata for messages that shall be deleted
|
||||
Map<MessageId, BdfDictionary> messages =
|
||||
new HashMap<>(messageIds.size());
|
||||
for (MessageId m : messageIds) {
|
||||
BdfDictionary d;
|
||||
try {
|
||||
d = clientHelper.getMessageMetadataAsDictionary(txn, m);
|
||||
d = clientHelper.getMessageMetadataAsDictionary(txn1, m);
|
||||
} catch (FormatException e) {
|
||||
throw new DbException(e);
|
||||
}
|
||||
@@ -620,16 +620,14 @@ class IntroductionManagerImpl extends ConversationClientImpl
|
||||
GroupId g = getContactGroup(db.getContact(txn, c)).getId();
|
||||
|
||||
// get messages to be deleted
|
||||
Map<MessageId, BdfDictionary> messages = retriever.getMessages(g);
|
||||
Map<MessageId, BdfDictionary> messages = retriever.getMessages(txn, g);
|
||||
|
||||
// assign protocol messages to their sessions
|
||||
Map<SessionId, DeletableSession> sessions = new HashMap<>();
|
||||
for (Entry<MessageId, BdfDictionary> entry : messages.entrySet()) {
|
||||
BdfDictionary d = entry.getValue();
|
||||
if (d == null) continue; // throw new NoSuchMessageException()
|
||||
MessageMetadata m;
|
||||
try {
|
||||
m = messageParser.parseMetadata(d);
|
||||
m = messageParser.parseMetadata(entry.getValue());
|
||||
} catch (FormatException e) {
|
||||
throw new DbException(e);
|
||||
}
|
||||
|
||||
@@ -620,7 +620,7 @@ class GroupInvitationManagerImpl extends ConversationClientImpl
|
||||
|
||||
@FunctionalInterface
|
||||
private interface DeletableSessionRetriever {
|
||||
Map<GroupId, DeletableSession> getDeletableSessions(
|
||||
Map<GroupId, DeletableSession> getDeletableSessions(Transaction txn,
|
||||
GroupId contactGroup, Map<MessageId, BdfDictionary> metadata)
|
||||
throws DbException;
|
||||
}
|
||||
@@ -632,13 +632,13 @@ class GroupInvitationManagerImpl extends ConversationClientImpl
|
||||
* It returns true if the given {@link MessageId} causes a problem
|
||||
* so that the session can not be deleted.
|
||||
*/
|
||||
boolean causesProblem(MessageId messageId) throws DbException;
|
||||
boolean causesProblem(MessageId messageId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean deleteAllMessages(Transaction txn, ContactId c)
|
||||
throws DbException {
|
||||
return deleteMessages(txn, c, (g, metadata) -> {
|
||||
return deleteMessages(txn, c, (txn1, g, metadata) -> {
|
||||
// get all sessions and their states
|
||||
Map<GroupId, DeletableSession> sessions = new HashMap<>();
|
||||
for (BdfDictionary d : metadata.values()) {
|
||||
@@ -659,7 +659,7 @@ class GroupInvitationManagerImpl extends ConversationClientImpl
|
||||
@Override
|
||||
public boolean deleteMessages(Transaction txn, ContactId c,
|
||||
Set<MessageId> messageIds) throws DbException {
|
||||
return deleteMessages(txn, c, (g, metadata) -> {
|
||||
return deleteMessages(txn, c, (txn1, g, metadata) -> {
|
||||
// get only sessions from given messageIds
|
||||
Map<GroupId, DeletableSession> sessions = new HashMap<>();
|
||||
for (MessageId messageId : messageIds) {
|
||||
@@ -670,7 +670,7 @@ class GroupInvitationManagerImpl extends ConversationClientImpl
|
||||
messageParser.parseMetadata(d);
|
||||
SessionId sessionId =
|
||||
getSessionId(messageMetadata.getPrivateGroupId());
|
||||
StoredSession ss = getSession(txn, g, sessionId);
|
||||
StoredSession ss = getSession(txn1, g, sessionId);
|
||||
if (ss == null) throw new DbException();
|
||||
Session session = sessionParser
|
||||
.parseSession(g, metadata.get(ss.storageId));
|
||||
@@ -700,9 +700,9 @@ class GroupInvitationManagerImpl extends ConversationClientImpl
|
||||
throw new DbException(e);
|
||||
}
|
||||
|
||||
// get all sessions and their states
|
||||
// get sessions and their states from retriever
|
||||
Map<GroupId, DeletableSession> sessions =
|
||||
retriever.getDeletableSessions(g, metadata);
|
||||
retriever.getDeletableSessions(txn, g, metadata);
|
||||
|
||||
// assign protocol messages to their sessions
|
||||
for (Entry<MessageId, BdfDictionary> entry : metadata.entrySet()) {
|
||||
|
||||
@@ -541,7 +541,7 @@ abstract class SharingManagerImpl<S extends Shareable>
|
||||
|
||||
@FunctionalInterface
|
||||
private interface DeletableSessionRetriever {
|
||||
Map<GroupId, DeletableSession> getDeletableSessions(
|
||||
Map<GroupId, DeletableSession> getDeletableSessions(Transaction txn,
|
||||
GroupId contactGroup, Map<MessageId, BdfDictionary> metadata)
|
||||
throws DbException;
|
||||
}
|
||||
@@ -553,13 +553,13 @@ abstract class SharingManagerImpl<S extends Shareable>
|
||||
* It returns true if the given {@link MessageId} causes a problem
|
||||
* so that the session can not be deleted.
|
||||
*/
|
||||
boolean causesProblem(MessageId messageId) throws DbException;
|
||||
boolean causesProblem(MessageId messageId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean deleteAllMessages(Transaction txn, ContactId c)
|
||||
throws DbException {
|
||||
return deleteMessages(txn, c, (contactGroup, metadata) -> {
|
||||
return deleteMessages(txn, c, (txn1, contactGroup, metadata) -> {
|
||||
// get all sessions and their states
|
||||
Map<GroupId, DeletableSession> sessions = new HashMap<>();
|
||||
for (BdfDictionary d : metadata.values()) {
|
||||
@@ -580,7 +580,7 @@ abstract class SharingManagerImpl<S extends Shareable>
|
||||
@Override
|
||||
public boolean deleteMessages(Transaction txn, ContactId c,
|
||||
Set<MessageId> messageIds) throws DbException {
|
||||
return deleteMessages(txn, c, (g, metadata) -> {
|
||||
return deleteMessages(txn, c, (txn1, g, metadata) -> {
|
||||
// get only sessions from given messageIds
|
||||
Map<GroupId, DeletableSession> sessions = new HashMap<>();
|
||||
for (MessageId messageId : messageIds) {
|
||||
@@ -591,7 +591,7 @@ abstract class SharingManagerImpl<S extends Shareable>
|
||||
messageParser.parseMetadata(d);
|
||||
SessionId sessionId =
|
||||
getSessionId(messageMetadata.getShareableId());
|
||||
StoredSession ss = getSession(txn, g, sessionId);
|
||||
StoredSession ss = getSession(txn1, g, sessionId);
|
||||
if (ss == null) throw new DbException();
|
||||
Session session = sessionParser
|
||||
.parseSession(g, metadata.get(ss.storageId));
|
||||
@@ -623,7 +623,7 @@ abstract class SharingManagerImpl<S extends Shareable>
|
||||
|
||||
// get all sessions and their states
|
||||
Map<GroupId, DeletableSession> sessions =
|
||||
retriever.getDeletableSessions(g, metadata);
|
||||
retriever.getDeletableSessions(txn, g, metadata);
|
||||
|
||||
// assign protocol messages to their sessions
|
||||
for (Entry<MessageId, BdfDictionary> entry : metadata.entrySet()) {
|
||||
|
||||
@@ -1470,7 +1470,8 @@ public class IntroductionIntegrationTest
|
||||
sync0To2(1, true);
|
||||
eventWaiter.await(TIMEOUT, 1);
|
||||
|
||||
// deleting introduction also fails for introducees
|
||||
// deleting introduction fails for introducees,
|
||||
// because response is not yet selected for deletion
|
||||
assertFalse(deleteMessages0From1(toDelete1));
|
||||
assertFalse(deleteMessages0From2(toDelete2));
|
||||
|
||||
|
||||
@@ -56,7 +56,7 @@ public class MessagingManagerIntegrationTest
|
||||
messagingManager0 = c0.getMessagingManager();
|
||||
messagingManager1 = c1.getMessagingManager();
|
||||
messageFactory = c0.getPrivateMessageFactory();
|
||||
assertEquals(contact0From1, contact1From0);
|
||||
assertEquals(contactId0From1, contactId1From0);
|
||||
contactId = contactId0From1;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user