mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-13 03:09:04 +01:00
Posting group messages takes previous message into account
This commit is contained in:
@@ -3,8 +3,8 @@ package org.briarproject.android.privategroup.conversation;
|
||||
import android.support.annotation.Nullable;
|
||||
|
||||
import org.briarproject.android.api.AndroidNotificationManager;
|
||||
import org.briarproject.android.controller.handler.ResultExceptionHandler;
|
||||
import org.briarproject.android.threaded.ThreadListControllerImpl;
|
||||
import org.briarproject.api.clients.MessageTracker.GroupCount;
|
||||
import org.briarproject.api.crypto.CryptoExecutor;
|
||||
import org.briarproject.api.db.DatabaseExecutor;
|
||||
import org.briarproject.api.db.DbException;
|
||||
@@ -28,6 +28,9 @@ import java.util.logging.Logger;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import static java.lang.Math.max;
|
||||
import static java.util.logging.Level.WARNING;
|
||||
|
||||
public class GroupControllerImpl extends
|
||||
ThreadListControllerImpl<PrivateGroup, GroupMessageItem, GroupMessageHeader, GroupMessage>
|
||||
implements GroupController {
|
||||
@@ -44,9 +47,9 @@ public class GroupControllerImpl extends
|
||||
@CryptoExecutor Executor cryptoExecutor,
|
||||
PrivateGroupManager privateGroupManager,
|
||||
GroupMessageFactory groupMessageFactory, EventBus eventBus,
|
||||
AndroidNotificationManager notificationManager, Clock clock) {
|
||||
Clock clock, AndroidNotificationManager notificationManager) {
|
||||
super(dbExecutor, lifecycleManager, identityManager, cryptoExecutor,
|
||||
eventBus, notificationManager, clock);
|
||||
eventBus, clock, notificationManager);
|
||||
this.privateGroupManager = privateGroupManager;
|
||||
this.groupMessageFactory = groupMessageFactory;
|
||||
}
|
||||
@@ -97,18 +100,52 @@ public class GroupControllerImpl extends
|
||||
}
|
||||
|
||||
@Override
|
||||
protected long getLatestTimestamp() throws DbException {
|
||||
GroupCount count = privateGroupManager.getGroupCount(getGroupId());
|
||||
return count.getLatestMsgTime();
|
||||
public void createAndStoreMessage(final String body,
|
||||
@Nullable final GroupMessageItem parentItem,
|
||||
final ResultExceptionHandler<GroupMessageItem, DbException> handler) {
|
||||
runOnDbThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
LocalAuthor author = identityManager.getLocalAuthor();
|
||||
MessageId parentId = null;
|
||||
MessageId previousMsgId =
|
||||
privateGroupManager.getPreviousMsgId(getGroupId());
|
||||
// timestamp must be greater than the timestamps
|
||||
// of the member's previous message...
|
||||
long timestamp = privateGroupManager
|
||||
.getMessageTimestamp(previousMsgId);
|
||||
// ...and the parent post, if any
|
||||
if (parentItem != null) {
|
||||
timestamp = max(parentItem.getTimestamp(), timestamp);
|
||||
parentId = parentItem.getId();
|
||||
}
|
||||
timestamp = max(clock.currentTimeMillis(), timestamp + 1);
|
||||
createMessage(body, timestamp, parentId, author,
|
||||
previousMsgId, handler);
|
||||
} catch (DbException e) {
|
||||
if (LOG.isLoggable(WARNING))
|
||||
LOG.log(WARNING, e.toString(), e);
|
||||
handler.onException(e);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
protected GroupMessage createLocalMessage(String body, long timestamp,
|
||||
@Nullable MessageId parentId, LocalAuthor author) {
|
||||
MessageId previousMsgId = null; // TODO
|
||||
return groupMessageFactory
|
||||
.createGroupMessage(getGroupId(), timestamp, parentId,
|
||||
author, body, previousMsgId);
|
||||
private void createMessage(final String body, final long timestamp,
|
||||
final @Nullable MessageId parentId, final LocalAuthor author,
|
||||
final MessageId previousMsgId,
|
||||
final ResultExceptionHandler<GroupMessageItem, DbException> handler) {
|
||||
cryptoExecutor.execute(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
LOG.info("Creating group message...");
|
||||
GroupMessage msg = groupMessageFactory
|
||||
.createGroupMessage(getGroupId(), timestamp,
|
||||
parentId, author, body, previousMsgId);
|
||||
storePost(msg, body, handler);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user