Merge branch '41-alias-author-info' into 'master'

Refactor Author.Status into dedicated AuthorInfo class and add alias

See merge request briar/briar!968
This commit is contained in:
Torsten Grote
2018-10-30 19:33:39 +00:00
40 changed files with 473 additions and 283 deletions

View File

@@ -5,6 +5,7 @@ import org.briarproject.bramble.api.db.DbException;
import org.briarproject.bramble.api.db.Transaction; import org.briarproject.bramble.api.db.Transaction;
import org.briarproject.bramble.api.identity.Author; import org.briarproject.bramble.api.identity.Author;
import org.briarproject.bramble.api.identity.AuthorId; import org.briarproject.bramble.api.identity.AuthorId;
import org.briarproject.bramble.api.identity.AuthorInfo;
import org.briarproject.bramble.api.lifecycle.LifecycleManager; import org.briarproject.bramble.api.lifecycle.LifecycleManager;
import org.briarproject.bramble.api.nullsafety.NotNullByDefault; import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
@@ -113,6 +114,16 @@ public interface ContactManager {
boolean contactExists(AuthorId remoteAuthorId, AuthorId localAuthorId) boolean contactExists(AuthorId remoteAuthorId, AuthorId localAuthorId)
throws DbException; throws DbException;
/**
* Returns the {@link AuthorInfo} for the given author.
*/
AuthorInfo getAuthorInfo(AuthorId a) throws DbException;
/**
* Returns the {@link AuthorInfo} for the given author.
*/
AuthorInfo getAuthorInfo(Transaction txn, AuthorId a) throws DbException;
interface ContactHook { interface ContactHook {
void addingContact(Transaction txn, Contact c) throws DbException; void addingContact(Transaction txn, Contact c) throws DbException;

View File

@@ -16,10 +16,6 @@ import static org.briarproject.bramble.api.identity.AuthorConstants.MAX_PUBLIC_K
@NotNullByDefault @NotNullByDefault
public class Author implements Nameable { public class Author implements Nameable {
public enum Status {
NONE, ANONYMOUS, UNKNOWN, UNVERIFIED, VERIFIED, OURSELVES
}
/** /**
* The current version of the author structure. * The current version of the author structure.
*/ */

View File

@@ -0,0 +1,52 @@
package org.briarproject.bramble.api.identity;
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
import javax.annotation.Nullable;
import javax.annotation.concurrent.Immutable;
@Immutable
@NotNullByDefault
public class AuthorInfo {
public enum Status {
NONE, ANONYMOUS, UNKNOWN, UNVERIFIED, VERIFIED, OURSELVES
}
private final Status status;
@Nullable
private final String alias;
public AuthorInfo(Status status, @Nullable String alias) {
this.status = status;
this.alias = alias;
}
public AuthorInfo(Status status) {
this(status, null);
}
public Status getStatus() {
return status;
}
@Nullable
public String getAlias() {
return alias;
}
@Override
public int hashCode() {
int hashCode = status.ordinal();
if (alias != null) hashCode += alias.hashCode();
return hashCode;
}
@Override
public boolean equals(Object o) {
if (!(o instanceof AuthorInfo)) return false;
AuthorInfo info = (AuthorInfo) o;
return status == info.status &&
(alias == null ? info.alias == null : alias.equals(info.alias));
}
}

View File

@@ -3,7 +3,6 @@ package org.briarproject.bramble.api.identity;
import org.briarproject.bramble.api.crypto.CryptoExecutor; import org.briarproject.bramble.api.crypto.CryptoExecutor;
import org.briarproject.bramble.api.db.DbException; import org.briarproject.bramble.api.db.DbException;
import org.briarproject.bramble.api.db.Transaction; import org.briarproject.bramble.api.db.Transaction;
import org.briarproject.bramble.api.identity.Author.Status;
import org.briarproject.bramble.api.nullsafety.NotNullByDefault; import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
@NotNullByDefault @NotNullByDefault
@@ -37,14 +36,4 @@ public interface IdentityManager {
*/ */
LocalAuthor getLocalAuthor(Transaction txn) throws DbException; LocalAuthor getLocalAuthor(Transaction txn) throws DbException;
/**
* Returns the {@link Status} of the given author.
*/
Status getAuthorStatus(AuthorId a) throws DbException;
/**
* Returns the {@link Status} of the given author.
*/
Status getAuthorStatus(Transaction txn, AuthorId a) throws DbException;
} }

View File

@@ -0,0 +1,42 @@
package org.briarproject.bramble.api.identity;
import org.briarproject.bramble.test.BrambleTestCase;
import org.junit.Test;
import static org.briarproject.bramble.api.identity.AuthorInfo.Status.NONE;
import static org.briarproject.bramble.api.identity.AuthorInfo.Status.VERIFIED;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotEquals;
public class AuthorInfoTest extends BrambleTestCase {
@Test
public void testEquals() {
assertEquals(
new AuthorInfo(NONE),
new AuthorInfo(NONE, null)
);
assertEquals(
new AuthorInfo(NONE, "test"),
new AuthorInfo(NONE, "test")
);
assertNotEquals(
new AuthorInfo(NONE),
new AuthorInfo(VERIFIED)
);
assertNotEquals(
new AuthorInfo(NONE, "test"),
new AuthorInfo(NONE)
);
assertNotEquals(
new AuthorInfo(NONE),
new AuthorInfo(NONE, "test")
);
assertNotEquals(
new AuthorInfo(NONE, "a"),
new AuthorInfo(NONE, "b")
);
}
}

View File

@@ -10,6 +10,9 @@ import org.briarproject.bramble.api.db.NoSuchContactException;
import org.briarproject.bramble.api.db.Transaction; import org.briarproject.bramble.api.db.Transaction;
import org.briarproject.bramble.api.identity.Author; import org.briarproject.bramble.api.identity.Author;
import org.briarproject.bramble.api.identity.AuthorId; import org.briarproject.bramble.api.identity.AuthorId;
import org.briarproject.bramble.api.identity.AuthorInfo;
import org.briarproject.bramble.api.identity.IdentityManager;
import org.briarproject.bramble.api.identity.LocalAuthor;
import org.briarproject.bramble.api.nullsafety.NotNullByDefault; import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
import org.briarproject.bramble.api.transport.KeyManager; import org.briarproject.bramble.api.transport.KeyManager;
@@ -23,6 +26,10 @@ import javax.annotation.concurrent.ThreadSafe;
import javax.inject.Inject; import javax.inject.Inject;
import static org.briarproject.bramble.api.identity.AuthorConstants.MAX_AUTHOR_NAME_LENGTH; import static org.briarproject.bramble.api.identity.AuthorConstants.MAX_AUTHOR_NAME_LENGTH;
import static org.briarproject.bramble.api.identity.AuthorInfo.Status.OURSELVES;
import static org.briarproject.bramble.api.identity.AuthorInfo.Status.UNKNOWN;
import static org.briarproject.bramble.api.identity.AuthorInfo.Status.UNVERIFIED;
import static org.briarproject.bramble.api.identity.AuthorInfo.Status.VERIFIED;
import static org.briarproject.bramble.util.StringUtils.toUtf8; import static org.briarproject.bramble.util.StringUtils.toUtf8;
@ThreadSafe @ThreadSafe
@@ -31,12 +38,15 @@ class ContactManagerImpl implements ContactManager {
private final DatabaseComponent db; private final DatabaseComponent db;
private final KeyManager keyManager; private final KeyManager keyManager;
private final IdentityManager identityManager;
private final List<ContactHook> hooks; private final List<ContactHook> hooks;
@Inject @Inject
ContactManagerImpl(DatabaseComponent db, KeyManager keyManager) { ContactManagerImpl(DatabaseComponent db, KeyManager keyManager,
IdentityManager identityManager) {
this.db = db; this.db = db;
this.keyManager = keyManager; this.keyManager = keyManager;
this.identityManager = identityManager;
hooks = new CopyOnWriteArrayList<>(); hooks = new CopyOnWriteArrayList<>();
} }
@@ -191,4 +201,23 @@ class ContactManagerImpl implements ContactManager {
db.removeContact(txn, c); db.removeContact(txn, c);
} }
@Override
public AuthorInfo getAuthorInfo(AuthorId a) throws DbException {
return db.transactionWithResult(true, txn -> getAuthorInfo(txn, a));
}
@Override
public AuthorInfo getAuthorInfo(Transaction txn, AuthorId authorId)
throws DbException {
LocalAuthor localAuthor = identityManager.getLocalAuthor(txn);
if (localAuthor.getId().equals(authorId))
return new AuthorInfo(OURSELVES);
Collection<Contact> contacts = db.getContactsByAuthorId(txn, authorId);
if (contacts.isEmpty()) return new AuthorInfo(UNKNOWN);
if (contacts.size() > 1) throw new AssertionError();
Contact c = contacts.iterator().next();
if (c.isVerified()) return new AuthorInfo(VERIFIED, c.getAlias());
else return new AuthorInfo(UNVERIFIED, c.getAlias());
}
} }

View File

@@ -1,29 +1,21 @@
package org.briarproject.bramble.identity; package org.briarproject.bramble.identity;
import org.briarproject.bramble.api.contact.Contact;
import org.briarproject.bramble.api.crypto.CryptoComponent; import org.briarproject.bramble.api.crypto.CryptoComponent;
import org.briarproject.bramble.api.crypto.KeyPair; import org.briarproject.bramble.api.crypto.KeyPair;
import org.briarproject.bramble.api.db.DatabaseComponent; import org.briarproject.bramble.api.db.DatabaseComponent;
import org.briarproject.bramble.api.db.DbException; import org.briarproject.bramble.api.db.DbException;
import org.briarproject.bramble.api.db.Transaction; import org.briarproject.bramble.api.db.Transaction;
import org.briarproject.bramble.api.identity.Author.Status;
import org.briarproject.bramble.api.identity.AuthorFactory; import org.briarproject.bramble.api.identity.AuthorFactory;
import org.briarproject.bramble.api.identity.AuthorId;
import org.briarproject.bramble.api.identity.IdentityManager; import org.briarproject.bramble.api.identity.IdentityManager;
import org.briarproject.bramble.api.identity.LocalAuthor; import org.briarproject.bramble.api.identity.LocalAuthor;
import org.briarproject.bramble.api.nullsafety.NotNullByDefault; import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
import java.util.Collection;
import java.util.logging.Logger; import java.util.logging.Logger;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import javax.annotation.concurrent.ThreadSafe; import javax.annotation.concurrent.ThreadSafe;
import javax.inject.Inject; import javax.inject.Inject;
import static org.briarproject.bramble.api.identity.Author.Status.OURSELVES;
import static org.briarproject.bramble.api.identity.Author.Status.UNKNOWN;
import static org.briarproject.bramble.api.identity.Author.Status.UNVERIFIED;
import static org.briarproject.bramble.api.identity.Author.Status.VERIFIED;
import static org.briarproject.bramble.util.LogUtils.logDuration; import static org.briarproject.bramble.util.LogUtils.logDuration;
import static org.briarproject.bramble.util.LogUtils.now; import static org.briarproject.bramble.util.LogUtils.now;
@@ -118,26 +110,4 @@ class IdentityManagerImpl implements IdentityManager {
return db.getLocalAuthors(txn).iterator().next(); return db.getLocalAuthors(txn).iterator().next();
} }
@Override
public Status getAuthorStatus(AuthorId authorId) throws DbException {
Transaction txn = db.startTransaction(true);
try {
return getAuthorStatus(txn, authorId);
} finally {
db.endTransaction(txn);
}
}
@Override
public Status getAuthorStatus(Transaction txn, AuthorId authorId)
throws DbException {
if (getLocalAuthor(txn).getId().equals(authorId)) return OURSELVES;
Collection<Contact> contacts = db.getContactsByAuthorId(txn, authorId);
if (contacts.isEmpty()) return UNKNOWN;
for (Contact c : contacts) {
if (c.isVerified()) return VERIFIED;
}
return UNVERIFIED;
}
} }

View File

