mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-17 13:19:52 +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.io.InputStream;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
@@ -371,15 +372,23 @@ class MessagingManagerImpl implements MessagingManager, IncomingMessageHook,
|
|||||||
public Set<MessageId> getMessageIds(Transaction txn, ContactId c)
|
public Set<MessageId> getMessageIds(Transaction txn, ContactId c)
|
||||||
throws DbException {
|
throws DbException {
|
||||||
GroupId g = getContactGroup(db.getContact(txn, c)).getId();
|
GroupId g = getContactGroup(db.getContact(txn, c)).getId();
|
||||||
BdfDictionary query = BdfDictionary.of(
|
// Date: 2019-11-01
|
||||||
new BdfEntry(MSG_KEY_MSG_TYPE, PRIVATE_MESSAGE));
|
// 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 {
|
try {
|
||||||
Map<MessageId, BdfDictionary> results =
|
Map<MessageId, BdfDictionary> messages =
|
||||||
clientHelper.getMessageMetadataAsDictionary(txn, g, query);
|
clientHelper.getMessageMetadataAsDictionary(txn, g);
|
||||||
return results.keySet();
|
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) {
|
} catch (FormatException e) {
|
||||||
throw new DbException(e);
|
throw new DbException(e);
|
||||||
}
|
}
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -450,7 +459,8 @@ class MessagingManagerImpl implements MessagingManager, IncomingMessageHook,
|
|||||||
Long messageType = meta.getOptionalLong(MSG_KEY_MSG_TYPE);
|
Long messageType = meta.getOptionalLong(MSG_KEY_MSG_TYPE);
|
||||||
if (messageType != null && messageType != PRIVATE_MESSAGE)
|
if (messageType != null && messageType != PRIVATE_MESSAGE)
|
||||||
throw new AssertionError("not supported");
|
throw new AssertionError("not supported");
|
||||||
headers = parseAttachmentHeaders(meta);
|
headers = messageType == null ? emptyList() :
|
||||||
|
parseAttachmentHeaders(meta);
|
||||||
} catch (FormatException e) {
|
} catch (FormatException e) {
|
||||||
throw new DbException(e);
|
throw new DbException(e);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -208,6 +208,32 @@ public class MessagingManagerIntegrationTest
|
|||||||
assertGroupCounts(c0, 0, 0);
|
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
|
@Test
|
||||||
public void testDeleteAttachment() throws Exception {
|
public void testDeleteAttachment() throws Exception {
|
||||||
// send one message with attachment
|
// 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.BlogManager;
|
||||||
import org.briarproject.briar.api.blog.BlogSharingManager;
|
import org.briarproject.briar.api.blog.BlogSharingManager;
|
||||||
import org.briarproject.briar.api.client.MessageTracker;
|
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.ForumManager;
|
||||||
import org.briarproject.briar.api.forum.ForumSharingManager;
|
import org.briarproject.briar.api.forum.ForumSharingManager;
|
||||||
import org.briarproject.briar.api.introduction.IntroductionManager;
|
import org.briarproject.briar.api.introduction.IntroductionManager;
|
||||||
@@ -89,6 +90,8 @@ public interface BriarIntegrationTestComponent
|
|||||||
|
|
||||||
ContactManager getContactManager();
|
ContactManager getContactManager();
|
||||||
|
|
||||||
|
ConversationManager getConversationManager();
|
||||||
|
|
||||||
DatabaseComponent getDatabaseComponent();
|
DatabaseComponent getDatabaseComponent();
|
||||||
|
|
||||||
BlogManager getBlogManager();
|
BlogManager getBlogManager();
|
||||||
|
|||||||
Reference in New Issue
Block a user