Add method to get contact ids of existing custodians

This commit is contained in:
ameba23
2022-03-03 10:48:23 +01:00
parent c0932b4df1
commit b7bdad4b67
2 changed files with 33 additions and 0 deletions

View File

@@ -612,4 +612,30 @@ class SocialBackupManagerImpl extends ConversationClientImpl
results.entrySet().iterator().next();
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();
}
}