* The event
*/
@Subscribe
public void identityRemoved(IdentityRemovedEvent identityRemovedEvent) {
OwnIdentity ownIdentity = identityRemovedEvent.ownIdentity();
Identity identity = identityRemovedEvent.identity();
trustedIdentities.remove(ownIdentity, identity);
boolean foundIdentity = false;
for (Entry<OwnIdentity, Collection<Identity>> trustedIdentity : trustedIdentities.asMap().entrySet()) {
if (trustedIdentity.getKey().equals(ownIdentity)) {
continue;
}
if (trustedIdentity.getValue().contains(identity)) {
foundIdentity = true;
}
}
if (foundIdentity) {
/* some local identity still trusts this identity, don’t remove. */
return;
}
Optional<Sone> sone = getSone(identity.getId());
if (!sone.isPresent()) {
/* TODO - we don’t have the Sone anymore. should this happen? */
return;
}
database.removePosts(sone.get());
for (Post post : sone.get().getPosts()) {
eventBus.post(new PostRemovedEvent(post));
}
database.removePostReplies(sone.get());
for (PostReply reply : sone.get().getReplies()) {
eventBus.post(new PostReplyRemovedEvent(reply));
}
synchronized (sones) {
sones.remove(identity.getId());
}
eventBus.post(new SoneRemovedEvent(sone.get()));
}