mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-17 13:19:52 +01:00
add amCustodian method which determines whether you are a custodian for a given contact
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
package org.briarproject.briar.api.socialbackup;
|
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.contact.ContactId;
|
||||||
import org.briarproject.bramble.api.db.DbException;
|
import org.briarproject.bramble.api.db.DbException;
|
||||||
import org.briarproject.bramble.api.db.Transaction;
|
import org.briarproject.bramble.api.db.Transaction;
|
||||||
@@ -52,4 +53,6 @@ public interface SocialBackupManager extends
|
|||||||
@Override
|
@Override
|
||||||
Collection<ConversationMessageHeader> getMessageHeaders(
|
Collection<ConversationMessageHeader> getMessageHeaders(
|
||||||
Transaction txn, ContactId contactId) throws DbException;
|
Transaction txn, ContactId contactId) throws DbException;
|
||||||
|
|
||||||
|
boolean amCustodian(Transaction txn, ContactId contactId);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -230,6 +230,17 @@ class SocialBackupManagerImpl extends ConversationClientImpl
|
|||||||
return false;
|
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
|
@Nullable
|
||||||
@Override
|
@Override
|
||||||
public BackupMetadata getBackupMetadata(Transaction txn)
|
public BackupMetadata getBackupMetadata(Transaction txn)
|
||||||
|
|||||||
@@ -122,6 +122,9 @@ public class SocialBackupIntegrationTest
|
|||||||
ShardMessageHeader s = (ShardMessageHeader) h;
|
ShardMessageHeader s = (ShardMessageHeader) h;
|
||||||
assertFalse(s.isLocal());
|
assertFalse(s.isLocal());
|
||||||
}
|
}
|
||||||
|
db1.transaction(false, txn -> {
|
||||||
|
assertTrue(socialBackupManager1.amCustodian(txn, contactId0From1));
|
||||||
|
});
|
||||||
|
|
||||||
// the shard message from 0 should have arrived at 2
|
// the shard message from 0 should have arrived at 2
|
||||||
Collection<ConversationMessageHeader> messages0At2 =
|
Collection<ConversationMessageHeader> messages0At2 =
|
||||||
|
|||||||
Reference in New Issue
Block a user