Add database method for retrieving a contact by author ID

and use it for retreiving the status of an author faster.
Also add tests for both.
This commit is contained in:
Torsten Grote
2016-08-31 16:49:02 -03:00
parent 61c05c1dd4
commit 6f0ffa8439
7 changed files with 197 additions and 11 deletions

View File

@@ -130,17 +130,18 @@ class IdentityManagerImpl implements IdentityManager {
@Override
public Status getAuthorStatus(Transaction txn, AuthorId authorId)
throws DbException {
// Compare to the IDs of the user's identities
for (LocalAuthor a : db.getLocalAuthors(txn))
for (LocalAuthor a : db.getLocalAuthors(txn)) {
if (a.getId().equals(authorId)) return OURSELVES;
// Compare to the IDs of contacts' identities
for (Contact c : db.getContacts(txn)) {
if (c.getAuthor().getId().equals(authorId)) {
if (c.isVerified()) return VERIFIED;
else return UNVERIFIED;
}
}
return UNKNOWN;
Collection<Contact> contacts = db.getContactsByAuthorId(txn, authorId);
if (contacts.isEmpty()) return UNKNOWN;
for (Contact c : contacts) {
if (c.isVerified()) return VERIFIED;
}
return UNVERIFIED;
}
}