[core] Add method to ConversationClient that returns a set of MessageIds it is responsible for

This commit is contained in:
Torsten Grote
2019-10-21 14:59:10 -03:00
parent 01df141c08
commit 190a6bff96
5 changed files with 31 additions and 3 deletions

View File

@@ -12,6 +12,7 @@ import org.briarproject.briar.api.client.MessageTracker.GroupCount;
import org.briarproject.briar.api.messaging.MessagingManager;
import java.util.Collection;
import java.util.Set;
@NotNullByDefault
public interface ConversationManager {
@@ -51,6 +52,13 @@ public interface ConversationManager {
Collection<ConversationMessageHeader> getMessageHeaders(Transaction txn,
ContactId contactId) throws DbException;
/**
* Returns all conversation {@link MessageId}s for the given contact
* this client is responsible for.
*/
Set<MessageId> getMessageIds(Transaction txn, ContactId contactId)
throws DbException;
GroupCount getGroupCount(Transaction txn, ContactId c)
throws DbException;

View File

@@ -660,7 +660,8 @@ class IntroductionManagerImpl extends ConversationClientImpl
return allDeleted;
}
private Set<MessageId> getMessageIds(Transaction txn, ContactId c)
@Override
public Set<MessageId> getMessageIds(Transaction txn, ContactId c)
throws DbException {
GroupId g = getContactGroup(db.getContact(txn, c)).getId();
BdfDictionary query = messageParser.getMessagesVisibleInUiQuery();

View File

@@ -7,6 +7,7 @@ import org.briarproject.bramble.api.contact.Contact;
import org.briarproject.bramble.api.contact.ContactId;
import org.briarproject.bramble.api.contact.ContactManager.ContactHook;
import org.briarproject.bramble.api.data.BdfDictionary;
import org.briarproject.bramble.api.data.BdfEntry;
import org.briarproject.bramble.api.data.BdfList;
import org.briarproject.bramble.api.data.MetadataParser;
import org.briarproject.bramble.api.db.DatabaseComponent;
@@ -47,6 +48,7 @@ import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.Set;
import javax.annotation.concurrent.Immutable;
import javax.inject.Inject;
@@ -363,6 +365,21 @@ class MessagingManagerImpl implements MessagingManager, IncomingMessageHook,
return headers;
}
@Override
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));
try {
Map<MessageId, BdfDictionary> results =
clientHelper.getMessageMetadataAsDictionary(txn, g, query);
return results.keySet();
} catch (FormatException e) {
throw new DbException(e);
}
}
@Override
public String getMessageText(MessageId m) throws DbException {
try {

View File

@@ -729,7 +729,8 @@ class GroupInvitationManagerImpl extends ConversationClientImpl
return allDeleted;
}
private Set<MessageId> getMessageIds(Transaction txn, ContactId c)
@Override
public Set<MessageId> getMessageIds(Transaction txn, ContactId c)
throws DbException {
GroupId g = getContactGroup(db.getContact(txn, c)).getId();
BdfDictionary query = messageParser.getMessagesVisibleInUiQuery();

View File

@@ -629,7 +629,8 @@ abstract class SharingManagerImpl<S extends Shareable>
return allDeleted;
}
private Set<MessageId> getMessageIds(Transaction txn, ContactId c)
@Override
public Set<MessageId> getMessageIds(Transaction txn, ContactId c)
throws DbException {
GroupId g = getContactGroup(db.getContact(txn, c)).getId();
BdfDictionary query = messageParser.getMessagesVisibleInUiQuery();