mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-18 21:59:54 +01:00
Removed direct calls to DB's contact/identity methods.
This commit is contained in:
@@ -30,10 +30,10 @@ public interface ContactManager {
|
|||||||
void removeContact(ContactId c) throws DbException;
|
void removeContact(ContactId c) throws DbException;
|
||||||
|
|
||||||
interface AddContactHook {
|
interface AddContactHook {
|
||||||
void addingContact(ContactId c);
|
void addingContact(Contact c);
|
||||||
}
|
}
|
||||||
|
|
||||||
interface RemoveContactHook {
|
interface RemoveContactHook {
|
||||||
void removingContact(ContactId c);
|
void removingContact(Contact c);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,10 +25,10 @@ public interface IdentityManager {
|
|||||||
void removeLocalAuthor(AuthorId a) throws DbException;
|
void removeLocalAuthor(AuthorId a) throws DbException;
|
||||||
|
|
||||||
interface AddIdentityHook {
|
interface AddIdentityHook {
|
||||||
void addingIdentity(AuthorId a);
|
void addingIdentity(LocalAuthor a);
|
||||||
}
|
}
|
||||||
|
|
||||||
interface RemoveIdentityHook {
|
interface RemoveIdentityHook {
|
||||||
void removingIdentity(AuthorId a);
|
void removingIdentity(LocalAuthor a);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ import org.briarproject.api.event.EventBus;
|
|||||||
import org.briarproject.api.identity.Author;
|
import org.briarproject.api.identity.Author;
|
||||||
import org.briarproject.api.identity.AuthorId;
|
import org.briarproject.api.identity.AuthorId;
|
||||||
import org.briarproject.api.identity.IdentityManager.RemoveIdentityHook;
|
import org.briarproject.api.identity.IdentityManager.RemoveIdentityHook;
|
||||||
|
import org.briarproject.api.identity.LocalAuthor;
|
||||||
import org.briarproject.api.lifecycle.Service;
|
import org.briarproject.api.lifecycle.Service;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@@ -54,12 +55,12 @@ class ContactManagerImpl implements ContactManager, Service,
|
|||||||
for (Contact c : db.getContacts()) {
|
for (Contact c : db.getContacts()) {
|
||||||
if (c.getStatus().equals(ADDING)) {
|
if (c.getStatus().equals(ADDING)) {
|
||||||
for (AddContactHook hook : addHooks)
|
for (AddContactHook hook : addHooks)
|
||||||
hook.addingContact(c.getId());
|
hook.addingContact(c);
|
||||||
db.setContactStatus(c.getId(), ACTIVE);
|
db.setContactStatus(c.getId(), ACTIVE);
|
||||||
eventBus.broadcast(new ContactAddedEvent(c.getId()));
|
eventBus.broadcast(new ContactAddedEvent(c.getId()));
|
||||||
} else if (c.getStatus().equals(REMOVING)) {
|
} else if (c.getStatus().equals(REMOVING)) {
|
||||||
for (RemoveContactHook hook : removeHooks)
|
for (RemoveContactHook hook : removeHooks)
|
||||||
hook.removingContact(c.getId());
|
hook.removingContact(c);
|
||||||
db.removeContact(c.getId());
|
db.removeContact(c.getId());
|
||||||
eventBus.broadcast(new ContactRemovedEvent(c.getId()));
|
eventBus.broadcast(new ContactRemovedEvent(c.getId()));
|
||||||
}
|
}
|
||||||
@@ -90,7 +91,8 @@ class ContactManagerImpl implements ContactManager, Service,
|
|||||||
public ContactId addContact(Author remote, AuthorId local)
|
public ContactId addContact(Author remote, AuthorId local)
|
||||||
throws DbException {
|
throws DbException {
|
||||||
ContactId c = db.addContact(remote, local);
|
ContactId c = db.addContact(remote, local);
|
||||||
for (AddContactHook hook : addHooks) hook.addingContact(c);
|
Contact contact = db.getContact(c);
|
||||||
|
for (AddContactHook hook : addHooks) hook.addingContact(contact);
|
||||||
db.setContactStatus(c, ACTIVE);
|
db.setContactStatus(c, ACTIVE);
|
||||||
eventBus.broadcast(new ContactAddedEvent(c));
|
eventBus.broadcast(new ContactAddedEvent(c));
|
||||||
return c;
|
return c;
|
||||||
@@ -115,17 +117,19 @@ class ContactManagerImpl implements ContactManager, Service,
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void removeContact(ContactId c) throws DbException {
|
public void removeContact(ContactId c) throws DbException {
|
||||||
|
Contact contact = db.getContact(c);
|
||||||
db.setContactStatus(c, REMOVING);
|
db.setContactStatus(c, REMOVING);
|
||||||
for (RemoveContactHook hook : removeHooks) hook.removingContact(c);
|
for (RemoveContactHook hook : removeHooks)
|
||||||
|
hook.removingContact(contact);
|
||||||
db.removeContact(c);
|
db.removeContact(c);
|
||||||
eventBus.broadcast(new ContactRemovedEvent(c));
|
eventBus.broadcast(new ContactRemovedEvent(c));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void removingIdentity(AuthorId a) {
|
public void removingIdentity(LocalAuthor a) {
|
||||||
// Remove any contacts of the local pseudonym that's being removed
|
// Remove any contacts of the local pseudonym that's being removed
|
||||||
try {
|
try {
|
||||||
for (ContactId c : db.getContacts(a)) removeContact(c);
|
for (ContactId c : db.getContacts(a.getId())) removeContact(c);
|
||||||
} catch (DbException e) {
|
} catch (DbException e) {
|
||||||
if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
|
if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ import org.briarproject.api.forum.ForumPost;
|
|||||||
import org.briarproject.api.forum.ForumPostHeader;
|
import org.briarproject.api.forum.ForumPostHeader;
|
||||||
import org.briarproject.api.identity.Author;
|
import org.briarproject.api.identity.Author;
|
||||||
import org.briarproject.api.identity.AuthorId;
|
import org.briarproject.api.identity.AuthorId;
|
||||||
|
import org.briarproject.api.identity.IdentityManager;
|
||||||
import org.briarproject.api.identity.LocalAuthor;
|
import org.briarproject.api.identity.LocalAuthor;
|
||||||
import org.briarproject.api.sync.ClientId;
|
import org.briarproject.api.sync.ClientId;
|
||||||
import org.briarproject.api.sync.Group;
|
import org.briarproject.api.sync.Group;
|
||||||
@@ -59,6 +60,7 @@ class ForumManagerImpl implements ForumManager {
|
|||||||
|
|
||||||
private final DatabaseComponent db;
|
private final DatabaseComponent db;
|
||||||
private final ContactManager contactManager;
|
private final ContactManager contactManager;
|
||||||
|
private final IdentityManager identityManager;
|
||||||
private final BdfReaderFactory bdfReaderFactory;
|
private final BdfReaderFactory bdfReaderFactory;
|
||||||
private final MetadataEncoder metadataEncoder;
|
private final MetadataEncoder metadataEncoder;
|
||||||
private final MetadataParser metadataParser;
|
private final MetadataParser metadataParser;
|
||||||
@@ -68,10 +70,11 @@ class ForumManagerImpl implements ForumManager {
|
|||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
ForumManagerImpl(DatabaseComponent db, ContactManager contactManager,
|
ForumManagerImpl(DatabaseComponent db, ContactManager contactManager,
|
||||||
BdfReaderFactory bdfReaderFactory, MetadataEncoder metadataEncoder,
|
IdentityManager identityManager, BdfReaderFactory bdfReaderFactory,
|
||||||
MetadataParser metadataParser) {
|
MetadataEncoder metadataEncoder, MetadataParser metadataParser) {
|
||||||
this.db = db;
|
this.db = db;
|
||||||
this.contactManager = contactManager;
|
this.contactManager = contactManager;
|
||||||
|
this.identityManager = identityManager;
|
||||||
this.bdfReaderFactory = bdfReaderFactory;
|
this.bdfReaderFactory = bdfReaderFactory;
|
||||||
this.metadataEncoder = metadataEncoder;
|
this.metadataEncoder = metadataEncoder;
|
||||||
this.metadataParser = metadataParser;
|
this.metadataParser = metadataParser;
|
||||||
@@ -173,7 +176,7 @@ class ForumManagerImpl implements ForumManager {
|
|||||||
try {
|
try {
|
||||||
// Load the IDs of the user's identities
|
// Load the IDs of the user's identities
|
||||||
Set<AuthorId> localAuthorIds = new HashSet<AuthorId>();
|
Set<AuthorId> localAuthorIds = new HashSet<AuthorId>();
|
||||||
for (LocalAuthor a : db.getLocalAuthors())
|
for (LocalAuthor a : identityManager.getLocalAuthors())
|
||||||
localAuthorIds.add(a.getId());
|
localAuthorIds.add(a.getId());
|
||||||
// Load the IDs of contacts' identities
|
// Load the IDs of contacts' identities
|
||||||
Set<AuthorId> contactAuthorIds = new HashSet<AuthorId>();
|
Set<AuthorId> contactAuthorIds = new HashSet<AuthorId>();
|
||||||
|
|||||||
@@ -106,17 +106,17 @@ class ForumSharingManagerImpl implements ForumSharingManager, AddContactHook,
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void addingContact(ContactId c) {
|
public void addingContact(Contact c) {
|
||||||
lock.writeLock().lock();
|
lock.writeLock().lock();
|
||||||
try {
|
try {
|
||||||
// Create a group to share with the contact
|
// Create a group to share with the contact
|
||||||
Group g = getContactGroup(db.getContact(c));
|
Group g = getContactGroup(c);
|
||||||
// Store the group and share it with the contact
|
// Store the group and share it with the contact
|
||||||
db.addGroup(g);
|
db.addGroup(g);
|
||||||
db.setVisibility(g.getId(), Collections.singletonList(c));
|
db.setVisibility(g.getId(), Collections.singletonList(c.getId()));
|
||||||
// Attach the contact ID to the group
|
// Attach the contact ID to the group
|
||||||
BdfDictionary d = new BdfDictionary();
|
BdfDictionary d = new BdfDictionary();
|
||||||
d.put("contactId", c.getInt());
|
d.put("contactId", c.getId().getInt());
|
||||||
db.mergeGroupMetadata(g.getId(), metadataEncoder.encode(d));
|
db.mergeGroupMetadata(g.getId(), metadataEncoder.encode(d));
|
||||||
// Share any forums that are shared with all contacts
|
// Share any forums that are shared with all contacts
|
||||||
List<Forum> shared = getForumsSharedWithAllContacts();
|
List<Forum> shared = getForumsSharedWithAllContacts();
|
||||||
@@ -131,10 +131,10 @@ class ForumSharingManagerImpl implements ForumSharingManager, AddContactHook,
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void removingContact(ContactId c) {
|
public void removingContact(Contact c) {
|
||||||
lock.writeLock().lock();
|
lock.writeLock().lock();
|
||||||
try {
|
try {
|
||||||
db.removeGroup(getContactGroup(db.getContact(c)));
|
db.removeGroup(getContactGroup(c));
|
||||||
} catch (DbException e) {
|
} catch (DbException e) {
|
||||||
if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
|
if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
|
||||||
} finally {
|
} finally {
|
||||||
|
|||||||
@@ -50,12 +50,12 @@ class IdentityManagerImpl implements IdentityManager, Service {
|
|||||||
for (LocalAuthor a : db.getLocalAuthors()) {
|
for (LocalAuthor a : db.getLocalAuthors()) {
|
||||||
if (a.getStatus().equals(ADDING)) {
|
if (a.getStatus().equals(ADDING)) {
|
||||||
for (AddIdentityHook hook : addHooks)
|
for (AddIdentityHook hook : addHooks)
|
||||||
hook.addingIdentity(a.getId());
|
hook.addingIdentity(a);
|
||||||
db.setLocalAuthorStatus(a.getId(), ACTIVE);
|
db.setLocalAuthorStatus(a.getId(), ACTIVE);
|
||||||
eventBus.broadcast(new LocalAuthorAddedEvent(a.getId()));
|
eventBus.broadcast(new LocalAuthorAddedEvent(a.getId()));
|
||||||
} else if (a.getStatus().equals(REMOVING)) {
|
} else if (a.getStatus().equals(REMOVING)) {
|
||||||
for (RemoveIdentityHook hook : removeHooks)
|
for (RemoveIdentityHook hook : removeHooks)
|
||||||
hook.removingIdentity(a.getId());
|
hook.removingIdentity(a);
|
||||||
db.removeLocalAuthor(a.getId());
|
db.removeLocalAuthor(a.getId());
|
||||||
eventBus.broadcast(new LocalAuthorRemovedEvent(a.getId()));
|
eventBus.broadcast(new LocalAuthorRemovedEvent(a.getId()));
|
||||||
}
|
}
|
||||||
@@ -83,11 +83,11 @@ class IdentityManagerImpl implements IdentityManager, Service {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void addLocalAuthor(LocalAuthor a) throws DbException {
|
public void addLocalAuthor(LocalAuthor localAuthor) throws DbException {
|
||||||
db.addLocalAuthor(a);
|
db.addLocalAuthor(localAuthor);
|
||||||
for (AddIdentityHook hook : addHooks) hook.addingIdentity(a.getId());
|
for (AddIdentityHook hook : addHooks) hook.addingIdentity(localAuthor);
|
||||||
db.setLocalAuthorStatus(a.getId(), ACTIVE);
|
db.setLocalAuthorStatus(localAuthor.getId(), ACTIVE);
|
||||||
eventBus.broadcast(new LocalAuthorAddedEvent(a.getId()));
|
eventBus.broadcast(new LocalAuthorAddedEvent(localAuthor.getId()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -109,8 +109,10 @@ class IdentityManagerImpl implements IdentityManager, Service {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void removeLocalAuthor(AuthorId a) throws DbException {
|
public void removeLocalAuthor(AuthorId a) throws DbException {
|
||||||
|
LocalAuthor localAuthor = db.getLocalAuthor(a);
|
||||||
db.setLocalAuthorStatus(a, REMOVING);
|
db.setLocalAuthorStatus(a, REMOVING);
|
||||||
for (RemoveIdentityHook hook : removeHooks) hook.removingIdentity(a);
|
for (RemoveIdentityHook hook : removeHooks)
|
||||||
|
hook.removingIdentity(localAuthor);
|
||||||
db.removeLocalAuthor(a);
|
db.removeLocalAuthor(a);
|
||||||
eventBus.broadcast(new LocalAuthorRemovedEvent(a));
|
eventBus.broadcast(new LocalAuthorRemovedEvent(a));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -71,16 +71,16 @@ class MessagingManagerImpl implements MessagingManager, AddContactHook,
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void addingContact(ContactId c) {
|
public void addingContact(Contact c) {
|
||||||
try {
|
try {
|
||||||
// Create a group to share with the contact
|
// Create a group to share with the contact
|
||||||
Group g = getContactGroup(db.getContact(c));
|
Group g = getContactGroup(c);
|
||||||
// Store the group and share it with the contact
|
// Store the group and share it with the contact
|
||||||
db.addGroup(g);
|
db.addGroup(g);
|
||||||
db.setVisibility(g.getId(), Collections.singletonList(c));
|
db.setVisibility(g.getId(), Collections.singletonList(c.getId()));
|
||||||
// Attach the contact ID to the group
|
// Attach the contact ID to the group
|
||||||
BdfDictionary d = new BdfDictionary();
|
BdfDictionary d = new BdfDictionary();
|
||||||
d.put("contactId", c.getInt());
|
d.put("contactId", c.getId().getInt());
|
||||||
db.mergeGroupMetadata(g.getId(), metadataEncoder.encode(d));
|
db.mergeGroupMetadata(g.getId(), metadataEncoder.encode(d));
|
||||||
} catch (DbException e) {
|
} catch (DbException e) {
|
||||||
if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
|
if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
|
||||||
@@ -94,9 +94,9 @@ class MessagingManagerImpl implements MessagingManager, AddContactHook,
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void removingContact(ContactId c) {
|
public void removingContact(Contact c) {
|
||||||
try {
|
try {
|
||||||
db.removeGroup(getContactGroup(db.getContact(c)));
|
db.removeGroup(getContactGroup(c));
|
||||||
} catch (DbException e) {
|
} catch (DbException e) {
|
||||||
if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
|
if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -95,14 +95,14 @@ class TransportPropertyManagerImpl implements TransportPropertyManager,
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void addingContact(ContactId c) {
|
public void addingContact(Contact c) {
|
||||||
lock.writeLock().lock();
|
lock.writeLock().lock();
|
||||||
try {
|
try {
|
||||||
// Create a group to share with the contact
|
// Create a group to share with the contact
|
||||||
Group g = getContactGroup(db.getContact(c));
|
Group g = getContactGroup(c);
|
||||||
// Store the group and share it with the contact
|
// Store the group and share it with the contact
|
||||||
db.addGroup(g);
|
db.addGroup(g);
|
||||||
db.setVisibility(g.getId(), Collections.singletonList(c));
|
db.setVisibility(g.getId(), Collections.singletonList(c.getId()));
|
||||||
// Copy the latest local properties into the group
|
// Copy the latest local properties into the group
|
||||||
DeviceId dev = db.getDeviceId();
|
DeviceId dev = db.getDeviceId();
|
||||||
Map<TransportId, TransportProperties> local = getLocalProperties();
|
Map<TransportId, TransportProperties> local = getLocalProperties();
|
||||||
@@ -120,10 +120,10 @@ class TransportPropertyManagerImpl implements TransportPropertyManager,
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void removingContact(ContactId c) {
|
public void removingContact(Contact c) {
|
||||||
lock.writeLock().lock();
|
lock.writeLock().lock();
|
||||||
try {
|
try {
|
||||||
db.removeGroup(getContactGroup(db.getContact(c)));
|
db.removeGroup(getContactGroup(c));
|
||||||
} catch (DbException e) {
|
} catch (DbException e) {
|
||||||
if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
|
if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
|
||||||
} finally {
|
} finally {
|
||||||
@@ -136,7 +136,7 @@ class TransportPropertyManagerImpl implements TransportPropertyManager,
|
|||||||
Map<TransportId, TransportProperties> props) throws DbException {
|
Map<TransportId, TransportProperties> props) throws DbException {
|
||||||
lock.writeLock().lock();
|
lock.writeLock().lock();
|
||||||
try {
|
try {
|
||||||
Group g = getContactGroup(db.getContact(c));
|
Group g = getContactGroup(contactManager.getContact(c));
|
||||||
for (Entry<TransportId, TransportProperties> e : props.entrySet()) {
|
for (Entry<TransportId, TransportProperties> e : props.entrySet()) {
|
||||||
storeMessage(g.getId(), dev, e.getKey(), e.getValue(), 0, false,
|
storeMessage(g.getId(), dev, e.getKey(), e.getValue(), 0, false,
|
||||||
false);
|
false);
|
||||||
|
|||||||
@@ -0,0 +1,14 @@
|
|||||||
|
package org.briarproject.contact;
|
||||||
|
|
||||||
|
import org.briarproject.BriarTestCase;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import static org.junit.Assert.fail;
|
||||||
|
|
||||||
|
public class ContactManagerImplTest extends BriarTestCase {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testUnitTestsExist() {
|
||||||
|
fail(); // FIXME: Write tests
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
package org.briarproject.identity;
|
||||||
|
|
||||||
|
import org.briarproject.BriarTestCase;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import static org.junit.Assert.fail;
|
||||||
|
|
||||||
|
public class IdentityManagerImplTest extends BriarTestCase {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testUnitTestsExist() {
|
||||||
|
fail(); // FIXME: Write tests
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user