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