mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-12 18:59:06 +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;
|
||||
|
||||
interface AddContactHook {
|
||||
void addingContact(ContactId c);
|
||||
void addingContact(Contact c);
|
||||
}
|
||||
|
||||
interface RemoveContactHook {
|
||||
void removingContact(ContactId c);
|
||||
void removingContact(Contact c);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,10 +25,10 @@ public interface IdentityManager {
|
||||
void removeLocalAuthor(AuthorId a) throws DbException;
|
||||
|
||||
interface AddIdentityHook {
|
||||
void addingIdentity(AuthorId a);
|
||||
void addingIdentity(LocalAuthor a);
|
||||
}
|
||||
|
||||
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.AuthorId;
|
||||
import org.briarproject.api.identity.IdentityManager.RemoveIdentityHook;
|
||||
import org.briarproject.api.identity.LocalAuthor;
|
||||
import org.briarproject.api.lifecycle.Service;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@@ -54,12 +55,12 @@ class ContactManagerImpl implements ContactManager, Service,
|
||||
for (Contact c : db.getContacts()) {
|
||||
if (c.getStatus().equals(ADDING)) {
|
||||
for (AddContactHook hook : addHooks)
|
||||
hook.addingContact(c.getId());
|
||||
hook.addingContact(c);
|
||||
db.setContactStatus(c.getId(), ACTIVE);
|
||||
eventBus.broadcast(new ContactAddedEvent(c.getId()));
|
||||
} else if (c.getStatus().equals(REMOVING)) {
|
||||
for (RemoveContactHook hook : removeHooks)
|
||||
hook.removingContact(c.getId());
|
||||
hook.removingContact(c);
|
||||
db.removeContact(c.getId());
|
||||
eventBus.broadcast(new ContactRemovedEvent(c.getId()));
|
||||
}
|
||||
@@ -90,7 +91,8 @@ class ContactManagerImpl implements ContactManager, Service,
|
||||
public ContactId addContact(Author remote, AuthorId local)
|
||||
throws DbException {
|
||||
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);
|
||||
eventBus.broadcast(new ContactAddedEvent(c));
|
||||
return c;
|
||||
@@ -115,17 +117,19 @@ class ContactManagerImpl implements ContactManager, Service,
|
||||
|
||||
@Override
|
||||
public void removeContact(ContactId c) throws DbException {
|
||||
Contact contact = db.getContact(c);
|
||||
db.setContactStatus(c, REMOVING);
|
||||
for (RemoveContactHook hook : removeHooks) hook.removingContact(c);
|
||||
for (RemoveContactHook hook : removeHooks)
|
||||
hook.removingContact(contact);
|
||||
db.removeContact(c);
|
||||
eventBus.broadcast(new ContactRemovedEvent(c));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removingIdentity(AuthorId a) {
|
||||
public void removingIdentity(LocalAuthor a) {
|
||||
// Remove any contacts of the local pseudonym that's being removed
|
||||
try {
|
||||
for (ContactId c : db.getContacts(a)) removeContact(c);
|
||||
for (ContactId c : db.getContacts(a.getId())) removeContact(c);
|
||||
} catch (DbException 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.identity.Author;
|
||||
import org.briarproject.api.identity.AuthorId;
|
||||
import org.briarproject.api.identity.IdentityManager;
|
||||
import org.briarproject.api.identity.LocalAuthor;
|
||||
import org.briarproject.api.sync.ClientId;
|
||||
import org.briarproject.api.sync.Group;
|
||||
@@ -59,6 +60,7 @@ class ForumManagerImpl implements ForumManager {
|
||||
|
||||
private final DatabaseComponent db;
|
||||
private final ContactManager contactManager;
|
||||
private final IdentityManager identityManager;
|
||||
private final BdfReaderFactory bdfReaderFactory;
|
||||
private final MetadataEncoder metadataEncoder;
|
||||
private final MetadataParser metadataParser;
|
||||
@@ -68,10 +70,11 @@ class ForumManagerImpl implements ForumManager {
|
||||
|
||||
@Inject
|
||||
ForumManagerImpl(DatabaseComponent db, ContactManager contactManager,
|
||||
BdfReaderFactory bdfReaderFactory, MetadataEncoder metadataEncoder,
|
||||
MetadataParser metadataParser) {
|
||||
IdentityManager identityManager, BdfReaderFactory bdfReaderFactory,
|
||||
MetadataEncoder metadataEncoder, MetadataParser metadataParser) {
|
||||
this.db = db;
|
||||
this.contactManager = contactManager;
|
||||
this.identityManager = identityManager;
|
||||
this.bdfReaderFactory = bdfReaderFactory;
|
||||
this.metadataEncoder = metadataEncoder;
|
||||
this.metadataParser = metadataParser;
|
||||
@@ -173,7 +176,7 @@ class ForumManagerImpl implements ForumManager {
|
||||
try {
|
||||
// Load the IDs of the user's identities
|
||||
Set<AuthorId> localAuthorIds = new HashSet<AuthorId>();
|
||||
for (LocalAuthor a : db.getLocalAuthors())
|
||||
for (LocalAuthor a : identityManager.getLocalAuthors())
|
||||
localAuthorIds.add(a.getId());
|
||||
// Load the IDs of contacts' identities
|
||||
Set<AuthorId> contactAuthorIds = new HashSet<AuthorId>();
|
||||
|
||||
@@ -106,17 +106,17 @@ class ForumSharingManagerImpl implements ForumSharingManager, AddContactHook,
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addingContact(ContactId c) {
|
||||
public void addingContact(Contact c) {
|
||||
lock.writeLock().lock();
|
||||
try {
|
||||
// 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
|
||||
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
|
||||
BdfDictionary d = new BdfDictionary();
|
||||
d.put("contactId", c.getInt());
|
||||
d.put("contactId", c.getId().getInt());
|
||||
db.mergeGroupMetadata(g.getId(), metadataEncoder.encode(d));
|
||||
// Share any forums that are shared with all contacts
|
||||
List<Forum> shared = getForumsSharedWithAllContacts();
|
||||
@@ -131,10 +131,10 @@ class ForumSharingManagerImpl implements ForumSharingManager, AddContactHook,
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removingContact(ContactId c) {
|
||||
public void removingContact(Contact c) {
|
||||
lock.writeLock().lock();
|
||||
try {
|
||||
db.removeGroup(getContactGroup(db.getContact(c)));
|
||||
db.removeGroup(getContactGroup(c));
|
||||
} catch (DbException e) {
|
||||
if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
|
||||
} finally {
|
||||
|
||||
@@ -50,12 +50,12 @@ class IdentityManagerImpl implements IdentityManager, Service {
|
||||
for (LocalAuthor a : db.getLocalAuthors()) {
|
||||
if (a.getStatus().equals(ADDING)) {
|
||||
for (AddIdentityHook hook : addHooks)
|
||||
hook.addingIdentity(a.getId());
|
||||
hook.addingIdentity(a);
|
||||
db.setLocalAuthorStatus(a.getId(), ACTIVE);
|
||||
eventBus.broadcast(new LocalAuthorAddedEvent(a.getId()));
|
||||
} else if (a.getStatus().equals(REMOVING)) {
|
||||
for (RemoveIdentityHook hook : removeHooks)
|
||||
hook.removingIdentity(a.getId());
|
||||
hook.removingIdentity(a);
|
||||
db.removeLocalAuthor(a.getId());
|
||||
eventBus.broadcast(new LocalAuthorRemovedEvent(a.getId()));
|
||||
}
|
||||
@@ -83,11 +83,11 @@ class IdentityManagerImpl implements IdentityManager, Service {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addLocalAuthor(LocalAuthor a) throws DbException {
|
||||
db.addLocalAuthor(a);
|
||||
for (AddIdentityHook hook : addHooks) hook.addingIdentity(a.getId());
|
||||
db.setLocalAuthorStatus(a.getId(), ACTIVE);
|
||||
eventBus.broadcast(new LocalAuthorAddedEvent(a.getId()));
|
||||
public void addLocalAuthor(LocalAuthor localAuthor) throws DbException {
|
||||
db.addLocalAuthor(localAuthor);
|
||||
for (AddIdentityHook hook : addHooks) hook.addingIdentity(localAuthor);
|
||||
db.setLocalAuthorStatus(localAuthor.getId(), ACTIVE);
|
||||
eventBus.broadcast(new LocalAuthorAddedEvent(localAuthor.getId()));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -109,8 +109,10 @@ class IdentityManagerImpl implements IdentityManager, Service {
|
||||
|
||||
@Override
|
||||
public void removeLocalAuthor(AuthorId a) throws DbException {
|
||||
LocalAuthor localAuthor = db.getLocalAuthor(a);
|
||||
db.setLocalAuthorStatus(a, REMOVING);
|
||||
for (RemoveIdentityHook hook : removeHooks) hook.removingIdentity(a);
|
||||
for (RemoveIdentityHook hook : removeHooks)
|
||||
hook.removingIdentity(localAuthor);
|
||||
db.removeLocalAuthor(a);
|
||||
eventBus.broadcast(new LocalAuthorRemovedEvent(a));
|
||||
}
|
||||
|
||||
@@ -71,16 +71,16 @@ class MessagingManagerImpl implements MessagingManager, AddContactHook,
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addingContact(ContactId c) {
|
||||
public void addingContact(Contact c) {
|
||||
try {
|
||||
// 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
|
||||
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
|
||||
BdfDictionary d = new BdfDictionary();
|
||||
d.put("contactId", c.getInt());
|
||||
d.put("contactId", c.getId().getInt());
|
||||
db.mergeGroupMetadata(g.getId(), metadataEncoder.encode(d));
|
||||
} catch (DbException e) {
|
||||
if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
|
||||
@@ -94,9 +94,9 @@ class MessagingManagerImpl implements MessagingManager, AddContactHook,
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removingContact(ContactId c) {
|
||||
public void removingContact(Contact c) {
|
||||
try {
|
||||
db.removeGroup(getContactGroup(db.getContact(c)));
|
||||
db.removeGroup(getContactGroup(c));
|
||||
} catch (DbException e) {
|
||||
if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
|
||||
}
|
||||
|
||||
@@ -95,14 +95,14 @@ class TransportPropertyManagerImpl implements TransportPropertyManager,
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addingContact(ContactId c) {
|
||||
public void addingContact(Contact c) {
|
||||
lock.writeLock().lock();
|
||||
try {
|
||||
// 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
|
||||
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
|
||||
DeviceId dev = db.getDeviceId();
|
||||
Map<TransportId, TransportProperties> local = getLocalProperties();
|
||||
@@ -120,10 +120,10 @@ class TransportPropertyManagerImpl implements TransportPropertyManager,
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removingContact(ContactId c) {
|
||||
public void removingContact(Contact c) {
|
||||
lock.writeLock().lock();
|
||||
try {
|
||||
db.removeGroup(getContactGroup(db.getContact(c)));
|
||||
db.removeGroup(getContactGroup(c));
|
||||
} catch (DbException e) {
|
||||
if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
|
||||
} finally {
|
||||
@@ -136,7 +136,7 @@ class TransportPropertyManagerImpl implements TransportPropertyManager,
|
||||
Map<TransportId, TransportProperties> props) throws DbException {
|
||||
lock.writeLock().lock();
|
||||
try {
|
||||
Group g = getContactGroup(db.getContact(c));
|
||||
Group g = getContactGroup(contactManager.getContact(c));
|
||||
for (Entry<TransportId, TransportProperties> e : props.entrySet()) {
|
||||
storeMessage(g.getId(), dev, e.getKey(), e.getValue(), 0, 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