diff --git a/briar-api/src/main/java/org/briarproject/briar/api/socialbackup/SocialBackupManager.java b/briar-api/src/main/java/org/briarproject/briar/api/socialbackup/SocialBackupManager.java index f8f4522ac..d3fa8e486 100644 --- a/briar-api/src/main/java/org/briarproject/briar/api/socialbackup/SocialBackupManager.java +++ b/briar-api/src/main/java/org/briarproject/briar/api/socialbackup/SocialBackupManager.java @@ -78,4 +78,11 @@ public interface SocialBackupManager extends */ byte[] getReturnShardPayloadBytes(Transaction txn, ContactId contactId) throws DbException; + + + /** + * Get a list of the contact ids of your custodians, or an empty + * list if no backup exists. + */ + List getCustodianContactIds(Transaction txn); } diff --git a/briar-core/src/main/java/org/briarproject/briar/socialbackup/SocialBackupManagerImpl.java b/briar-core/src/main/java/org/briarproject/briar/socialbackup/SocialBackupManagerImpl.java index 530542d00..60b4cab03 100644 --- a/briar-core/src/main/java/org/briarproject/briar/socialbackup/SocialBackupManagerImpl.java +++ b/briar-core/src/main/java/org/briarproject/briar/socialbackup/SocialBackupManagerImpl.java @@ -612,4 +612,30 @@ class SocialBackupManagerImpl extends ConversationClientImpl results.entrySet().iterator().next(); return new Pair<>(e.getKey(), e.getValue()); } + + public List getCustodianContactIds(Transaction txn) { + ArrayList contactIds = new ArrayList<>(); + try { + BackupMetadata b = getBackupMetadata(txn); + if (b == null) throw new DbException(); + List custodians = b.getCustodians(); + for (Author custodian : custodians) { + contactIds.add(authorToContactId(txn, custodian)); + } + } catch (DbException ignored) { + // Will return an empty list + } + return contactIds; + } + + private ContactId authorToContactId(Transaction txn, Author author) + throws DbException { + ArrayList contacts = + (ArrayList) contactManager.getContacts(txn); + for (Contact c : contacts) { + if (c.getAuthor().equals(author)) return c.getId(); + } + throw new DbException(); + } + }