Creator automatically joins the group after creating it

This commit is contained in:
Torsten Grote
2016-10-20 12:45:56 -02:00
parent e06726b2f9
commit 4f4f1956eb
7 changed files with 178 additions and 51 deletions

View File

@@ -34,6 +34,8 @@ import org.briarproject.api.messaging.MessagingManager;
import org.briarproject.api.messaging.PrivateMessageFactory;
import org.briarproject.api.plugins.ConnectionRegistry;
import org.briarproject.api.plugins.PluginManager;
import org.briarproject.api.privategroup.GroupMessageFactory;
import org.briarproject.api.privategroup.PrivateGroupFactory;
import org.briarproject.api.privategroup.PrivateGroupManager;
import org.briarproject.api.privategroup.invitation.GroupInvitationManager;
import org.briarproject.api.settings.SettingsManager;
@@ -99,6 +101,10 @@ public interface AndroidComponent extends CoreEagerSingletons {
GroupInvitationManager groupInvitationManager();
PrivateGroupFactory privateGroupFactory();
GroupMessageFactory groupMessageFactory();
ForumManager forumManager();
ForumSharingManager forumSharingManager();

View File

@@ -15,6 +15,7 @@ import org.briarproject.api.identity.IdentityManager;
import org.briarproject.api.identity.LocalAuthor;
import org.briarproject.api.lifecycle.LifecycleManager;
import org.briarproject.api.privategroup.GroupMessage;
import org.briarproject.api.privategroup.GroupMessageFactory;
import org.briarproject.api.privategroup.GroupMessageHeader;
import org.briarproject.api.privategroup.PrivateGroup;
import org.briarproject.api.privategroup.PrivateGroupManager;
@@ -35,16 +36,19 @@ public class GroupControllerImpl extends
Logger.getLogger(GroupControllerImpl.class.getName());
private final PrivateGroupManager privateGroupManager;
private final GroupMessageFactory groupMessageFactory;
@Inject
GroupControllerImpl(@DatabaseExecutor Executor dbExecutor,
LifecycleManager lifecycleManager, IdentityManager identityManager,
@CryptoExecutor Executor cryptoExecutor,
PrivateGroupManager privateGroupManager, EventBus eventBus,
PrivateGroupManager privateGroupManager,
GroupMessageFactory groupMessageFactory, EventBus eventBus,
AndroidNotificationManager notificationManager, Clock clock) {
super(dbExecutor, lifecycleManager, identityManager, cryptoExecutor,
eventBus, notificationManager, clock);
this.privateGroupManager = privateGroupManager;
this.groupMessageFactory = groupMessageFactory;
}
@Override
@@ -101,8 +105,10 @@ public class GroupControllerImpl extends
@Override
protected GroupMessage createLocalMessage(String body, long timestamp,
@Nullable MessageId parentId, LocalAuthor author) {
return privateGroupManager.createLocalMessage(getGroupId(), body,
timestamp, parentId, author);
MessageId previousMsgId = null; // TODO
return groupMessageFactory
.createGroupMessage(getGroupId(), timestamp, parentId,
author, body, previousMsgId);
}
@Override

View File

@@ -3,11 +3,19 @@ package org.briarproject.android.privategroup.creation;
import org.briarproject.android.controller.DbControllerImpl;
import org.briarproject.android.controller.handler.ResultExceptionHandler;
import org.briarproject.api.contact.ContactId;
import org.briarproject.api.crypto.CryptoExecutor;
import org.briarproject.api.db.DatabaseExecutor;
import org.briarproject.api.db.DbException;
import org.briarproject.api.identity.IdentityManager;
import org.briarproject.api.identity.LocalAuthor;
import org.briarproject.api.lifecycle.LifecycleManager;
import org.briarproject.api.privategroup.GroupMessage;
import org.briarproject.api.privategroup.GroupMessageFactory;
import org.briarproject.api.privategroup.PrivateGroup;
import org.briarproject.api.privategroup.PrivateGroupFactory;
import org.briarproject.api.privategroup.PrivateGroupManager;
import org.briarproject.api.sync.GroupId;
import org.briarproject.api.system.Clock;
import java.util.Collection;
import java.util.concurrent.Executor;
@@ -23,25 +31,81 @@ public class CreateGroupControllerImpl extends DbControllerImpl
private static final Logger LOG =
Logger.getLogger(CreateGroupControllerImpl.class.getName());
private final IdentityManager identityManager;
private final PrivateGroupFactory groupFactory;
private final GroupMessageFactory groupMessageFactory;
private final PrivateGroupManager groupManager;
private final Clock clock;
@CryptoExecutor
private final Executor cryptoExecutor;
@Inject
CreateGroupControllerImpl(@DatabaseExecutor Executor dbExecutor,
LifecycleManager lifecycleManager,
PrivateGroupManager groupManager) {
@CryptoExecutor Executor cryptoExecutor,
LifecycleManager lifecycleManager, IdentityManager identityManager,
PrivateGroupFactory groupFactory,
GroupMessageFactory groupMessageFactory,
PrivateGroupManager groupManager, Clock clock) {
super(dbExecutor, lifecycleManager);
this.identityManager = identityManager;
this.groupFactory = groupFactory;
this.groupMessageFactory = groupMessageFactory;
this.groupManager = groupManager;
this.clock = clock;
this.cryptoExecutor = cryptoExecutor;
}
@Override
public void createGroup(final String name,
final ResultExceptionHandler<GroupId, DbException> handler) {
runOnDbThread(new Runnable() {
@Override
public void run() {
try {
LocalAuthor author = identityManager.getLocalAuthor();
createGroupAndMessages(author, name, handler);
} catch (DbException e) {
if (LOG.isLoggable(WARNING))
LOG.log(WARNING, e.toString(), e);
handler.onException(e);
}
}
});
}
private void createGroupAndMessages(final LocalAuthor author,
final String name,
final ResultExceptionHandler<GroupId, DbException> handler) {
cryptoExecutor.execute(new Runnable() {
@Override
public void run() {
LOG.info("Creating group...");
PrivateGroup group =
groupFactory.createPrivateGroup(name, author);
LOG.info("Creating new member announcement...");
GroupMessage newMemberMsg = groupMessageFactory
.createNewMemberMessage(group.getId(),
clock.currentTimeMillis(), author, author);
LOG.info("Creating new join announcement...");
GroupMessage joinMsg = groupMessageFactory
.createJoinMessage(group.getId(),
newMemberMsg.getMessage().getTimestamp(),
author, newMemberMsg.getMessage().getId());
storeGroup(group, newMemberMsg, joinMsg, handler);
}
});
}
private void storeGroup(final PrivateGroup group,
final GroupMessage newMemberMsg, final GroupMessage joinMsg,
final ResultExceptionHandler<GroupId, DbException> handler) {
runOnDbThread(new Runnable() {
@Override
public void run() {
LOG.info("Adding group to database...");
try {
handler.onResult(groupManager.addPrivateGroup(name));
groupManager.addPrivateGroup(group, newMemberMsg, joinMsg);
handler.onResult(group.getId());
} catch (DbException e) {
if (LOG.isLoggable(WARNING))
LOG.log(WARNING, e.toString(), e);

View File

@@ -44,6 +44,7 @@ public abstract class ThreadListControllerImpl<G extends NamedGroup, I extends T
Logger.getLogger(ThreadListControllerImpl.class.getName());
private final IdentityManager identityManager;
@CryptoExecutor
private final Executor cryptoExecutor;
protected final AndroidNotificationManager notificationManager;
private final EventBus eventBus;