mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-12 02:39:05 +01:00
[core] also support private messages in legacy format for selective deletion
This commit is contained in:
@@ -47,6 +47,7 @@ import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
@@ -371,15 +372,23 @@ class MessagingManagerImpl implements MessagingManager, IncomingMessageHook,
|
||||
public Set<MessageId> getMessageIds(Transaction txn, ContactId c)
|
||||
throws DbException {
|
||||
GroupId g = getContactGroup(db.getContact(txn, c)).getId();
|
||||
BdfDictionary query = BdfDictionary.of(
|
||||
new BdfEntry(MSG_KEY_MSG_TYPE, PRIVATE_MESSAGE));
|
||||
// Date: 2019-11-01
|
||||
// When we remove support for old messages without MSG_KEY_MSG_TYPE,
|
||||
// we can use a query here for (MSG_KEY_MSG_TYPE, PRIVATE_MESSAGE)
|
||||
Set<MessageId> result = new HashSet<>();
|
||||
try {
|
||||
Map<MessageId, BdfDictionary> results =
|
||||
clientHelper.getMessageMetadataAsDictionary(txn, g, query);
|
||||
return results.keySet();
|
||||
Map<MessageId, BdfDictionary> messages =
|
||||
clientHelper.getMessageMetadataAsDictionary(txn, g);
|
||||
for (Map.Entry<MessageId, BdfDictionary> entry : messages
|
||||
.entrySet()) {
|
||||
Long type = entry.getValue().getOptionalLong(MSG_KEY_MSG_TYPE);
|
||||
if (type == null || type == PRIVATE_MESSAGE)
|
||||
result.add(entry.getKey());
|
||||
}
|
||||
} catch (FormatException e) {
|
||||
throw new DbException(e);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -450,7 +459,8 @@ class MessagingManagerImpl implements MessagingManager, IncomingMessageHook,
|
||||
Long messageType = meta.getOptionalLong(MSG_KEY_MSG_TYPE);
|
||||
if (messageType != null && messageType != PRIVATE_MESSAGE)
|
||||
throw new AssertionError("not supported");
|
||||
headers = parseAttachmentHeaders(meta);
|
||||
headers = messageType == null ? emptyList() :
|
||||
parseAttachmentHeaders(meta);
|
||||
} catch (FormatException e) {
|
||||
throw new DbException(e);
|
||||
}
|
||||
|
||||
@@ -208,6 +208,32 @@ public class MessagingManagerIntegrationTest
|
||||
assertGroupCounts(c0, 0, 0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDeleteLegacySubset() throws Exception {
|
||||
// send legacy message
|
||||
GroupId g = c0.getMessagingManager().getConversationId(contactId);
|
||||
PrivateMessage m0 = messageFactory.createLegacyPrivateMessage(g,
|
||||
clock.currentTimeMillis(), getRandomString(42));
|
||||
c0.getMessagingManager().addLocalMessage(m0);
|
||||
syncMessage(c0, c1, contactId, 1, true);
|
||||
|
||||
// message arrived on both sides
|
||||
assertEquals(1, getMessages(c0).size());
|
||||
assertEquals(1, getMessages(c1).size());
|
||||
|
||||
// delete message on both sides (deletes all, because returns true)
|
||||
Set<MessageId> toDelete = new HashSet<>();
|
||||
toDelete.add(m0.getMessage().getId());
|
||||
assertTrue(c0.getConversationManager()
|
||||
.deleteMessages(contactId, toDelete));
|
||||
assertTrue(c1.getConversationManager()
|
||||
.deleteMessages(contactId, toDelete));
|
||||
|
||||
// message was deleted
|
||||
assertEquals(0, getMessages(c0).size());
|
||||
assertEquals(0, getMessages(c1).size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDeleteAttachment() throws Exception {
|
||||
// send one message with attachment
|
||||
|
||||
@@ -16,6 +16,7 @@ import org.briarproject.briar.api.blog.BlogFactory;
|
||||
import org.briarproject.briar.api.blog.BlogManager;
|
||||
import org.briarproject.briar.api.blog.BlogSharingManager;
|
||||
import org.briarproject.briar.api.client.MessageTracker;
|
||||
import org.briarproject.briar.api.conversation.ConversationManager;
|
||||
import org.briarproject.briar.api.forum.ForumManager;
|
||||
import org.briarproject.briar.api.forum.ForumSharingManager;
|
||||
import org.briarproject.briar.api.introduction.IntroductionManager;
|
||||
@@ -89,6 +90,8 @@ public interface BriarIntegrationTestComponent
|
||||
|
||||
ContactManager getContactManager();
|
||||
|
||||
ConversationManager getConversationManager();
|
||||
|
||||
DatabaseComponent getDatabaseComponent();
|
||||
|
||||
BlogManager getBlogManager();
|
||||
|
||||
Reference in New Issue
Block a user