Identity manager hooks. #209

This commit is contained in:
akwizgran
2016-01-20 12:03:15 +00:00
parent 82cf12040f
commit c4692a7007
16 changed files with 258 additions and 53 deletions

View File

@@ -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);
}
}
}

View File

@@ -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;
}
}