diff --git a/briar-api/src/org/briarproject/api/privategroup/PrivateGroupFactory.java b/briar-api/src/org/briarproject/api/privategroup/PrivateGroupFactory.java index 492eabc866df02bc8be162aa02c79165ab6f717f..6a27552fa286c13c9c7e12c683c7af44707e18db 100644 --- a/briar-api/src/org/briarproject/api/privategroup/PrivateGroupFactory.java +++ b/briar-api/src/org/briarproject/api/privategroup/PrivateGroupFactory.java @@ -1,6 +1,8 @@ package org.briarproject.api.privategroup; +import org.briarproject.api.FormatException; import org.briarproject.api.identity.Author; +import org.briarproject.api.sync.Group; import org.jetbrains.annotations.NotNull; public interface PrivateGroupFactory { @@ -17,4 +19,9 @@ public interface PrivateGroupFactory { @NotNull PrivateGroup createPrivateGroup(String name, Author author, byte[] salt); + /** + * Parses a group and returns the corresponding PrivateGroup. + */ + PrivateGroup parsePrivateGroup(Group group) throws FormatException; + } diff --git a/briar-core/src/org/briarproject/privategroup/PrivateGroupFactoryImpl.java b/briar-core/src/org/briarproject/privategroup/PrivateGroupFactoryImpl.java index 429fd56b5f34383f80ae8f308543581cbdc46566..7389f2fd691718ee4c84ae88b8f505df97d79b98 100644 --- a/briar-core/src/org/briarproject/privategroup/PrivateGroupFactoryImpl.java +++ b/briar-core/src/org/briarproject/privategroup/PrivateGroupFactoryImpl.java @@ -4,6 +4,7 @@ import org.briarproject.api.FormatException; import org.briarproject.api.clients.ClientHelper; import org.briarproject.api.data.BdfList; import org.briarproject.api.identity.Author; +import org.briarproject.api.identity.AuthorFactory; import org.briarproject.api.privategroup.PrivateGroup; import org.briarproject.api.privategroup.PrivateGroupFactory; import org.briarproject.api.sync.Group; @@ -22,14 +23,17 @@ class PrivateGroupFactoryImpl implements PrivateGroupFactory { private final GroupFactory groupFactory; private final ClientHelper clientHelper; + private final AuthorFactory authorFactory; private final SecureRandom random; @Inject PrivateGroupFactoryImpl(GroupFactory groupFactory, - ClientHelper clientHelper, SecureRandom random) { + ClientHelper clientHelper, AuthorFactory authorFactory, + SecureRandom random) { this.groupFactory = groupFactory; this.clientHelper = clientHelper; + this.authorFactory = authorFactory; this.random = random; } @@ -66,4 +70,13 @@ class PrivateGroupFactoryImpl implements PrivateGroupFactory { } } + @Override + public PrivateGroup parsePrivateGroup(Group group) throws FormatException { + byte[] descriptor = group.getDescriptor(); + BdfList list = clientHelper.toList(descriptor); + Author a = + authorFactory.createAuthor(list.getString(1), list.getRaw(2)); + return new PrivateGroup(group, list.getString(0), a, list.getRaw(3)); + } + } diff --git a/briar-core/src/org/briarproject/privategroup/PrivateGroupManagerImpl.java b/briar-core/src/org/briarproject/privategroup/PrivateGroupManagerImpl.java index 3c9f5814bc580c50a3bb1822855000993d613e82..d9483d33602d7b67dc9955f87be27bf573b4f538 100644 --- a/briar-core/src/org/briarproject/privategroup/PrivateGroupManagerImpl.java +++ b/briar-core/src/org/briarproject/privategroup/PrivateGroupManagerImpl.java @@ -8,7 +8,6 @@ import org.briarproject.api.data.MetadataParser; import org.briarproject.api.db.DatabaseComponent; import org.briarproject.api.db.DbException; import org.briarproject.api.db.Transaction; -import org.briarproject.api.identity.Author; import org.briarproject.api.identity.IdentityManager; import org.briarproject.api.privategroup.GroupMessage; import org.briarproject.api.privategroup.GroupMessageHeader; @@ -16,6 +15,7 @@ import org.briarproject.api.privategroup.PrivateGroup; import org.briarproject.api.privategroup.PrivateGroupFactory; import org.briarproject.api.privategroup.PrivateGroupManager; import org.briarproject.api.sync.ClientId; +import org.briarproject.api.sync.Group; import org.briarproject.api.sync.GroupId; import org.briarproject.api.sync.Message; import org.briarproject.api.sync.MessageId; @@ -81,16 +81,27 @@ public class PrivateGroupManagerImpl extends BdfIncomingMessageHook implements @NotNull @Override public PrivateGroup getPrivateGroup(GroupId g) throws DbException { - Author a = identityManager.getLocalAuthor(); - return privateGroupFactory.createPrivateGroup("todo", a); + PrivateGroup privateGroup; + Transaction txn = db.startTransaction(true); + try { + privateGroup = getPrivateGroup(txn, g); + txn.setComplete(); + } finally { + db.endTransaction(txn); + } + return privateGroup; } @NotNull @Override public PrivateGroup getPrivateGroup(Transaction txn, GroupId g) throws DbException { - Author a = identityManager.getLocalAuthor(txn); - return privateGroupFactory.createPrivateGroup("todo", a); + try { + Group group = db.getGroup(txn, g); + return privateGroupFactory.parsePrivateGroup(group); + } catch (FormatException e) { + throw new DbException(e); + } } @NotNull