@@ -5,10 +5,14 @@ import org.briarproject.bramble.api.contact.ContactId;
import org.briarproject.bramble.api.contact.ContactManager; import org.briarproject.bramble.api.contact.ContactManager;
import org.briarproject.bramble.api.crypto.SecretKey; import org.briarproject.bramble.api.crypto.SecretKey;
import org.briarproject.bramble.api.db.DatabaseComponent; import org.briarproject.bramble.api.db.DatabaseComponent;
import org.briarproject.bramble.api.db.DbException;
import org.briarproject.bramble.api.db.NoSuchContactException; import org.briarproject.bramble.api.db.NoSuchContactException;
import org.briarproject.bramble.api.db.Transaction; import org.briarproject.bramble.api.db.Transaction;
import org.briarproject.bramble.api.identity.Author; import org.briarproject.bramble.api.identity.Author;
import org.briarproject.bramble.api.identity.AuthorId; import org.briarproject.bramble.api.identity.AuthorId;
import org.briarproject.bramble.api.identity.AuthorInfo;
import org.briarproject.bramble.api.identity.IdentityManager;
import org.briarproject.bramble.api.identity.LocalAuthor;
import org.briarproject.bramble.api.transport.KeyManager; import org.briarproject.bramble.api.transport.KeyManager;
import org.briarproject.bramble.test.BrambleMockTestCase; import org.briarproject.bramble.test.BrambleMockTestCase;
import org.briarproject.bramble.test.DbExpectations; import org.briarproject.bramble.test.DbExpectations;
@@ -21,12 +25,20 @@ import java.util.Collection;
import java.util.Collections; import java.util.Collections;
import java.util.Random; import java.util.Random;
import static java.util.Collections.emptyList;
import static java.util.Collections.singletonList;
import static org.briarproject.bramble.api.identity.AuthorConstants.MAX_AUTHOR_NAME_LENGTH; import static org.briarproject.bramble.api.identity.AuthorConstants.MAX_AUTHOR_NAME_LENGTH;
import static org.briarproject.bramble.api.identity.AuthorInfo.Status.OURSELVES;
import static org.briarproject.bramble.api.identity.AuthorInfo.Status.UNKNOWN;
import static org.briarproject.bramble.api.identity.AuthorInfo.Status.UNVERIFIED;
import static org.briarproject.bramble.api.identity.AuthorInfo.Status.VERIFIED;
import static org.briarproject.bramble.test.TestUtils.getAuthor; import static org.briarproject.bramble.test.TestUtils.getAuthor;
import static org.briarproject.bramble.test.TestUtils.getLocalAuthor;
import static org.briarproject.bramble.test.TestUtils.getRandomId; import static org.briarproject.bramble.test.TestUtils.getRandomId;
import static org.briarproject.bramble.test.TestUtils.getSecretKey; import static org.briarproject.bramble.test.TestUtils.getSecretKey;
import static org.briarproject.bramble.util.StringUtils.getRandomString; import static org.briarproject.bramble.util.StringUtils.getRandomString;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
public class ContactManagerImplTest extends BrambleMockTestCase { public class ContactManagerImplTest extends BrambleMockTestCase {
@@ -34,17 +46,20 @@ public class ContactManagerImplTest extends BrambleMockTestCase {
private final Mockery context = new Mockery(); private final Mockery context = new Mockery();
private final DatabaseComponent db = context.mock(DatabaseComponent.class); private final DatabaseComponent db = context.mock(DatabaseComponent.class);
private final KeyManager keyManager = context.mock(KeyManager.class); private final KeyManager keyManager = context.mock(KeyManager.class);
private final IdentityManager identityManager =
context.mock(IdentityManager.class);
private final ContactManager contactManager; private final ContactManager contactManager;
private final ContactId contactId = new ContactId(42); private final ContactId contactId = new ContactId(42);
private final Author remote = getAuthor(); private final Author remote = getAuthor();
private final AuthorId local = new AuthorId(getRandomId()); private final AuthorId local = new AuthorId(getRandomId());
private final LocalAuthor localAuthor = getLocalAuthor();
private final String alias = getRandomString(MAX_AUTHOR_NAME_LENGTH); private final String alias = getRandomString(MAX_AUTHOR_NAME_LENGTH);
private final boolean verified = false, active = true; private final boolean verified = false, active = true;
private final Contact contact = private final Contact contact =
new Contact(contactId, remote, local, alias, verified, active); new Contact(contactId, remote, local, alias, verified, active);
public ContactManagerImplTest() { public ContactManagerImplTest() {
contactManager = new ContactManagerImpl(db, keyManager); contactManager = new ContactManagerImpl(db, keyManager, identityManager);
} }
@Test @Test
@@ -109,7 +124,7 @@ public class ContactManagerImplTest extends BrambleMockTestCase {
oneOf(db).startTransaction(true); oneOf(db).startTransaction(true);
will(returnValue(txn)); will(returnValue(txn));
oneOf(db).getContactsByAuthorId(txn, remote.getId()); oneOf(db).getContactsByAuthorId(txn, remote.getId());
will(returnValue(Collections.emptyList())); will(returnValue(emptyList()));
oneOf(db).endTransaction(txn); oneOf(db).endTransaction(txn);
}}); }});
@@ -208,4 +223,79 @@ public class ContactManagerImplTest extends BrambleMockTestCase {
assertTrue(contactManager.contactExists(remote.getId(), local)); assertTrue(contactManager.contactExists(remote.getId(), local));
} }
@Test
public void testGetAuthorStatus() throws Exception {
Transaction txn = new Transaction(null, true);
Collection<Contact> contacts = singletonList(
new Contact(new ContactId(1), remote, localAuthor.getId(),
alias, false, true));
context.checking(new DbExpectations() {{
oneOf(db).transactionWithResult(with(equal(true)),
withDbCallable(txn));
oneOf(identityManager).getLocalAuthor(txn);
will(returnValue(localAuthor));
oneOf(db).getContactsByAuthorId(txn, remote.getId());
will(returnValue(contacts));
}});
AuthorInfo authorInfo =
contactManager.getAuthorInfo(txn, remote.getId());
assertEquals(UNVERIFIED, authorInfo.getStatus());
assertEquals(alias, contact.getAlias());
}
@Test
public void testGetAuthorStatusTransaction() throws DbException {
Transaction txn = new Transaction(null, true);
// check unknown author
context.checking(new Expectations() {{
oneOf(identityManager).getLocalAuthor(txn);
will(returnValue(localAuthor));
oneOf(db).getContactsByAuthorId(txn, remote.getId());
will(returnValue(emptyList()));
}});
AuthorInfo authorInfo =
contactManager.getAuthorInfo(txn, remote.getId());
assertEquals(UNKNOWN, authorInfo.getStatus());
assertNull(authorInfo.getAlias());
// check unverified contact
Collection<Contact> contacts = singletonList(
new Contact(new ContactId(1), remote, localAuthor.getId(),
alias, false, true));
checkAuthorStatusContext(txn, remote.getId(), contacts);
authorInfo = contactManager.getAuthorInfo(txn, remote.getId());
assertEquals(UNVERIFIED, authorInfo.getStatus());
assertEquals(alias, contact.getAlias());
// check verified contact
contacts = singletonList(new Contact(new ContactId(1), remote,
localAuthor.getId(), alias, true, true));
checkAuthorStatusContext(txn, remote.getId(), contacts);
authorInfo = contactManager.getAuthorInfo(txn, remote.getId());
assertEquals(VERIFIED, authorInfo.getStatus());
assertEquals(alias, contact.getAlias());
// check ourselves
context.checking(new Expectations() {{
oneOf(identityManager).getLocalAuthor(txn);
will(returnValue(localAuthor));
never(db).getContactsByAuthorId(txn, remote.getId());
}});
authorInfo = contactManager.getAuthorInfo(txn, localAuthor.getId());
assertEquals(OURSELVES, authorInfo.getStatus());
assertNull(authorInfo.getAlias());
}
private void checkAuthorStatusContext(Transaction txn, AuthorId authorId,
Collection<Contact> contacts) throws DbException {
context.checking(new Expectations() {{
oneOf(identityManager).getLocalAuthor(txn);
will(returnValue(localAuthor));
oneOf(db).getContactsByAuthorId(txn, authorId);
will(returnValue(contacts));
}});
}
} }

View File

@@ -1,7 +1,5 @@
package org.briarproject.bramble.identity; package org.briarproject.bramble.identity;
import org.briarproject.bramble.api.contact.Contact;
import org.briarproject.bramble.api.contact.ContactId;
import org.briarproject.bramble.api.crypto.CryptoComponent; import org.briarproject.bramble.api.crypto.CryptoComponent;
import org.briarproject.bramble.api.crypto.KeyPair; import org.briarproject.bramble.api.crypto.KeyPair;
import org.briarproject.bramble.api.crypto.PrivateKey; import org.briarproject.bramble.api.crypto.PrivateKey;
@@ -9,9 +7,7 @@ import org.briarproject.bramble.api.crypto.PublicKey;
import org.briarproject.bramble.api.db.DatabaseComponent; import org.briarproject.bramble.api.db.DatabaseComponent;
import org.briarproject.bramble.api.db.DbException; import org.briarproject.bramble.api.db.DbException;
import org.briarproject.bramble.api.db.Transaction; import org.briarproject.bramble.api.db.Transaction;
import org.briarproject.bramble.api.identity.Author;
import org.briarproject.bramble.api.identity.AuthorFactory; import org.briarproject.bramble.api.identity.AuthorFactory;
import org.briarproject.bramble.api.identity.AuthorId;
import org.briarproject.bramble.api.identity.IdentityManager; import org.briarproject.bramble.api.identity.IdentityManager;
import org.briarproject.bramble.api.identity.LocalAuthor; import org.briarproject.bramble.api.identity.LocalAuthor;
import org.briarproject.bramble.test.BrambleMockTestCase; import org.briarproject.bramble.test.BrambleMockTestCase;
@@ -19,17 +15,10 @@ import org.jmock.Expectations;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.Collections; import java.util.Collections;
import static org.briarproject.bramble.api.identity.Author.Status.OURSELVES;
import static org.briarproject.bramble.api.identity.Author.Status.UNKNOWN;
import static org.briarproject.bramble.api.identity.Author.Status.UNVERIFIED;
import static org.briarproject.bramble.api.identity.Author.Status.VERIFIED;
import static org.briarproject.bramble.test.TestUtils.getAuthor;
import static org.briarproject.bramble.test.TestUtils.getLocalAuthor; import static org.briarproject.bramble.test.TestUtils.getLocalAuthor;
import static org.briarproject.bramble.util.StringUtils.getRandomString;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
public class IdentityManagerImplTest extends BrambleMockTestCase { public class IdentityManagerImplTest extends BrambleMockTestCase {
@@ -108,60 +97,4 @@ public class IdentityManagerImplTest extends BrambleMockTestCase {
assertEquals(localAuthor, identityManager.getLocalAuthor()); assertEquals(localAuthor, identityManager.getLocalAuthor());
} }
@Test
public void testGetAuthorStatus() throws DbException {
Author author = getAuthor();
AuthorId authorId = author.getId();
Collection<Contact> contacts = new ArrayList<>();
context.checking(new Expectations() {{
oneOf(db).startTransaction(true);
will(returnValue(txn));
oneOf(db).getLocalAuthors(txn);
will(returnValue(localAuthors));
oneOf(db).getContactsByAuthorId(txn, authorId);
will(returnValue(contacts));
oneOf(db).endTransaction(txn);
}});
assertEquals(UNKNOWN, identityManager.getAuthorStatus(authorId));
// add one unverified contact
Contact contact = new Contact(new ContactId(1), author,
localAuthor.getId(), getRandomString(5), false, true);
contacts.add(contact);
checkAuthorStatusContext(authorId, contacts);
assertEquals(UNVERIFIED, identityManager.getAuthorStatus(authorId));
// add one verified contact
Contact contact2 = new Contact(new ContactId(1), author,
localAuthor.getId(), getRandomString(5), true, true);
contacts.add(contact2);
checkAuthorStatusContext(authorId, contacts);
assertEquals(VERIFIED, identityManager.getAuthorStatus(authorId));
context.checking(new Expectations() {{
oneOf(db).startTransaction(true);
will(returnValue(txn));
never(db).getLocalAuthors(txn);
never(db).getContactsByAuthorId(txn, authorId);
oneOf(db).endTransaction(txn);
}});
assertEquals(OURSELVES,
identityManager.getAuthorStatus(localAuthor.getId()));
}
private void checkAuthorStatusContext(AuthorId authorId,
Collection<Contact> contacts) throws DbException {
context.checking(new Expectations() {{
oneOf(db).startTransaction(true);
will(returnValue(txn));
never(db).getLocalAuthors(txn);
oneOf(db).getContactsByAuthorId(txn, authorId);
will(returnValue(contacts));
oneOf(db).endTransaction(txn);
}});
}
} }

View File

@@ -1,5 +1,6 @@
package org.briarproject.bramble.test; package org.briarproject.bramble.test;
import org.briarproject.bramble.api.db.DbCallable;
import org.briarproject.bramble.api.db.DbRunnable; import org.briarproject.bramble.api.db.DbRunnable;
import org.briarproject.bramble.api.db.Transaction; import org.briarproject.bramble.api.db.Transaction;
import org.jmock.Expectations; import org.jmock.Expectations;
@@ -13,4 +14,11 @@ public class DbExpectations extends Expectations {
return null; return null;
} }
protected <R, E extends Exception> DbCallable<R, E> withDbCallable(
Transaction txn) {
addParameterMatcher(any(DbCallable.class));
currentBuilder().setAction(new RunTransactionWithResultAction(txn));
return null;
}
} }

View File

@@ -0,0 +1,27 @@
package org.briarproject.bramble.test;
import org.briarproject.bramble.api.db.DbCallable;
import org.briarproject.bramble.api.db.Transaction;
import org.hamcrest.Description;
import org.jmock.api.Action;
import org.jmock.api.Invocation;
public class RunTransactionWithResultAction implements Action {
private final Transaction txn;
public RunTransactionWithResultAction(Transaction txn) {
this.txn = txn;
}
@Override
public Object invoke(Invocation invocation) throws Throwable {
DbCallable task = (DbCallable) invocation.getParameter(1);
return task.call(txn);
}
@Override
public void describeTo(Description description) {
description.appendText("runs a task inside a database transaction");
}
}

View File

