add amCustodian method which determines whether you are a custodian for a given contact

This commit is contained in:
ameba23
2021-03-22 17:02:39 +01:00
parent b1f5d71a4e
commit 365fa58928
3 changed files with 17 additions and 0 deletions

View File

@@ -1,5 +1,6 @@
package org.briarproject.briar.api.socialbackup;
import org.briarproject.bramble.api.contact.Contact;
import org.briarproject.bramble.api.contact.ContactId;
import org.briarproject.bramble.api.db.DbException;
import org.briarproject.bramble.api.db.Transaction;
@@ -52,4 +53,6 @@ public interface SocialBackupManager extends
@Override
Collection<ConversationMessageHeader> getMessageHeaders(
Transaction txn, ContactId contactId) throws DbException;
boolean amCustodian(Transaction txn, ContactId contactId);
}

View File

@@ -230,6 +230,17 @@ class SocialBackupManagerImpl extends ConversationClientImpl
return false;
}
public boolean amCustodian(Transaction txn, ContactId contactId) {
try {
GroupId groupId = getContactGroup(db.getContact(txn, contactId)).getId();
return findMessage(txn, groupId, SHARD, false) != null;
} catch (DbException e) {
return false;
} catch (FormatException e) {
return false;
}
}
@Nullable
@Override
public BackupMetadata getBackupMetadata(Transaction txn)

View File

@@ -122,6 +122,9 @@ public class SocialBackupIntegrationTest
ShardMessageHeader s = (ShardMessageHeader) h;
assertFalse(s.isLocal());
}
db1.transaction(false, txn -> {
assertTrue(socialBackupManager1.amCustodian(txn, contactId0From1));
});
// the shard message from 0 should have arrived at 2
Collection<ConversationMessageHeader> messages0At2 =