mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-17 21:29:54 +01:00
Identity manager hooks. #209
This commit is contained in:
@@ -13,6 +13,7 @@ import org.briarproject.api.event.ContactRemovedEvent;
|
||||
import org.briarproject.api.event.EventBus;
|
||||
import org.briarproject.api.identity.Author;
|
||||
import org.briarproject.api.identity.AuthorId;
|
||||
import org.briarproject.api.identity.IdentityManager.IdentityRemovedHook;
|
||||
import org.briarproject.api.lifecycle.Service;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@@ -27,7 +28,8 @@ import static org.briarproject.api.contact.Contact.Status.ACTIVE;
|
||||
import static org.briarproject.api.contact.Contact.Status.ADDING;
|
||||
import static org.briarproject.api.contact.Contact.Status.REMOVING;
|
||||
|
||||
class ContactManagerImpl implements ContactManager, Service {
|
||||
class ContactManagerImpl implements ContactManager, Service,
|
||||
IdentityRemovedHook {
|
||||
|
||||
private static final Logger LOG =
|
||||
Logger.getLogger(ContactManagerImpl.class.getName());
|
||||
@@ -118,4 +120,14 @@ class ContactManagerImpl implements ContactManager, Service {
|
||||
db.removeContact(c);
|
||||
eventBus.broadcast(new ContactRemovedEvent(c));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void identityRemoved(AuthorId a) {
|
||||
// Remove any contacts of the local pseudonym that's being removed
|
||||
try {
|
||||
for (ContactId c : db.getContacts(a)) removeContact(c);
|
||||
} catch (DbException e) {
|
||||
if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ import com.google.inject.AbstractModule;
|
||||
import com.google.inject.Provides;
|
||||
|
||||
import org.briarproject.api.contact.ContactManager;
|
||||
import org.briarproject.api.identity.IdentityManager;
|
||||
import org.briarproject.api.lifecycle.LifecycleManager;
|
||||
|
||||
import javax.inject.Singleton;
|
||||
@@ -15,8 +16,10 @@ public class ContactModule extends AbstractModule {
|
||||
|
||||
@Provides @Singleton
|
||||
ContactManager getContactManager(LifecycleManager lifecycleManager,
|
||||
IdentityManager identityManager,
|
||||
ContactManagerImpl contactManager) {
|
||||
lifecycleManager.register(contactManager);
|
||||
identityManager.registerIdentityRemovedHook(contactManager);
|
||||
return contactManager;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user