@@ -3,7 +3,7 @@ package org.briarproject.briar.android.blog;
import android.support.annotation.NonNull; import android.support.annotation.NonNull;
import org.briarproject.bramble.api.identity.Author; import org.briarproject.bramble.api.identity.Author;
import org.briarproject.bramble.api.identity.Author.Status; import org.briarproject.bramble.api.identity.AuthorInfo;
import org.briarproject.bramble.api.sync.GroupId; import org.briarproject.bramble.api.sync.GroupId;
import org.briarproject.bramble.api.sync.MessageId; import org.briarproject.bramble.api.sync.MessageId;
import org.briarproject.briar.api.blog.BlogPostHeader; import org.briarproject.briar.api.blog.BlogPostHeader;
@@ -15,6 +15,7 @@ import javax.annotation.concurrent.NotThreadSafe;
public class BlogPostItem implements Comparable<BlogPostItem> { public class BlogPostItem implements Comparable<BlogPostItem> {
private final BlogPostHeader header; private final BlogPostHeader header;
@Nullable
protected String text; protected String text;
private boolean read; private boolean read;
@@ -40,10 +41,11 @@ public class BlogPostItem implements Comparable<BlogPostItem> {
return header.getAuthor(); return header.getAuthor();
} }
Status getAuthorStatus() { AuthorInfo getAuthorInfo() {
return header.getAuthorStatus(); return header.getAuthorInfo();
} }
@Nullable
public String getText() { public String getText() {
return text; return text;
} }

View File

@@ -100,7 +100,7 @@ class BlogPostViewHolder extends RecyclerView.ViewHolder {
BlogPostHeader post = item.getPostHeader(); BlogPostHeader post = item.getPostHeader();
Author a = post.getAuthor(); Author a = post.getAuthor();
author.setAuthor(a); author.setAuthor(a);
author.setAuthorStatus(post.getAuthorStatus()); author.setAuthorInfo(post.getAuthorInfo());
author.setDate(post.getTimestamp()); author.setDate(post.getTimestamp());
author.setPersona( author.setPersona(
item.isRssFeed() ? AuthorView.RSS_FEED : AuthorView.NORMAL); item.isRssFeed() ? AuthorView.RSS_FEED : AuthorView.NORMAL);
@@ -144,7 +144,7 @@ class BlogPostViewHolder extends RecyclerView.ViewHolder {
private void onBindComment(BlogCommentItem item) { private void onBindComment(BlogCommentItem item) {
// reblogger // reblogger
reblogger.setAuthor(item.getAuthor()); reblogger.setAuthor(item.getAuthor());
reblogger.setAuthorStatus(item.getAuthorStatus()); reblogger.setAuthorInfo(item.getAuthorInfo());
reblogger.setDate(item.getTimestamp()); reblogger.setDate(item.getTimestamp());
if (!fullText) { if (!fullText) {
reblogger.setAuthorClickable(v -> listener.onAuthorClick(item)); reblogger.setAuthorClickable(v -> listener.onAuthorClick(item));
@@ -166,7 +166,7 @@ class BlogPostViewHolder extends RecyclerView.ViewHolder {
TextView text = v.findViewById(R.id.textView); TextView text = v.findViewById(R.id.textView);
author.setAuthor(c.getAuthor()); author.setAuthor(c.getAuthor());
author.setAuthorStatus(c.getAuthorStatus()); author.setAuthorInfo(c.getAuthorInfo());
author.setDate(c.getTimestamp()); author.setDate(c.getTimestamp());
// TODO make author clickable #624 // TODO make author clickable #624

View File

@@ -1,7 +1,7 @@
package org.briarproject.briar.android.forum; package org.briarproject.briar.android.forum;
import org.briarproject.bramble.api.identity.Author; import org.briarproject.bramble.api.identity.Author;
import org.briarproject.bramble.api.identity.Author.Status; import org.briarproject.bramble.api.identity.AuthorInfo;
import org.briarproject.bramble.api.sync.MessageId; import org.briarproject.bramble.api.sync.MessageId;
import org.briarproject.briar.android.threaded.ThreadItem; import org.briarproject.briar.android.threaded.ThreadItem;
import org.briarproject.briar.api.forum.ForumPostHeader; import org.briarproject.briar.api.forum.ForumPostHeader;
@@ -14,12 +14,12 @@ class ForumItem extends ThreadItem {
ForumItem(ForumPostHeader h, String text) { ForumItem(ForumPostHeader h, String text) {
super(h.getId(), h.getParentId(), text, h.getTimestamp(), h.getAuthor(), super(h.getId(), h.getParentId(), text, h.getTimestamp(), h.getAuthor(),
h.getAuthorStatus(), h.isRead()); h.getAuthorInfo(), h.isRead());
} }
ForumItem(MessageId messageId, @Nullable MessageId parentId, String text, ForumItem(MessageId messageId, @Nullable MessageId parentId, String text,
long timestamp, Author author, Status status) { long timestamp, Author author, AuthorInfo authorInfo) {
super(messageId, parentId, text, timestamp, author, status, true); super(messageId, parentId, text, timestamp, author, authorInfo, true);
} }
} }

View File

@@ -4,7 +4,7 @@ import android.support.annotation.LayoutRes;
import android.support.annotation.UiThread; import android.support.annotation.UiThread;
import org.briarproject.bramble.api.identity.Author; import org.briarproject.bramble.api.identity.Author;
import org.briarproject.bramble.api.identity.Author.Status; import org.briarproject.bramble.api.identity.AuthorInfo;
import org.briarproject.bramble.api.sync.GroupId; import org.briarproject.bramble.api.sync.GroupId;
import org.briarproject.bramble.api.sync.MessageId; import org.briarproject.bramble.api.sync.MessageId;
import org.briarproject.briar.R; import org.briarproject.briar.R;
@@ -22,14 +22,14 @@ class GroupMessageItem extends ThreadItem {
private GroupMessageItem(MessageId messageId, GroupId groupId, private GroupMessageItem(MessageId messageId, GroupId groupId,
@Nullable MessageId parentId, String text, long timestamp, @Nullable MessageId parentId, String text, long timestamp,
Author author, Status status, boolean isRead) { Author author, AuthorInfo authorInfo, boolean isRead) {
super(messageId, parentId, text, timestamp, author, status, isRead); super(messageId, parentId, text, timestamp, author, authorInfo, isRead);
this.groupId = groupId; this.groupId = groupId;
} }
GroupMessageItem(GroupMessageHeader h, String text) { GroupMessageItem(GroupMessageHeader h, String text) {
this(h.getId(), h.getGroupId(), h.getParentId(), text, h.getTimestamp(), this(h.getId(), h.getGroupId(), h.getParentId(), text, h.getTimestamp(),
h.getAuthor(), h.getAuthorStatus(), h.isRead()); h.getAuthor(), h.getAuthorInfo(), h.isRead());
} }
public GroupId getGroupId() { public GroupId getGroupId() {

View File

@@ -9,7 +9,7 @@ import org.briarproject.briar.R;
import org.briarproject.briar.android.threaded.BaseThreadItemViewHolder; import org.briarproject.briar.android.threaded.BaseThreadItemViewHolder;
import org.briarproject.briar.android.threaded.ThreadItemAdapter.ThreadItemListener; import org.briarproject.briar.android.threaded.ThreadItemAdapter.ThreadItemListener;
import static org.briarproject.bramble.api.identity.Author.Status.OURSELVES; import static org.briarproject.bramble.api.identity.AuthorInfo.Status.OURSELVES;
@UiThread @UiThread
@NotNullByDefault @NotNullByDefault
@@ -49,7 +49,7 @@ class JoinMessageItemViewHolder
textView.setText(ctx.getString(R.string.groups_member_created, textView.setText(ctx.getString(R.string.groups_member_created,
item.getAuthor().getName())); item.getAuthor().getName()));
} else { } else {
if (item.getStatus() == OURSELVES) { if (item.getAuthorInfo().getStatus() == OURSELVES) {
textView.setText(R.string.groups_member_joined_you); textView.setText(R.string.groups_member_joined_you);
} else { } else {
textView.setText(ctx.getString(R.string.groups_member_joined, textView.setText(ctx.getString(R.string.groups_member_joined,

View File

@@ -2,7 +2,8 @@ package org.briarproject.briar.android.privategroup.memberlist;
import org.briarproject.bramble.api.contact.ContactId; import org.briarproject.bramble.api.contact.ContactId;
import org.briarproject.bramble.api.identity.Author; import org.briarproject.bramble.api.identity.Author;
import org.briarproject.bramble.api.identity.Author.Status; import org.briarproject.bramble.api.identity.AuthorInfo;
import org.briarproject.bramble.api.identity.AuthorInfo.Status;
import org.briarproject.bramble.api.nullsafety.NotNullByDefault; import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
import org.briarproject.briar.api.privategroup.GroupMember; import org.briarproject.briar.api.privategroup.GroupMember;
@@ -25,8 +26,12 @@ class MemberListItem {
return groupMember.getAuthor(); return groupMember.getAuthor();
} }
AuthorInfo getAuthorInfo() {
return groupMember.getAuthorInfo();
}
Status getStatus() { Status getStatus() {
return groupMember.getStatus(); return groupMember.getAuthorInfo().getStatus();
} }
boolean isCreator() { boolean isCreator() {

View File

@@ -10,7 +10,9 @@ import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
import org.briarproject.briar.R; import org.briarproject.briar.R;
import org.briarproject.briar.android.view.AuthorView; import org.briarproject.briar.android.view.AuthorView;
import static org.briarproject.bramble.api.identity.Author.Status.OURSELVES; import static android.view.View.GONE;
import static android.view.View.VISIBLE;
import static org.briarproject.bramble.api.identity.AuthorInfo.Status.OURSELVES;
@UiThread @UiThread
@NotNullByDefault @NotNullByDefault
@@ -28,25 +30,25 @@ class MemberListItemHolder extends RecyclerView.ViewHolder {
} }
protected void bind(MemberListItem item) { protected void bind(MemberListItem item) {
// member name, avatar and status // member name, avatar and author info
author.setAuthor(item.getMember()); author.setAuthor(item.getMember());
author.setAuthorStatus(item.getStatus()); author.setAuthorInfo(item.getAuthorInfo());
// online status of visible contacts // online status of visible contacts
if (item.getContactId() != null) { if (item.getContactId() != null) {
bulb.setVisibility(View.VISIBLE); bulb.setVisibility(VISIBLE);
if (item.isOnline()) { if (item.isOnline()) {
bulb.setImageResource(R.drawable.contact_connected); bulb.setImageResource(R.drawable.contact_connected);
} else { } else {
bulb.setImageResource(R.drawable.contact_disconnected); bulb.setImageResource(R.drawable.contact_disconnected);
} }
} else { } else {
bulb.setVisibility(View.GONE); bulb.setVisibility(GONE);
} }
// text shown for creator // text shown for creator
if (item.isCreator()) { if (item.isCreator()) {
creator.setVisibility(View.VISIBLE); creator.setVisibility(VISIBLE);
if (item.getStatus() == OURSELVES) { if (item.getStatus() == OURSELVES) {
creator.setText(R.string.groups_member_created_you); creator.setText(R.string.groups_member_created_you);
} else { } else {
@@ -55,7 +57,7 @@ class MemberListItemHolder extends RecyclerView.ViewHolder {
item.getMember().getName())); item.getMember().getName()));
} }
} else { } else {
creator.setVisibility(View.GONE); creator.setVisibility(GONE);
} }
} }

View File

@@ -45,7 +45,7 @@ public abstract class BaseThreadItemViewHolder<I extends ThreadItem>
author.setAuthor(item.getAuthor()); author.setAuthor(item.getAuthor());
author.setDate(item.getTimestamp()); author.setDate(item.getTimestamp());
author.setAuthorStatus(item.getStatus()); author.setAuthorInfo(item.getAuthorInfo());
if (item.isHighlighted()) { if (item.isHighlighted()) {
layout.setActivated(true); layout.setActivated(true);

View File

@@ -1,7 +1,7 @@
package org.briarproject.briar.android.threaded; package org.briarproject.briar.android.threaded;
import org.briarproject.bramble.api.identity.Author; import org.briarproject.bramble.api.identity.Author;
import org.briarproject.bramble.api.identity.Author.Status; import org.briarproject.bramble.api.identity.AuthorInfo;
import org.briarproject.bramble.api.nullsafety.NotNullByDefault; import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
import org.briarproject.bramble.api.sync.MessageId; import org.briarproject.bramble.api.sync.MessageId;
import org.briarproject.briar.api.client.MessageTree.MessageNode; import org.briarproject.briar.api.client.MessageTree.MessageNode;
@@ -21,19 +21,19 @@ public abstract class ThreadItem implements MessageNode {
private final String text; private final String text;
private final long timestamp; private final long timestamp;
private final Author author; private final Author author;
private final Status status; private final AuthorInfo authorInfo;
private int level = UNDEFINED; private int level = UNDEFINED;
private boolean isRead, highlighted; private boolean isRead, highlighted;
public ThreadItem(MessageId messageId, @Nullable MessageId parentId, public ThreadItem(MessageId messageId, @Nullable MessageId parentId,
String text, long timestamp, Author author, Status status, String text, long timestamp, Author author, AuthorInfo authorInfo,
boolean isRead) { boolean isRead) {
this.messageId = messageId; this.messageId = messageId;
this.parentId = parentId; this.parentId = parentId;
this.text = text; this.text = text;
this.timestamp = timestamp; this.timestamp = timestamp;
this.author = author; this.author = author;
this.status = status; this.authorInfo = authorInfo;
this.isRead = isRead; this.isRead = isRead;
this.highlighted = false; this.highlighted = false;
} }
@@ -66,8 +66,8 @@ public abstract class ThreadItem implements MessageNode {
return author; return author;
} }
public Status getStatus() { public AuthorInfo getAuthorInfo() {
return status; return authorInfo;
} }
@Override @Override

View File

@@ -12,7 +12,7 @@ import android.widget.ImageView;
import android.widget.TextView; import android.widget.TextView;
import org.briarproject.bramble.api.identity.Author; import org.briarproject.bramble.api.identity.Author;
import org.briarproject.bramble.api.identity.Author.Status; import org.briarproject.bramble.api.identity.AuthorInfo;
import org.briarproject.briar.R; import org.briarproject.briar.R;
import org.briarproject.briar.android.util.UiUtils; import org.briarproject.briar.android.util.UiUtils;
@@ -24,8 +24,8 @@ import im.delight.android.identicons.IdenticonDrawable;
import static android.content.Context.LAYOUT_INFLATER_SERVICE; import static android.content.Context.LAYOUT_INFLATER_SERVICE;
import static android.graphics.Typeface.BOLD; import static android.graphics.Typeface.BOLD;
import static android.util.TypedValue.COMPLEX_UNIT_PX; import static android.util.TypedValue.COMPLEX_UNIT_PX;
import static org.briarproject.bramble.api.identity.Author.Status.NONE; import static org.briarproject.bramble.api.identity.AuthorInfo.Status.NONE;
import static org.briarproject.bramble.api.identity.Author.Status.OURSELVES; import static org.briarproject.bramble.api.identity.AuthorInfo.Status.OURSELVES;
import static org.briarproject.briar.android.util.UiUtils.resolveAttribute; import static org.briarproject.briar.android.util.UiUtils.resolveAttribute;
@UiThread @UiThread
@@ -79,15 +79,15 @@ public class AuthorView extends ConstraintLayout {
requestLayout(); requestLayout();
} }
public void setAuthorStatus(Status status) { public void setAuthorInfo(AuthorInfo authorInfo) {
if (status != NONE) { if (authorInfo.getStatus() != NONE) {
trustIndicator.setTrustLevel(status); trustIndicator.setTrustLevel(authorInfo.getStatus());
trustIndicator.setVisibility(VISIBLE); trustIndicator.setVisibility(VISIBLE);
} else { } else {
trustIndicator.setVisibility(GONE); trustIndicator.setVisibility(GONE);
} }
if (status == OURSELVES) { if (authorInfo.getStatus() == OURSELVES) {
authorName.setTypeface(authorNameTypeface, BOLD); authorName.setTypeface(authorNameTypeface, BOLD);
} else { } else {
authorName.setTypeface(authorNameTypeface, NORMAL); authorName.setTypeface(authorNameTypeface, NORMAL);

View File

@@ -3,14 +3,14 @@ package org.briarproject.briar.android.view;
import android.content.Context; import android.content.Context;
import android.support.annotation.UiThread; import android.support.annotation.UiThread;
import android.support.v4.content.ContextCompat; import android.support.v4.content.ContextCompat;
import android.support.v7.widget.AppCompatImageView;
import android.util.AttributeSet; import android.util.AttributeSet;
import android.widget.ImageView;
import org.briarproject.bramble.api.identity.Author.Status; import org.briarproject.bramble.api.identity.AuthorInfo.Status;
import org.briarproject.briar.R; import org.briarproject.briar.R;
@UiThread @UiThread
public class TrustIndicatorView extends ImageView { public class TrustIndicatorView extends AppCompatImageView {
public TrustIndicatorView(Context context) { public TrustIndicatorView(Context context) {
super(context); super(context);

View File

@@ -6,6 +6,7 @@ import junit.framework.Assert;
import org.briarproject.bramble.api.db.DbException; import org.briarproject.bramble.api.db.DbException;
import org.briarproject.bramble.api.identity.Author; import org.briarproject.bramble.api.identity.Author;
import org.briarproject.bramble.api.identity.AuthorInfo;
import org.briarproject.bramble.api.sync.MessageId; import org.briarproject.bramble.api.sync.MessageId;
import org.briarproject.briar.android.TestBriarApplication; import org.briarproject.briar.android.TestBriarApplication;
import org.briarproject.briar.android.controller.handler.UiResultExceptionHandler; import org.briarproject.briar.android.controller.handler.UiResultExceptionHandler;
@@ -26,7 +27,7 @@ import java.util.Arrays;
import static junit.framework.Assert.assertEquals; import static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.assertTrue; import static junit.framework.Assert.assertTrue;
import static org.briarproject.bramble.api.identity.Author.Status.UNKNOWN; import static org.briarproject.bramble.api.identity.AuthorInfo.Status.UNKNOWN;
import static org.briarproject.bramble.test.TestUtils.getAuthor; import static org.briarproject.bramble.test.TestUtils.getAuthor;
import static org.briarproject.bramble.test.TestUtils.getRandomId; import static org.briarproject.bramble.test.TestUtils.getRandomId;
import static org.briarproject.bramble.util.StringUtils.getRandomString; import static org.briarproject.bramble.util.StringUtils.getRandomString;
@@ -87,7 +88,8 @@ public class ForumActivityTest {
Author author = getAuthor(); Author author = getAuthor();
String text = getRandomString(MAX_FORUM_POST_TEXT_LENGTH); String text = getRandomString(MAX_FORUM_POST_TEXT_LENGTH);
forumItems[i] = new ForumItem(MESSAGE_IDS[i], PARENT_IDS[i], forumItems[i] = new ForumItem(MESSAGE_IDS[i], PARENT_IDS[i],
text, System.currentTimeMillis(), author, UNKNOWN); text, System.currentTimeMillis(), author,
new AuthorInfo(UNKNOWN));
forumItems[i].setLevel(LEVELS[i]); forumItems[i].setLevel(LEVELS[i]);
} }
ThreadItemList<ForumItem> list = new ThreadItemListImpl<>(); ThreadItemList<ForumItem> list = new ThreadItemListImpl<>();

View File

@@ -1,7 +1,7 @@
package org.briarproject.briar.api.blog; package org.briarproject.briar.api.blog;
import org.briarproject.bramble.api.identity.Author; import org.briarproject.bramble.api.identity.Author;
import org.briarproject.bramble.api.identity.Author.Status; import org.briarproject.bramble.api.identity.AuthorInfo;
import org.briarproject.bramble.api.nullsafety.NotNullByDefault; import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
import org.briarproject.bramble.api.sync.GroupId; import org.briarproject.bramble.api.sync.GroupId;
import org.briarproject.bramble.api.sync.MessageId; import org.briarproject.bramble.api.sync.MessageId;
@@ -23,10 +23,10 @@ public class BlogCommentHeader extends BlogPostHeader {
public BlogCommentHeader(MessageType type, GroupId groupId, public BlogCommentHeader(MessageType type, GroupId groupId,
@Nullable String comment, BlogPostHeader parent, MessageId id, @Nullable String comment, BlogPostHeader parent, MessageId id,
long timestamp, long timeReceived, Author author, long timestamp, long timeReceived, Author author,
Status authorStatus, boolean read) { AuthorInfo authorInfo, boolean read) {
super(type, groupId, id, parent.getId(), timestamp, super(type, groupId, id, parent.getId(), timestamp,
timeReceived, author, authorStatus, false, read); timeReceived, author, authorInfo, false, read);
if (type != COMMENT && type != WRAPPED_COMMENT) if (type != COMMENT && type != WRAPPED_COMMENT)
throw new IllegalArgumentException("Incompatible Message Type"); throw new IllegalArgumentException("Incompatible Message Type");

View File

@@ -1,7 +1,7 @@
package org.briarproject.briar.api.blog; package org.briarproject.briar.api.blog;
import org.briarproject.bramble.api.identity.Author; import org.briarproject.bramble.api.identity.Author;
import org.briarproject.bramble.api.identity.Author.Status; import org.briarproject.bramble.api.identity.AuthorInfo;
import org.briarproject.bramble.api.nullsafety.NotNullByDefault; import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
import org.briarproject.bramble.api.sync.GroupId; import org.briarproject.bramble.api.sync.GroupId;
import org.briarproject.bramble.api.sync.MessageId; import org.briarproject.bramble.api.sync.MessageId;
@@ -21,8 +21,8 @@ public class BlogPostHeader extends PostHeader {
public BlogPostHeader(MessageType type, GroupId groupId, MessageId id, public BlogPostHeader(MessageType type, GroupId groupId, MessageId id,
@Nullable MessageId parentId, long timestamp, long timeReceived, @Nullable MessageId parentId, long timestamp, long timeReceived,
Author author, Status authorStatus, boolean rssFeed, boolean read) { Author author, AuthorInfo authorInfo, boolean rssFeed, boolean read) {
super(id, parentId, timestamp, author, authorStatus, read); super(id, parentId, timestamp, author, authorInfo, read);
this.type = type; this.type = type;
this.groupId = groupId; this.groupId = groupId;
this.timeReceived = timeReceived; this.timeReceived = timeReceived;
@@ -31,9 +31,9 @@ public class BlogPostHeader extends PostHeader {
public BlogPostHeader(MessageType type, GroupId groupId, MessageId id, public BlogPostHeader(MessageType type, GroupId groupId, MessageId id,
long timestamp, long timeReceived, Author author, long timestamp, long timeReceived, Author author,
Status authorStatus, boolean rssFeed, boolean read) { AuthorInfo authorInfo, boolean rssFeed, boolean read) {
this(type, groupId, id, null, timestamp, timeReceived, author, this(type, groupId, id, null, timestamp, timeReceived, author,
authorStatus, rssFeed, read); authorInfo, rssFeed, read);
} }
public MessageType getType() { public MessageType getType() {

View File

@@ -1,7 +1,8 @@
package org.briarproject.briar.api.client; package org.briarproject.briar.api.client;
import org.briarproject.bramble.api.identity.Author; import org.briarproject.bramble.api.identity.Author;
import org.briarproject.bramble.api.identity.Author.Status; import org.briarproject.bramble.api.identity.AuthorInfo;
import org.briarproject.bramble.api.identity.AuthorInfo.Status;
import org.briarproject.bramble.api.nullsafety.NotNullByDefault; import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
import org.briarproject.bramble.api.sync.MessageId; import org.briarproject.bramble.api.sync.MessageId;
@@ -17,16 +18,16 @@ public abstract class PostHeader {
private final MessageId parentId; private final MessageId parentId;
private final long timestamp; private final long timestamp;
private final Author author; private final Author author;
private final Status authorStatus; private final AuthorInfo authorInfo;
private final boolean read; private final boolean read;
public PostHeader(MessageId id, @Nullable MessageId parentId, public PostHeader(MessageId id, @Nullable MessageId parentId,
long timestamp, Author author, Status authorStatus, boolean read) { long timestamp, Author author, AuthorInfo authorInfo, boolean read) {
this.id = id; this.id = id;
this.parentId = parentId; this.parentId = parentId;
this.timestamp = timestamp; this.timestamp = timestamp;
this.author = author; this.author = author;
this.authorStatus = authorStatus; this.authorInfo = authorInfo;
this.read = read; this.read = read;
} }
@@ -39,7 +40,11 @@ public abstract class PostHeader {
} }
public Status getAuthorStatus() { public Status getAuthorStatus() {
return authorStatus; return authorInfo.getStatus();
}
public AuthorInfo getAuthorInfo() {
return authorInfo;
} }
public long getTimestamp() { public long getTimestamp() {

View File

@@ -1,6 +1,7 @@
package org.briarproject.briar.api.forum; package org.briarproject.briar.api.forum;
import org.briarproject.bramble.api.identity.Author; import org.briarproject.bramble.api.identity.Author;
import org.briarproject.bramble.api.identity.AuthorInfo;
import org.briarproject.bramble.api.nullsafety.NotNullByDefault; import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
import org.briarproject.bramble.api.sync.MessageId; import org.briarproject.bramble.api.sync.MessageId;
import org.briarproject.briar.api.client.PostHeader; import org.briarproject.briar.api.client.PostHeader;
@@ -13,9 +14,9 @@ import javax.annotation.concurrent.Immutable;
public class ForumPostHeader extends PostHeader { public class ForumPostHeader extends PostHeader {
public ForumPostHeader(MessageId id, @Nullable MessageId parentId, public ForumPostHeader(MessageId id, @Nullable MessageId parentId,
long timestamp, Author author, Author.Status authorStatus, long timestamp, Author author, AuthorInfo authorInfo,
boolean read) { boolean read) {
super(id, parentId, timestamp, author, authorStatus, read); super(id, parentId, timestamp, author, authorInfo, read);
} }
} }

View File

@@ -2,7 +2,7 @@ package org.briarproject.briar.api.privategroup;
import org.briarproject.bramble.api.contact.ContactId; import org.briarproject.bramble.api.contact.ContactId;
import org.briarproject.bramble.api.identity.Author; import org.briarproject.bramble.api.identity.Author;
import org.briarproject.bramble.api.identity.Author.Status; import org.briarproject.bramble.api.identity.AuthorInfo;
import org.briarproject.bramble.api.nullsafety.NotNullByDefault; import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
import javax.annotation.Nullable; import javax.annotation.Nullable;
@@ -13,16 +13,16 @@ import javax.annotation.concurrent.Immutable;
public class GroupMember { public class GroupMember {
private final Author author; private final Author author;
private final Status status; private final AuthorInfo authorInfo;
private final boolean isCreator; private final boolean isCreator;
@Nullable @Nullable
private final ContactId contactId; private final ContactId contactId;
private final Visibility visibility; private final Visibility visibility;
public GroupMember(Author author, Status status, boolean isCreator, public GroupMember(Author author, AuthorInfo authorInfo, boolean isCreator,
@Nullable ContactId contactId, Visibility visibility) { @Nullable ContactId contactId, Visibility visibility) {
this.author = author; this.author = author;
this.status = status; this.authorInfo = authorInfo;
this.isCreator = isCreator; this.isCreator = isCreator;
this.contactId = contactId; this.contactId = contactId;
this.visibility = visibility; this.visibility = visibility;
@@ -32,8 +32,8 @@ public class GroupMember {
return author; return author;
} }
public Status getStatus() { public AuthorInfo getAuthorInfo() {
return status; return authorInfo;
} }
public boolean isCreator() { public boolean isCreator() {

View File

@@ -1,7 +1,7 @@
package org.briarproject.briar.api.privategroup; package org.briarproject.briar.api.privategroup;
import org.briarproject.bramble.api.identity.Author; import org.briarproject.bramble.api.identity.Author;
import org.briarproject.bramble.api.identity.Author.Status; import org.briarproject.bramble.api.identity.AuthorInfo;
import org.briarproject.bramble.api.nullsafety.NotNullByDefault; import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
import org.briarproject.bramble.api.sync.GroupId; import org.briarproject.bramble.api.sync.GroupId;
import org.briarproject.bramble.api.sync.MessageId; import org.briarproject.bramble.api.sync.MessageId;
@@ -18,8 +18,8 @@ public class GroupMessageHeader extends PostHeader {
public GroupMessageHeader(GroupId groupId, MessageId id, public GroupMessageHeader(GroupId groupId, MessageId id,
@Nullable MessageId parentId, long timestamp, @Nullable MessageId parentId, long timestamp,
Author author, Status authorStatus, boolean read) { Author author, AuthorInfo authorInfo, boolean read) {
super(id, parentId, timestamp, author, authorStatus, read); super(id, parentId, timestamp, author, authorInfo, read);
this.groupId = groupId; this.groupId = groupId;
} }

View File

@@ -14,7 +14,7 @@ public class JoinMessageHeader extends GroupMessageHeader {
public JoinMessageHeader(GroupMessageHeader h, Visibility visibility, public JoinMessageHeader(GroupMessageHeader h, Visibility visibility,
boolean isInitial) { boolean isInitial) {
super(h.getGroupId(), h.getId(), h.getParentId(), h.getTimestamp(), super(h.getGroupId(), h.getId(), h.getParentId(), h.getTimestamp(),
h.getAuthor(), h.getAuthorStatus(), h.isRead()); h.getAuthor(), h.getAuthorInfo(), h.isRead());
this.visibility = visibility; this.visibility = visibility;
this.isInitial = isInitial; this.isInitial = isInitial;
} }

View File

@@ -3,6 +3,7 @@ package org.briarproject.briar.blog;
import org.briarproject.bramble.api.FormatException; import org.briarproject.bramble.api.FormatException;
import org.briarproject.bramble.api.client.ClientHelper; import org.briarproject.bramble.api.client.ClientHelper;
import org.briarproject.bramble.api.contact.Contact; import org.briarproject.bramble.api.contact.Contact;
import org.briarproject.bramble.api.contact.ContactManager;
import org.briarproject.bramble.api.contact.ContactManager.ContactHook; import org.briarproject.bramble.api.contact.ContactManager.ContactHook;
import org.briarproject.bramble.api.data.BdfDictionary; import org.briarproject.bramble.api.data.BdfDictionary;
import org.briarproject.bramble.api.data.BdfEntry; import org.briarproject.bramble.api.data.BdfEntry;
@@ -12,8 +13,8 @@ import org.briarproject.bramble.api.db.DatabaseComponent;
import org.briarproject.bramble.api.db.DbException; import org.briarproject.bramble.api.db.DbException;
import org.briarproject.bramble.api.db.Transaction; import org.briarproject.bramble.api.db.Transaction;
import org.briarproject.bramble.api.identity.Author; import org.briarproject.bramble.api.identity.Author;
import org.briarproject.bramble.api.identity.Author.Status;
import org.briarproject.bramble.api.identity.AuthorId; import org.briarproject.bramble.api.identity.AuthorId;
import org.briarproject.bramble.api.identity.AuthorInfo;
import org.briarproject.bramble.api.identity.IdentityManager; import org.briarproject.bramble.api.identity.IdentityManager;
import org.briarproject.bramble.api.identity.LocalAuthor; import org.briarproject.bramble.api.identity.LocalAuthor;
import org.briarproject.bramble.api.nullsafety.NotNullByDefault; import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
@@ -49,6 +50,7 @@ import java.util.concurrent.CopyOnWriteArrayList;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import javax.inject.Inject; import javax.inject.Inject;
import static org.briarproject.bramble.api.identity.AuthorInfo.Status.NONE;
import static org.briarproject.briar.api.blog.BlogConstants.KEY_AUTHOR; import static org.briarproject.briar.api.blog.BlogConstants.KEY_AUTHOR;
import static org.briarproject.briar.api.blog.BlogConstants.KEY_COMMENT; import static org.briarproject.briar.api.blog.BlogConstants.KEY_COMMENT;
import static org.briarproject.briar.api.blog.BlogConstants.KEY_ORIGINAL_MSG_ID; import static org.briarproject.briar.api.blog.BlogConstants.KEY_ORIGINAL_MSG_ID;
@@ -68,17 +70,19 @@ import static org.briarproject.briar.api.blog.MessageType.WRAPPED_POST;
class BlogManagerImpl extends BdfIncomingMessageHook implements BlogManager, class BlogManagerImpl extends BdfIncomingMessageHook implements BlogManager,
ContactHook, Client { ContactHook, Client {
private final ContactManager contactManager;
private final IdentityManager identityManager; private final IdentityManager identityManager;
private final BlogFactory blogFactory; private final BlogFactory blogFactory;
private final BlogPostFactory blogPostFactory; private final BlogPostFactory blogPostFactory;
private final List<RemoveBlogHook> removeHooks; private final List<RemoveBlogHook> removeHooks;
@Inject @Inject
BlogManagerImpl(DatabaseComponent db, IdentityManager identityManager, BlogManagerImpl(DatabaseComponent db, ContactManager contactManager,
ClientHelper clientHelper, MetadataParser metadataParser, IdentityManager identityManager, ClientHelper clientHelper,
BlogFactory blogFactory, BlogPostFactory blogPostFactory) { MetadataParser metadataParser, BlogFactory blogFactory,
BlogPostFactory blogPostFactory) {
super(db, clientHelper, metadataParser); super(db, clientHelper, metadataParser);
this.contactManager = contactManager;
this.identityManager = identityManager; this.identityManager = identityManager;
this.blogFactory = blogFactory; this.blogFactory = blogFactory;
this.blogPostFactory = blogPostFactory; this.blogPostFactory = blogPostFactory;
@@ -501,25 +505,24 @@ class BlogManagerImpl extends BdfIncomingMessageHook implements BlogManager,
new HashMap<>(metadata1.size() + metadata2.size()); new HashMap<>(metadata1.size() + metadata2.size());
metadata.putAll(metadata1); metadata.putAll(metadata1);
metadata.putAll(metadata2); metadata.putAll(metadata2);
// get all authors we need to get the status for // get all authors we need to get the information for
Set<AuthorId> authors = new HashSet<>(); Set<AuthorId> authors = new HashSet<>();
for (Entry<MessageId, BdfDictionary> entry : metadata.entrySet()) { for (Entry<MessageId, BdfDictionary> entry : metadata.entrySet()) {
BdfList authorList = entry.getValue().getList(KEY_AUTHOR); BdfList authorList = entry.getValue().getList(KEY_AUTHOR);
Author a = clientHelper.parseAndValidateAuthor(authorList); Author a = clientHelper.parseAndValidateAuthor(authorList);
authors.add(a.getId()); authors.add(a.getId());
} }
// get statuses for all authors // get information for all authors
Map<AuthorId, Status> authorStatuses = new HashMap<>(); Map<AuthorId, AuthorInfo> authorInfos = new HashMap<>();
for (AuthorId authorId : authors) { for (AuthorId authorId : authors) {
authorStatuses.put(authorId, authorInfos.put(authorId,
identityManager.getAuthorStatus(txn, authorId)); contactManager.getAuthorInfo(txn, authorId));
} }
// get post headers // get post headers
for (Entry<MessageId, BdfDictionary> entry : metadata.entrySet()) { for (Entry<MessageId, BdfDictionary> entry : metadata.entrySet()) {
BdfDictionary meta = entry.getValue(); BdfDictionary meta = entry.getValue();
BlogPostHeader h = BlogPostHeader h = getPostHeaderFromMetadata(txn, g,
getPostHeaderFromMetadata(txn, g, entry.getKey(), meta, entry.getKey(), meta, authorInfos);
authorStatuses);
headers.add(h); headers.add(h);
} }
db.commitTransaction(txn); db.commitTransaction(txn);
@@ -563,7 +566,7 @@ class BlogManagerImpl extends BdfIncomingMessageHook implements BlogManager,
private BlogPostHeader getPostHeaderFromMetadata(Transaction txn, private BlogPostHeader getPostHeaderFromMetadata(Transaction txn,
GroupId groupId, MessageId id, BdfDictionary meta, GroupId groupId, MessageId id, BdfDictionary meta,
Map<AuthorId, Status> authorStatuses) Map<AuthorId, AuthorInfo> authorInfos)
throws DbException, FormatException { throws DbException, FormatException {
MessageType type = getMessageType(meta); MessageType type = getMessageType(meta);
@@ -574,13 +577,13 @@ class BlogManagerImpl extends BdfIncomingMessageHook implements BlogManager,
BdfList authorList = meta.getList(KEY_AUTHOR); BdfList authorList = meta.getList(KEY_AUTHOR);
Author author = clientHelper.parseAndValidateAuthor(authorList); Author author = clientHelper.parseAndValidateAuthor(authorList);
boolean isFeedPost = meta.getBoolean(KEY_RSS_FEED, false); boolean isFeedPost = meta.getBoolean(KEY_RSS_FEED, false);
Status authorStatus; AuthorInfo authorInfo;
if (isFeedPost) { if (isFeedPost) {
authorStatus = Status.NONE; authorInfo = new AuthorInfo(NONE);
} else if (authorStatuses.containsKey(author.getId())) { } else if (authorInfos.containsKey(author.getId())) {
authorStatus = authorStatuses.get(author.getId()); authorInfo = authorInfos.get(author.getId());
} else { } else {
authorStatus = identityManager.getAuthorStatus(txn, author.getId()); authorInfo = contactManager.getAuthorInfo(txn, author.getId());
} }
boolean read = meta.getBoolean(KEY_READ, false); boolean read = meta.getBoolean(KEY_READ, false);
@@ -591,10 +594,10 @@ class BlogManagerImpl extends BdfIncomingMessageHook implements BlogManager,
BlogPostHeader parent = BlogPostHeader parent =
getPostHeaderFromMetadata(txn, groupId, parentId); getPostHeaderFromMetadata(txn, groupId, parentId);
return new BlogCommentHeader(type, groupId, comment, parent, id, return new BlogCommentHeader(type, groupId, comment, parent, id,
timestamp, timeReceived, author, authorStatus, read); timestamp, timeReceived, author, authorInfo, read);
} else { } else {
return new BlogPostHeader(type, groupId, id, timestamp, return new BlogPostHeader(type, groupId, id, timestamp,
timeReceived, author, authorStatus, isFeedPost, read); timeReceived, author, authorInfo, isFeedPost, read);
} }
} }

View File

@@ -2,6 +2,7 @@ package org.briarproject.briar.forum;
import org.briarproject.bramble.api.FormatException; import org.briarproject.bramble.api.FormatException;
import org.briarproject.bramble.api.client.ClientHelper; import org.briarproject.bramble.api.client.ClientHelper;
import org.briarproject.bramble.api.contact.ContactManager;
import org.briarproject.bramble.api.data.BdfDictionary; import org.briarproject.bramble.api.data.BdfDictionary;
import org.briarproject.bramble.api.data.BdfList; import org.briarproject.bramble.api.data.BdfList;
import org.briarproject.bramble.api.data.MetadataParser; import org.briarproject.bramble.api.data.MetadataParser;
@@ -9,9 +10,8 @@ import org.briarproject.bramble.api.db.DatabaseComponent;
import org.briarproject.bramble.api.db.DbException; import org.briarproject.bramble.api.db.DbException;
import org.briarproject.bramble.api.db.Transaction; import org.briarproject.bramble.api.db.Transaction;
import org.briarproject.bramble.api.identity.Author; import org.briarproject.bramble.api.identity.Author;
import org.briarproject.bramble.api.identity.Author.Status;
import org.briarproject.bramble.api.identity.AuthorId; import org.briarproject.bramble.api.identity.AuthorId;
import org.briarproject.bramble.api.identity.IdentityManager; import org.briarproject.bramble.api.identity.AuthorInfo;
import org.briarproject.bramble.api.identity.LocalAuthor; import org.briarproject.bramble.api.identity.LocalAuthor;
import org.briarproject.bramble.api.nullsafety.NotNullByDefault; import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
import org.briarproject.bramble.api.sync.Group; import org.briarproject.bramble.api.sync.Group;
@@ -45,7 +45,7 @@ import javax.annotation.Nullable;
import javax.annotation.concurrent.ThreadSafe; import javax.annotation.concurrent.ThreadSafe;
import javax.inject.Inject; import javax.inject.Inject;
import static org.briarproject.bramble.api.identity.Author.Status.OURSELVES; import static org.briarproject.bramble.api.identity.AuthorInfo.Status.OURSELVES;
import static org.briarproject.briar.api.forum.ForumConstants.KEY_AUTHOR; import static org.briarproject.briar.api.forum.ForumConstants.KEY_AUTHOR;
import static org.briarproject.briar.api.forum.ForumConstants.KEY_LOCAL; import static org.briarproject.briar.api.forum.ForumConstants.KEY_LOCAL;
import static org.briarproject.briar.api.forum.ForumConstants.KEY_PARENT; import static org.briarproject.briar.api.forum.ForumConstants.KEY_PARENT;
@@ -56,19 +56,19 @@ import static org.briarproject.briar.client.MessageTrackerConstants.MSG_KEY_READ
@NotNullByDefault @NotNullByDefault
class ForumManagerImpl extends BdfIncomingMessageHook implements ForumManager { class ForumManagerImpl extends BdfIncomingMessageHook implements ForumManager {
private final IdentityManager identityManager; private final ContactManager contactManager;
private final ForumFactory forumFactory; private final ForumFactory forumFactory;
private final ForumPostFactory forumPostFactory; private final ForumPostFactory forumPostFactory;
private final MessageTracker messageTracker; private final MessageTracker messageTracker;
private final List<RemoveForumHook> removeHooks; private final List<RemoveForumHook> removeHooks;
@Inject @Inject
ForumManagerImpl(DatabaseComponent db, IdentityManager identityManager, ForumManagerImpl(DatabaseComponent db, ContactManager contactManager,
ClientHelper clientHelper, MetadataParser metadataParser, ClientHelper clientHelper, MetadataParser metadataParser,
ForumFactory forumFactory, ForumPostFactory forumPostFactory, ForumFactory forumFactory, ForumPostFactory forumPostFactory,
MessageTracker messageTracker) { MessageTracker messageTracker) {
super(db, clientHelper, metadataParser); super(db, clientHelper, metadataParser);
this.identityManager = identityManager; this.contactManager = contactManager;
this.forumFactory = forumFactory; this.forumFactory = forumFactory;
this.forumPostFactory = forumPostFactory; this.forumPostFactory = forumPostFactory;
this.messageTracker = messageTracker; this.messageTracker = messageTracker;
@@ -142,8 +142,9 @@ class ForumManagerImpl extends BdfIncomingMessageHook implements ForumManager {
throw new AssertionError(e); throw new AssertionError(e);
} }
}); });
AuthorInfo authorInfo = new AuthorInfo(OURSELVES);
return new ForumPostHeader(p.getMessage().getId(), p.getParent(), return new ForumPostHeader(p.getMessage().getId(), p.getParent(),
p.getMessage().getTimestamp(), p.getAuthor(), OURSELVES, true); p.getMessage().getTimestamp(), p.getAuthor(), authorInfo, true);
} }
@Override @Override
@@ -196,7 +197,7 @@ class ForumManagerImpl extends BdfIncomingMessageHook implements ForumManager {
Collection<ForumPostHeader> headers = new ArrayList<>(); Collection<ForumPostHeader> headers = new ArrayList<>();
Map<MessageId, BdfDictionary> metadata = Map<MessageId, BdfDictionary> metadata =
clientHelper.getMessageMetadataAsDictionary(txn, g); clientHelper.getMessageMetadataAsDictionary(txn, g);
// get all authors we need to get the status for // get all authors we need to get the info for
Set<AuthorId> authors = new HashSet<>(); Set<AuthorId> authors = new HashSet<>();
for (Entry<MessageId, BdfDictionary> entry : for (Entry<MessageId, BdfDictionary> entry :
metadata.entrySet()) { metadata.entrySet()) {
@@ -204,17 +205,17 @@ class ForumManagerImpl extends BdfIncomingMessageHook implements ForumManager {
Author a = clientHelper.parseAndValidateAuthor(authorList); Author a = clientHelper.parseAndValidateAuthor(authorList);
authors.add(a.getId()); authors.add(a.getId());
} }
// get statuses for all authors // get information for all authors
Map<AuthorId, Status> statuses = new HashMap<>(); Map<AuthorId, AuthorInfo> authorInfos = new HashMap<>();
for (AuthorId id : authors) { for (AuthorId id : authors) {
statuses.put(id, identityManager.getAuthorStatus(txn, id)); authorInfos.put(id, contactManager.getAuthorInfo(txn, id));
} }
// Parse the metadata // Parse the metadata
for (Entry<MessageId, BdfDictionary> entry : for (Entry<MessageId, BdfDictionary> entry :
metadata.entrySet()) { metadata.entrySet()) {
BdfDictionary meta = entry.getValue(); BdfDictionary meta = entry.getValue();
headers.add(getForumPostHeader(txn, entry.getKey(), meta, headers.add(getForumPostHeader(txn, entry.getKey(), meta,
statuses)); authorInfos));
} }
return headers; return headers;
}); });
@@ -252,7 +253,7 @@ class ForumManagerImpl extends BdfIncomingMessageHook implements ForumManager {
} }
private ForumPostHeader getForumPostHeader(Transaction txn, MessageId id, private ForumPostHeader getForumPostHeader(Transaction txn, MessageId id,
BdfDictionary meta, Map<AuthorId, Status> statuses) BdfDictionary meta, Map<AuthorId, AuthorInfo> authorInfos)
throws DbException, FormatException { throws DbException, FormatException {
long timestamp = meta.getLong(KEY_TIMESTAMP); long timestamp = meta.getLong(KEY_TIMESTAMP);
@@ -261,12 +262,12 @@ class ForumManagerImpl extends BdfIncomingMessageHook implements ForumManager {
parentId = new MessageId(meta.getRaw(KEY_PARENT)); parentId = new MessageId(meta.getRaw(KEY_PARENT));
BdfList authorList = meta.getList(KEY_AUTHOR); BdfList authorList = meta.getList(KEY_AUTHOR);
Author author = clientHelper.parseAndValidateAuthor(authorList); Author author = clientHelper.parseAndValidateAuthor(authorList);
Status status = statuses.get(author.getId()); AuthorInfo authorInfo = authorInfos.get(author.getId());
if (status == null) if (authorInfo == null)
status = identityManager.getAuthorStatus(txn, author.getId()); authorInfo = contactManager.getAuthorInfo(txn, author.getId());
boolean read = meta.getBoolean(MSG_KEY_READ); boolean read = meta.getBoolean(MSG_KEY_READ);
return new ForumPostHeader(id, parentId, timestamp, author, status, return new ForumPostHeader(id, parentId, timestamp, author, authorInfo,
read); read);
} }

View File

@@ -13,8 +13,9 @@ import org.briarproject.bramble.api.db.DbException;
import org.briarproject.bramble.api.db.Transaction; import org.briarproject.bramble.api.db.Transaction;
import org.briarproject.bramble.api.event.Event; import org.briarproject.bramble.api.event.Event;
import org.briarproject.bramble.api.identity.Author; import org.briarproject.bramble.api.identity.Author;
import org.briarproject.bramble.api.identity.Author.Status;
import org.briarproject.bramble.api.identity.AuthorId; import org.briarproject.bramble.api.identity.AuthorId;
import org.briarproject.bramble.api.identity.AuthorInfo;
import org.briarproject.bramble.api.identity.AuthorInfo.Status;
import org.briarproject.bramble.api.identity.IdentityManager; import org.briarproject.bramble.api.identity.IdentityManager;
import org.briarproject.bramble.api.identity.LocalAuthor; import org.briarproject.bramble.api.identity.LocalAuthor;
import org.briarproject.bramble.api.nullsafety.NotNullByDefault; import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
@@ -53,9 +54,9 @@ import java.util.concurrent.CopyOnWriteArrayList;
import javax.annotation.concurrent.ThreadSafe; import javax.annotation.concurrent.ThreadSafe;
import javax.inject.Inject; import javax.inject.Inject;
import static org.briarproject.bramble.api.identity.Author.Status.OURSELVES; import static org.briarproject.bramble.api.identity.AuthorInfo.Status.OURSELVES;
import static org.briarproject.bramble.api.identity.Author.Status.UNVERIFIED; import static org.briarproject.bramble.api.identity.AuthorInfo.Status.UNVERIFIED;
import static org.briarproject.bramble.api.identity.Author.Status.VERIFIED; import static org.briarproject.bramble.api.identity.AuthorInfo.Status.VERIFIED;
import static org.briarproject.briar.api.privategroup.MessageType.JOIN; import static org.briarproject.briar.api.privategroup.MessageType.JOIN;
import static org.briarproject.briar.api.privategroup.MessageType.POST; import static org.briarproject.briar.api.privategroup.MessageType.POST;
import static org.briarproject.briar.api.privategroup.Visibility.INVISIBLE; import static org.briarproject.briar.api.privategroup.Visibility.INVISIBLE;
@@ -231,9 +232,10 @@ class PrivateGroupManagerImpl extends BdfIncomingMessageHook
} finally { } finally {
db.endTransaction(txn); db.endTransaction(txn);
} }
AuthorInfo authorInfo = new AuthorInfo(OURSELVES);
return new GroupMessageHeader(m.getMessage().getGroupId(), return new GroupMessageHeader(m.getMessage().getGroupId(),
m.getMessage().getId(), m.getParent(), m.getMessage().getId(), m.getParent(),
m.getMessage().getTimestamp(), m.getMember(), OURSELVES, true); m.getMessage().getTimestamp(), m.getMember(), authorInfo, true);
} }
private void addMessageMetadata(BdfDictionary meta, GroupMessage m) { private void addMessageMetadata(BdfDictionary meta, GroupMessage m) {
@@ -321,15 +323,15 @@ class PrivateGroupManagerImpl extends BdfIncomingMessageHook
try { try {
Map<MessageId, BdfDictionary> metadata = Map<MessageId, BdfDictionary> metadata =
clientHelper.getMessageMetadataAsDictionary(txn, g); clientHelper.getMessageMetadataAsDictionary(txn, g);
// get all authors we need to get the status for // get all authors we need to get the information for
Set<AuthorId> authors = new HashSet<>(); Set<AuthorId> authors = new HashSet<>();
for (BdfDictionary meta : metadata.values()) { for (BdfDictionary meta : metadata.values()) {
authors.add(getAuthor(meta).getId()); authors.add(getAuthor(meta).getId());
} }
// get statuses for all authors // get information for all authors
Map<AuthorId, Status> statuses = new HashMap<>(); Map<AuthorId, AuthorInfo> authorInfos = new HashMap<>();
for (AuthorId id : authors) { for (AuthorId id : authors) {
statuses.put(id, identityManager.getAuthorStatus(txn, id)); authorInfos.put(id, contactManager.getAuthorInfo(txn, id));
} }
// get current visibilities for join messages // get current visibilities for join messages
Map<Author, Visibility> visibilities = getMembers(txn, g); Map<Author, Visibility> visibilities = getMembers(txn, g);
@@ -340,10 +342,10 @@ class PrivateGroupManagerImpl extends BdfIncomingMessageHook
Author member = getAuthor(meta); Author member = getAuthor(meta);
Visibility v = visibilities.get(member); Visibility v = visibilities.get(member);
headers.add(getJoinMessageHeader(txn, g, entry.getKey(), headers.add(getJoinMessageHeader(txn, g, entry.getKey(),
meta, statuses, v)); meta, authorInfos, v));
} else { } else {
headers.add(getGroupMessageHeader(txn, g, entry.getKey(), headers.add(getGroupMessageHeader(txn, g, entry.getKey(),
meta, statuses)); meta, authorInfos));
} }
} }
db.commitTransaction(txn); db.commitTransaction(txn);
@@ -356,7 +358,8 @@ class PrivateGroupManagerImpl extends BdfIncomingMessageHook
} }
private GroupMessageHeader getGroupMessageHeader(Transaction txn, GroupId g, private GroupMessageHeader getGroupMessageHeader(Transaction txn, GroupId g,
MessageId id, BdfDictionary meta, Map<AuthorId, Status> statuses) MessageId id, BdfDictionary meta,
Map<AuthorId, AuthorInfo> authorInfos)
throws DbException, FormatException { throws DbException, FormatException {
MessageId parentId = null; MessageId parentId = null;
@@ -366,24 +369,25 @@ class PrivateGroupManagerImpl extends BdfIncomingMessageHook
long timestamp = meta.getLong(KEY_TIMESTAMP); long timestamp = meta.getLong(KEY_TIMESTAMP);
Author member = getAuthor(meta); Author member = getAuthor(meta);
Status status; AuthorInfo authorInfo;
if (statuses.containsKey(member.getId())) { if (authorInfos.containsKey(member.getId())) {
status = statuses.get(member.getId()); authorInfo = authorInfos.get(member.getId());
} else { } else {
status = identityManager.getAuthorStatus(txn, member.getId()); authorInfo = contactManager.getAuthorInfo(txn, member.getId());
} }
boolean read = meta.getBoolean(KEY_READ); boolean read = meta.getBoolean(KEY_READ);
return new GroupMessageHeader(g, id, parentId, timestamp, member, return new GroupMessageHeader(g, id, parentId, timestamp, member,
status, read); authorInfo, read);
} }
private JoinMessageHeader getJoinMessageHeader(Transaction txn, GroupId g, private JoinMessageHeader getJoinMessageHeader(Transaction txn, GroupId g,
MessageId id, BdfDictionary meta, Map<AuthorId, Status> statuses, MessageId id, BdfDictionary meta,
Visibility v) throws DbException, FormatException { Map<AuthorId, AuthorInfo> authorInfos, Visibility v)
throws DbException, FormatException {
GroupMessageHeader header = GroupMessageHeader header =
getGroupMessageHeader(txn, g, id, meta, statuses); getGroupMessageHeader(txn, g, id, meta, authorInfos);
boolean creator = meta.getBoolean(KEY_INITIAL_JOIN_MSG); boolean creator = meta.getBoolean(KEY_INITIAL_JOIN_MSG);
return new JoinMessageHeader(header, v, creator); return new JoinMessageHeader(header, v, creator);
} }
@@ -398,7 +402,8 @@ class PrivateGroupManagerImpl extends BdfIncomingMessageHook
PrivateGroup privateGroup = getPrivateGroup(txn, g); PrivateGroup privateGroup = getPrivateGroup(txn, g);
for (Entry<Author, Visibility> m : authors.entrySet()) { for (Entry<Author, Visibility> m : authors.entrySet()) {
Author a = m.getKey(); Author a = m.getKey();
Status status = identityManager.getAuthorStatus(txn, a.getId()); AuthorInfo authorInfo = contactManager.getAuthorInfo(txn, a.getId());
Status status = authorInfo.getStatus();
Visibility v = m.getValue(); Visibility v = m.getValue();
ContactId c = null; ContactId c = null;
if (v != INVISIBLE && if (v != INVISIBLE &&
@@ -407,7 +412,7 @@ class PrivateGroupManagerImpl extends BdfIncomingMessageHook
.getId(); .getId();
} }
boolean isCreator = privateGroup.getCreator().equals(a); boolean isCreator = privateGroup.getCreator().equals(a);
members.add(new GroupMember(a, status, isCreator, c, v)); members.add(new GroupMember(a, authorInfo, isCreator, c, v));
} }
db.commitTransaction(txn); db.commitTransaction(txn);
return members; return members;

View File

@@ -4,6 +4,7 @@ import org.briarproject.bramble.api.FormatException;
import org.briarproject.bramble.api.client.ClientHelper; import org.briarproject.bramble.api.client.ClientHelper;
import org.briarproject.bramble.api.contact.Contact; import org.briarproject.bramble.api.contact.Contact;
import org.briarproject.bramble.api.contact.ContactId; import org.briarproject.bramble.api.contact.ContactId;
import org.briarproject.bramble.api.contact.ContactManager;
import org.briarproject.bramble.api.data.BdfDictionary; import org.briarproject.bramble.api.data.BdfDictionary;
import org.briarproject.bramble.api.data.BdfEntry; import org.briarproject.bramble.api.data.BdfEntry;
import org.briarproject.bramble.api.data.BdfList; import org.briarproject.bramble.api.data.BdfList;
@@ -12,6 +13,7 @@ import org.briarproject.bramble.api.db.DatabaseComponent;
import org.briarproject.bramble.api.db.DbException; import org.briarproject.bramble.api.db.DbException;
import org.briarproject.bramble.api.db.Transaction; import org.briarproject.bramble.api.db.Transaction;
import org.briarproject.bramble.api.identity.Author; import org.briarproject.bramble.api.identity.Author;
import org.briarproject.bramble.api.identity.AuthorInfo;
import org.briarproject.bramble.api.identity.IdentityManager; import org.briarproject.bramble.api.identity.IdentityManager;
import org.briarproject.bramble.api.identity.LocalAuthor; import org.briarproject.bramble.api.identity.LocalAuthor;
import org.briarproject.bramble.api.sync.Group; import org.briarproject.bramble.api.sync.Group;
@@ -29,9 +31,9 @@ import org.jmock.Expectations;
import org.jmock.Mockery; import org.jmock.Mockery;
import org.junit.Test; import org.junit.Test;
import static org.briarproject.bramble.api.identity.Author.Status.NONE; import static org.briarproject.bramble.api.identity.AuthorInfo.Status.NONE;
import static org.briarproject.bramble.api.identity.Author.Status.OURSELVES; import static org.briarproject.bramble.api.identity.AuthorInfo.Status.OURSELVES;
import static org.briarproject.bramble.api.identity.Author.Status.VERIFIED; import static org.briarproject.bramble.api.identity.AuthorInfo.Status.VERIFIED;
import static org.briarproject.bramble.test.TestUtils.getGroup; import static org.briarproject.bramble.test.TestUtils.getGroup;
import static org.briarproject.bramble.test.TestUtils.getLocalAuthor; import static org.briarproject.bramble.test.TestUtils.getLocalAuthor;
import static org.briarproject.bramble.test.TestUtils.getMessage; import static org.briarproject.bramble.test.TestUtils.getMessage;
@@ -64,6 +66,8 @@ public class BlogManagerImplTest extends BriarTestCase {
private final Mockery context = new Mockery(); private final Mockery context = new Mockery();
private final BlogManagerImpl blogManager; private final BlogManagerImpl blogManager;
private final DatabaseComponent db = context.mock(DatabaseComponent.class); private final DatabaseComponent db = context.mock(DatabaseComponent.class);
private final ContactManager contactManager =
context.mock(ContactManager.class);
private final IdentityManager identityManager = private final IdentityManager identityManager =
context.mock(IdentityManager.class); context.mock(IdentityManager.class);
private final ClientHelper clientHelper = context.mock(ClientHelper.class); private final ClientHelper clientHelper = context.mock(ClientHelper.class);
@@ -72,6 +76,8 @@ public class BlogManagerImplTest extends BriarTestCase {
context.mock(BlogPostFactory.class); context.mock(BlogPostFactory.class);
private final LocalAuthor localAuthor1, localAuthor2, rssLocalAuthor; private final LocalAuthor localAuthor1, localAuthor2, rssLocalAuthor;
private final AuthorInfo ourselvesInfo = new AuthorInfo(OURSELVES);
private final AuthorInfo verifiedInfo = new AuthorInfo(VERIFIED);
private final BdfList authorList1, authorList2, rssAuthorList; private final BdfList authorList1, authorList2, rssAuthorList;
private final Blog blog1, blog2, rssBlog; private final Blog blog1, blog2, rssBlog;
private final Message message, rssMessage; private final Message message, rssMessage;
@@ -81,7 +87,7 @@ public class BlogManagerImplTest extends BriarTestCase {
public BlogManagerImplTest() { public BlogManagerImplTest() {
MetadataParser metadataParser = context.mock(MetadataParser.class); MetadataParser metadataParser = context.mock(MetadataParser.class);
blogManager = new BlogManagerImpl(db, identityManager, clientHelper, blogManager = new BlogManagerImpl(db, contactManager, identityManager, clientHelper,
metadataParser, blogFactory, blogPostFactory); metadataParser, blogFactory, blogPostFactory);
localAuthor1 = getLocalAuthor(); localAuthor1 = getLocalAuthor();
@@ -175,8 +181,8 @@ public class BlogManagerImplTest extends BriarTestCase {
context.checking(new Expectations() {{ context.checking(new Expectations() {{
oneOf(clientHelper).parseAndValidateAuthor(authorList1); oneOf(clientHelper).parseAndValidateAuthor(authorList1);
will(returnValue(localAuthor1)); will(returnValue(localAuthor1));
oneOf(identityManager).getAuthorStatus(txn, localAuthor1.getId()); oneOf(contactManager).getAuthorInfo(txn, localAuthor1.getId());
will(returnValue(VERIFIED)); will(returnValue(verifiedInfo));
}}); }});
blogManager.incomingMessage(txn, message, body, meta); blogManager.incomingMessage(txn, message, body, meta);
@@ -281,8 +287,8 @@ public class BlogManagerImplTest extends BriarTestCase {
oneOf(clientHelper).addLocalMessage(txn, message, meta, true); oneOf(clientHelper).addLocalMessage(txn, message, meta, true);
oneOf(clientHelper).parseAndValidateAuthor(authorList1); oneOf(clientHelper).parseAndValidateAuthor(authorList1);
will(returnValue(localAuthor1)); will(returnValue(localAuthor1));
oneOf(identityManager).getAuthorStatus(txn, localAuthor1.getId()); oneOf(contactManager).getAuthorInfo(txn, localAuthor1.getId());
will(returnValue(OURSELVES)); will(returnValue(ourselvesInfo));
oneOf(db).commitTransaction(txn); oneOf(db).commitTransaction(txn);
oneOf(db).endTransaction(txn); oneOf(db).endTransaction(txn);
}}); }});
@@ -396,21 +402,21 @@ public class BlogManagerImplTest extends BriarTestCase {
// Create the headers for the comment and its parent // Create the headers for the comment and its parent
oneOf(clientHelper).parseAndValidateAuthor(authorList1); oneOf(clientHelper).parseAndValidateAuthor(authorList1);
will(returnValue(localAuthor1)); will(returnValue(localAuthor1));
oneOf(identityManager).getAuthorStatus(txn, localAuthor1.getId()); oneOf(contactManager).getAuthorInfo(txn, localAuthor1.getId());
will(returnValue(OURSELVES)); will(returnValue(ourselvesInfo));
oneOf(clientHelper).getMessageMetadataAsDictionary(txn, messageId); oneOf(clientHelper).getMessageMetadataAsDictionary(txn, messageId);
will(returnValue(postMeta)); will(returnValue(postMeta));
oneOf(clientHelper).parseAndValidateAuthor(authorList1); oneOf(clientHelper).parseAndValidateAuthor(authorList1);
will(returnValue(localAuthor1)); will(returnValue(localAuthor1));
oneOf(identityManager).getAuthorStatus(txn, localAuthor1.getId()); oneOf(contactManager).getAuthorInfo(txn, localAuthor1.getId());
will(returnValue(OURSELVES)); will(returnValue(ourselvesInfo));
oneOf(db).commitTransaction(txn); oneOf(db).commitTransaction(txn);
oneOf(db).endTransaction(txn); oneOf(db).endTransaction(txn);
}}); }});
BlogPostHeader postHeader = new BlogPostHeader(POST, blog1.getId(), BlogPostHeader postHeader = new BlogPostHeader(POST, blog1.getId(),
messageId, null, timestamp, timeReceived, localAuthor1, messageId, null, timestamp, timeReceived, localAuthor1,
OURSELVES, false, true); ourselvesInfo, false, true);
blogManager.addLocalComment(localAuthor1, blog1.getId(), comment, blogManager.addLocalComment(localAuthor1, blog1.getId(), comment,
postHeader); postHeader);
context.assertIsSatisfied(); context.assertIsSatisfied();
@@ -504,22 +510,22 @@ public class BlogManagerImplTest extends BriarTestCase {
// Create the headers for the comment and the wrapped post // Create the headers for the comment and the wrapped post
oneOf(clientHelper).parseAndValidateAuthor(authorList2); oneOf(clientHelper).parseAndValidateAuthor(authorList2);
will(returnValue(localAuthor2)); will(returnValue(localAuthor2));
oneOf(identityManager).getAuthorStatus(txn, localAuthor2.getId()); oneOf(contactManager).getAuthorInfo(txn, localAuthor2.getId());
will(returnValue(OURSELVES)); will(returnValue(ourselvesInfo));
oneOf(clientHelper).getMessageMetadataAsDictionary(txn, oneOf(clientHelper).getMessageMetadataAsDictionary(txn,
wrappedPostId); wrappedPostId);
will(returnValue(wrappedPostMeta)); will(returnValue(wrappedPostMeta));
oneOf(clientHelper).parseAndValidateAuthor(authorList1); oneOf(clientHelper).parseAndValidateAuthor(authorList1);
will(returnValue(localAuthor1)); will(returnValue(localAuthor1));
oneOf(identityManager).getAuthorStatus(txn, localAuthor1.getId()); oneOf(contactManager).getAuthorInfo(txn, localAuthor1.getId());
will(returnValue(VERIFIED)); will(returnValue(verifiedInfo));
oneOf(db).commitTransaction(txn); oneOf(db).commitTransaction(txn);
oneOf(db).endTransaction(txn); oneOf(db).endTransaction(txn);
}}); }});
BlogPostHeader originalPostHeader = new BlogPostHeader(POST, BlogPostHeader originalPostHeader = new BlogPostHeader(POST,
blog1.getId(), messageId, null, timestamp, timeReceived, blog1.getId(), messageId, null, timestamp, timeReceived,
localAuthor1, VERIFIED, false, true); localAuthor1, verifiedInfo, false, true);
blogManager.addLocalComment(localAuthor2, blog2.getId(), comment, blogManager.addLocalComment(localAuthor2, blog2.getId(), comment,
originalPostHeader); originalPostHeader);
context.assertIsSatisfied(); context.assertIsSatisfied();
@@ -613,8 +619,8 @@ public class BlogManagerImplTest extends BriarTestCase {
// Create the headers for the comment and the wrapped post // Create the headers for the comment and the wrapped post
oneOf(clientHelper).parseAndValidateAuthor(authorList1); oneOf(clientHelper).parseAndValidateAuthor(authorList1);
will(returnValue(localAuthor1)); will(returnValue(localAuthor1));
oneOf(identityManager).getAuthorStatus(txn, localAuthor1.getId()); oneOf(contactManager).getAuthorInfo(txn, localAuthor1.getId());
will(returnValue(OURSELVES)); will(returnValue(ourselvesInfo));
oneOf(clientHelper).getMessageMetadataAsDictionary(txn, oneOf(clientHelper).getMessageMetadataAsDictionary(txn,
wrappedPostId); wrappedPostId);
will(returnValue(wrappedPostMeta)); will(returnValue(wrappedPostMeta));
@@ -626,7 +632,7 @@ public class BlogManagerImplTest extends BriarTestCase {
BlogPostHeader originalPostHeader = new BlogPostHeader(POST, BlogPostHeader originalPostHeader = new BlogPostHeader(POST,
rssBlog.getId(), rssMessageId, null, timestamp, timeReceived, rssBlog.getId(), rssMessageId, null, timestamp, timeReceived,
rssLocalAuthor, NONE, true, true); rssLocalAuthor, new AuthorInfo(NONE), true, true);
blogManager.addLocalComment(localAuthor1, blog1.getId(), comment, blogManager.addLocalComment(localAuthor1, blog1.getId(), comment,
originalPostHeader); originalPostHeader);
context.assertIsSatisfied(); context.assertIsSatisfied();
@@ -752,15 +758,15 @@ public class BlogManagerImplTest extends BriarTestCase {
// the rewrapped post // the rewrapped post
oneOf(clientHelper).parseAndValidateAuthor(authorList2); oneOf(clientHelper).parseAndValidateAuthor(authorList2);
will(returnValue(localAuthor2)); will(returnValue(localAuthor2));
oneOf(identityManager).getAuthorStatus(txn, localAuthor2.getId()); oneOf(contactManager).getAuthorInfo(txn, localAuthor2.getId());
will(returnValue(OURSELVES)); will(returnValue(ourselvesInfo));
oneOf(clientHelper).getMessageMetadataAsDictionary(txn, oneOf(clientHelper).getMessageMetadataAsDictionary(txn,
wrappedCommentId); wrappedCommentId);
will(returnValue(wrappedCommentMeta)); will(returnValue(wrappedCommentMeta));
oneOf(clientHelper).parseAndValidateAuthor(authorList1); oneOf(clientHelper).parseAndValidateAuthor(authorList1);
will(returnValue(localAuthor1)); will(returnValue(localAuthor1));
oneOf(identityManager).getAuthorStatus(txn, localAuthor1.getId()); oneOf(contactManager).getAuthorInfo(txn, localAuthor1.getId());
will(returnValue(VERIFIED)); will(returnValue(verifiedInfo));
oneOf(clientHelper).getMessageMetadataAsDictionary(txn, oneOf(clientHelper).getMessageMetadataAsDictionary(txn,
rewrappedPostId); rewrappedPostId);
will(returnValue(rewrappedPostMeta)); will(returnValue(rewrappedPostMeta));
@@ -772,10 +778,10 @@ public class BlogManagerImplTest extends BriarTestCase {
BlogPostHeader wrappedPostHeader = new BlogPostHeader(WRAPPED_POST, BlogPostHeader wrappedPostHeader = new BlogPostHeader(WRAPPED_POST,
blog1.getId(), wrappedPostId, null, timestamp, timeReceived, blog1.getId(), wrappedPostId, null, timestamp, timeReceived,
rssLocalAuthor, NONE, true, true); rssLocalAuthor, new AuthorInfo(NONE), true, true);
BlogCommentHeader originalCommentHeader = new BlogCommentHeader(COMMENT, BlogCommentHeader originalCommentHeader = new BlogCommentHeader(COMMENT,
blog1.getId(), comment, wrappedPostHeader, originalCommentId, blog1.getId(), comment, wrappedPostHeader, originalCommentId,
timestamp, timeReceived, localAuthor1, VERIFIED, true); timestamp, timeReceived, localAuthor1, verifiedInfo, true);
blogManager.addLocalComment(localAuthor2, blog2.getId(), localComment, blogManager.addLocalComment(localAuthor2, blog2.getId(), localComment,
originalCommentHeader); originalCommentHeader);

View File

@@ -1,6 +1,5 @@
package org.briarproject.briar.blog; package org.briarproject.briar.blog;
import org.briarproject.bramble.api.identity.Author;
import org.briarproject.bramble.api.identity.LocalAuthor; import org.briarproject.bramble.api.identity.LocalAuthor;
import org.briarproject.bramble.api.sync.MessageId; import org.briarproject.bramble.api.sync.MessageId;
import org.briarproject.bramble.test.TestDatabaseModule; import org.briarproject.bramble.test.TestDatabaseModule;
@@ -23,6 +22,7 @@ import java.util.Iterator;
import static junit.framework.Assert.assertNotNull; import static junit.framework.Assert.assertNotNull;
import static org.briarproject.bramble.api.identity.AuthorConstants.MAX_AUTHOR_NAME_LENGTH; import static org.briarproject.bramble.api.identity.AuthorConstants.MAX_AUTHOR_NAME_LENGTH;
import static org.briarproject.bramble.api.identity.AuthorConstants.MAX_PUBLIC_KEY_LENGTH; import static org.briarproject.bramble.api.identity.AuthorConstants.MAX_PUBLIC_KEY_LENGTH;
import static org.briarproject.bramble.api.identity.AuthorInfo.Status.NONE;
import static org.briarproject.bramble.test.TestUtils.getRandomBytes; import static org.briarproject.bramble.test.TestUtils.getRandomBytes;
import static org.briarproject.bramble.util.StringUtils.getRandomString; import static org.briarproject.bramble.util.StringUtils.getRandomString;
import static org.briarproject.briar.api.blog.MessageType.COMMENT; import static org.briarproject.briar.api.blog.MessageType.COMMENT;
@@ -424,7 +424,7 @@ public class BlogManagerIntegrationTest
assertEquals(1, headers.size()); assertEquals(1, headers.size());
BlogPostHeader header = headers.iterator().next(); BlogPostHeader header = headers.iterator().next();
assertEquals(POST, header.getType()); assertEquals(POST, header.getType());
assertEquals(Author.Status.NONE, header.getAuthorStatus()); assertEquals(NONE, header.getAuthorStatus());
assertTrue(header.isRssFeed()); assertTrue(header.isRssFeed());
} }

View File

@@ -24,7 +24,7 @@ import java.util.Collection;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import static org.briarproject.bramble.api.identity.Author.Status.OURSELVES; import static org.briarproject.bramble.api.identity.AuthorInfo.Status.OURSELVES;
import static org.briarproject.briar.api.privategroup.Visibility.INVISIBLE; import static org.briarproject.briar.api.privategroup.Visibility.INVISIBLE;
import static org.briarproject.briar.api.privategroup.Visibility.REVEALED_BY_CONTACT; import static org.briarproject.briar.api.privategroup.Visibility.REVEALED_BY_CONTACT;
import static org.briarproject.briar.api.privategroup.Visibility.REVEALED_BY_US; import static org.briarproject.briar.api.privategroup.Visibility.REVEALED_BY_US;
@@ -92,7 +92,8 @@ public class PrivateGroupIntegrationTest
Collection<GroupMember> members = groupManager0.getMembers(groupId0); Collection<GroupMember> members = groupManager0.getMembers(groupId0);
assertEquals(1, members.size()); assertEquals(1, members.size());
assertEquals(author0, members.iterator().next().getAuthor()); assertEquals(author0, members.iterator().next().getAuthor());
assertEquals(OURSELVES, members.iterator().next().getStatus()); assertEquals(OURSELVES,
members.iterator().next().getAuthorInfo().getStatus());
sync0To1(1, true); sync0To1(1, true);
groupInvitationManager1 groupInvitationManager1
@@ -107,7 +108,7 @@ public class PrivateGroupIntegrationTest
members = groupManager0.getMembers(groupId0); members = groupManager0.getMembers(groupId0);
assertEquals(2, members.size()); assertEquals(2, members.size());
for (GroupMember m : members) { for (GroupMember m : members) {
if (m.getStatus() == OURSELVES) { if (m.getAuthorInfo().getStatus() == OURSELVES) {
assertEquals(author0.getId(), m.getAuthor().getId()); assertEquals(author0.getId(), m.getAuthor().getId());
} else { } else {
assertEquals(author1.getId(), m.getAuthor().getId()); assertEquals(author1.getId(), m.getAuthor().getId());
@@ -117,7 +118,7 @@ public class PrivateGroupIntegrationTest
members = groupManager1.getMembers(groupId0); members = groupManager1.getMembers(groupId0);
assertEquals(2, members.size()); assertEquals(2, members.size());
for (GroupMember m : members) { for (GroupMember m : members) {
if (m.getStatus() == OURSELVES) { if (m.getAuthorInfo().getStatus() == OURSELVES) {
assertEquals(author1.getId(), m.getAuthor().getId()); assertEquals(author1.getId(), m.getAuthor().getId());
} else { } else {
assertEquals(author0.getId(), m.getAuthor().getId()); assertEquals(author0.getId(), m.getAuthor().getId());

View File

@@ -20,7 +20,7 @@ import org.junit.Test;
import java.util.Collection; import java.util.Collection;
import static org.briarproject.bramble.api.identity.Author.Status.VERIFIED; import static org.briarproject.bramble.api.identity.AuthorInfo.Status.VERIFIED;
import static org.briarproject.bramble.api.sync.Group.Visibility.SHARED; import static org.briarproject.bramble.api.sync.Group.Visibility.SHARED;
import static org.briarproject.bramble.test.TestUtils.getRandomBytes; import static org.briarproject.bramble.test.TestUtils.getRandomBytes;
import static org.briarproject.bramble.test.TestUtils.getRandomId; import static org.briarproject.bramble.test.TestUtils.getRandomId;

View File

@@ -1,6 +1,7 @@
package org.briarproject.bramble.identity package org.briarproject.bramble.identity
import org.briarproject.bramble.api.identity.Author import org.briarproject.bramble.api.identity.Author
import org.briarproject.bramble.api.identity.AuthorInfo
import org.briarproject.briar.headless.json.JsonDict import org.briarproject.briar.headless.json.JsonDict
fun Author.output() = JsonDict( fun Author.output() = JsonDict(
@@ -10,4 +11,4 @@ fun Author.output() = JsonDict(
"publicKey" to publicKey "publicKey" to publicKey
) )
fun Author.Status.output() = name.toLowerCase() fun AuthorInfo.Status.output() = name.toLowerCase()

View File

@@ -8,7 +8,7 @@ import org.briarproject.briar.headless.json.JsonDict
internal fun BlogPostHeader.output(text: String) = JsonDict( internal fun BlogPostHeader.output(text: String) = JsonDict(
"text" to text, "text" to text,
"author" to author.output(), "author" to author.output(),
"authorStatus" to authorStatus.output(), "authorStatus" to authorInfo.status.output(),
"type" to type.output(), "type" to type.output(),
"id" to id.bytes, "id" to id.bytes,
"parentId" to parentId?.bytes, "parentId" to parentId?.bytes,

View File

@@ -6,7 +6,8 @@ import io.mockk.Runs
import io.mockk.every import io.mockk.every
import io.mockk.just import io.mockk.just
import io.mockk.mockk import io.mockk.mockk
import org.briarproject.bramble.api.identity.Author.Status.OURSELVES import org.briarproject.bramble.api.identity.AuthorInfo
import org.briarproject.bramble.api.identity.AuthorInfo.Status.OURSELVES
import org.briarproject.bramble.api.sync.MessageId import org.briarproject.bramble.api.sync.MessageId
import org.briarproject.bramble.identity.output import org.briarproject.bramble.identity.output
import org.briarproject.bramble.util.StringUtils.getRandomString import org.briarproject.bramble.util.StringUtils.getRandomString
@@ -30,8 +31,16 @@ internal class BlogControllerTest : ControllerTest() {
private val rssFeed = false private val rssFeed = false
private val read = true private val read = true
private val header = BlogPostHeader( private val header = BlogPostHeader(
POST, group.id, message.id, parentId, message.timestamp, timestamp, author, OURSELVES, POST,
rssFeed, read group.id,
message.id,
parentId,
message.timestamp,
timestamp,
author,
AuthorInfo(OURSELVES),
rssFeed,
read
) )
@Test @Test