mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-15 20:29:52 +01:00
Add a contactExists() method to the contactManager
This requires exposing the `containsContact()` method to the `DatabaseComponent` and is needed for finding out efficiently whether a contact already exists.
This commit is contained in:
@@ -125,6 +125,26 @@ class ContactManagerImpl implements ContactManager, RemoveIdentityHook {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean contactExists(Transaction txn, AuthorId remoteAuthorID,
|
||||
AuthorId localAuthorId) throws DbException {
|
||||
return db.containsContact(txn, remoteAuthorID, localAuthorId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean contactExists(AuthorId remoteAuthorID,
|
||||
AuthorId localAuthorId) throws DbException {
|
||||
boolean exists = false;
|
||||
Transaction txn = db.startTransaction(true);
|
||||
try {
|
||||
exists = contactExists(txn, remoteAuthorID, localAuthorId);
|
||||
txn.setComplete();
|
||||
} finally {
|
||||
db.endTransaction(txn);
|
||||
}
|
||||
return exists;
|
||||
}
|
||||
|
||||
private void removeContact(Transaction txn, ContactId c)
|
||||
throws DbException {
|
||||
Contact contact = db.getContact(txn, c);
|
||||
|
||||
@@ -342,6 +342,14 @@ class DatabaseComponentImpl<T> implements DatabaseComponent {
|
||||
return db.getContacts(txn, a);
|
||||
}
|
||||
|
||||
public boolean containsContact(Transaction transaction, AuthorId remote,
|
||||
AuthorId local) throws DbException {
|
||||
T txn = unbox(transaction);
|
||||
if (!db.containsLocalAuthor(txn, local))
|
||||
throw new NoSuchLocalAuthorException();
|
||||
return db.containsContact(txn, remote, local);
|
||||
}
|
||||
|
||||
public DeviceId getDeviceId(Transaction transaction) throws DbException {
|
||||
T txn = unbox(transaction);
|
||||
return db.getDeviceId(txn);
|
||||
|
||||
Reference in New Issue
Block a user