mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-18 05:39:53 +01:00
Add method to get contact ids of existing custodians
This commit is contained in:
@@ -78,4 +78,11 @@ public interface SocialBackupManager extends
|
|||||||
*/
|
*/
|
||||||
byte[] getReturnShardPayloadBytes(Transaction txn, ContactId contactId)
|
byte[] getReturnShardPayloadBytes(Transaction txn, ContactId contactId)
|
||||||
throws DbException;
|
throws DbException;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get a list of the contact ids of your custodians, or an empty
|
||||||
|
* list if no backup exists.
|
||||||
|
*/
|
||||||
|
List<ContactId> getCustodianContactIds(Transaction txn);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -612,4 +612,30 @@ class SocialBackupManagerImpl extends ConversationClientImpl
|
|||||||
results.entrySet().iterator().next();
|
results.entrySet().iterator().next();
|
||||||
return new Pair<>(e.getKey(), e.getValue());
|
return new Pair<>(e.getKey(), e.getValue());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<ContactId> getCustodianContactIds(Transaction txn) {
|
||||||
|
ArrayList<ContactId> contactIds = new ArrayList<>();
|
||||||
|
try {
|
||||||
|
BackupMetadata b = getBackupMetadata(txn);
|
||||||
|
if (b == null) throw new DbException();
|
||||||
|
List<Author> 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<Contact> contacts =
|
||||||
|
(ArrayList<Contact>) contactManager.getContacts(txn);
|
||||||
|
for (Contact c : contacts) {
|
||||||
|
if (c.getAuthor().equals(author)) return c.getId();
|
||||||
|
}
|
||||||
|
throw new DbException();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user