mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-16 20:59:54 +01:00
allow adding contacts within an existing transactions
This commit is contained in:
@@ -16,12 +16,21 @@ public interface ContactManager {
|
|||||||
/** Registers a hook to be called whenever a contact is removed. */
|
/** Registers a hook to be called whenever a contact is removed. */
|
||||||
void registerRemoveContactHook(RemoveContactHook hook);
|
void registerRemoveContactHook(RemoveContactHook hook);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Stores a contact within the given transaction associated with the given
|
||||||
|
* local and remote pseudonyms, and returns an ID for the contact.
|
||||||
|
*/
|
||||||
|
ContactId addContact(Transaction txn, Author remote, AuthorId local,
|
||||||
|
SecretKey master, long timestamp, boolean alice, boolean active)
|
||||||
|
throws DbException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Stores a contact associated with the given local and remote pseudonyms,
|
* Stores a contact associated with the given local and remote pseudonyms,
|
||||||
* and returns an ID for the contact.
|
* and returns an ID for the contact.
|
||||||
*/
|
*/
|
||||||
ContactId addContact(Author remote, AuthorId local, SecretKey master,
|
ContactId addContact(Author remote, AuthorId local,
|
||||||
long timestamp, boolean alice, boolean active) throws DbException;
|
SecretKey master, long timestamp, boolean alice, boolean active)
|
||||||
|
throws DbException;
|
||||||
|
|
||||||
/** Returns the contact with the given ID. */
|
/** Returns the contact with the given ID. */
|
||||||
Contact getContact(ContactId c) throws DbException;
|
Contact getContact(ContactId c) throws DbException;
|
||||||
|
|||||||
@@ -46,6 +46,18 @@ class ContactManagerImpl implements ContactManager, RemoveIdentityHook {
|
|||||||
removeHooks.add(hook);
|
removeHooks.add(hook);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ContactId addContact(Transaction txn, Author remote, AuthorId local,
|
||||||
|
SecretKey master,long timestamp, boolean alice, boolean active)
|
||||||
|
throws DbException {
|
||||||
|
ContactId c = db.addContact(txn, remote, local, active);
|
||||||
|
keyManager.addContact(txn, c, master, timestamp, alice);
|
||||||
|
Contact contact = db.getContact(txn, c);
|
||||||
|
for (AddContactHook hook : addHooks)
|
||||||
|
hook.addingContact(txn, contact);
|
||||||
|
return c;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ContactId addContact(Author remote, AuthorId local, SecretKey master,
|
public ContactId addContact(Author remote, AuthorId local, SecretKey master,
|
||||||
long timestamp, boolean alice, boolean active)
|
long timestamp, boolean alice, boolean active)
|
||||||
@@ -53,11 +65,8 @@ class ContactManagerImpl implements ContactManager, RemoveIdentityHook {
|
|||||||
ContactId c;
|
ContactId c;
|
||||||
Transaction txn = db.startTransaction(false);
|
Transaction txn = db.startTransaction(false);
|
||||||
try {
|
try {
|
||||||
c = db.addContact(txn, remote, local, active);
|
c = addContact(txn, remote, local, master, timestamp, alice,
|
||||||
keyManager.addContact(txn, c, master, timestamp, alice);
|
active);
|
||||||
Contact contact = db.getContact(txn, c);
|
|
||||||
for (AddContactHook hook : addHooks)
|
|
||||||
hook.addingContact(txn, contact);
|
|
||||||
txn.setComplete();
|
txn.setComplete();
|
||||||
} finally {
|
} finally {
|
||||||
db.endTransaction(txn);
|
db.endTransaction(txn);
|
||||||
|
|||||||
Reference in New Issue
Block a user