Addressing second round of review issues

This commit is contained in:
Torsten Grote
2016-10-19 09:03:48 -02:00
parent 0523c4e718
commit 8f882dc910
26 changed files with 167 additions and 164 deletions

View File

@@ -25,7 +25,6 @@ import org.briarproject.api.sync.Group;
import org.briarproject.api.sync.GroupId;
import org.briarproject.api.sync.Message;
import org.briarproject.api.sync.MessageId;
import org.briarproject.api.system.Clock;
import org.briarproject.clients.BdfIncomingMessageHook;
import org.briarproject.util.StringUtils;
import org.jetbrains.annotations.Nullable;
@@ -64,20 +63,17 @@ class ForumManagerImpl extends BdfIncomingMessageHook implements ForumManager {
private final IdentityManager identityManager;
private final ForumFactory forumFactory;
private final ForumPostFactory forumPostFactory;
private final Clock clock;
private final List<RemoveForumHook> removeHooks;
@Inject
ForumManagerImpl(DatabaseComponent db, IdentityManager identityManager,
ClientHelper clientHelper, MetadataParser metadataParser,
ForumFactory forumFactory, ForumPostFactory forumPostFactory,
Clock clock) {
ForumFactory forumFactory, ForumPostFactory forumPostFactory) {
super(db, clientHelper, metadataParser);
this.identityManager = identityManager;
this.forumFactory = forumFactory;
this.forumPostFactory = forumPostFactory;
this.clock = clock;
removeHooks = new CopyOnWriteArrayList<RemoveForumHook>();
}
@@ -129,23 +125,9 @@ class ForumManagerImpl extends BdfIncomingMessageHook implements ForumManager {
}
@Override
public ForumPost createLocalPost(final GroupId groupId,
final String body, final @Nullable MessageId parentId)
throws DbException {
LocalAuthor author;
GroupCount count;
Transaction txn = db.startTransaction(true);
try {
author = identityManager.getLocalAuthor(txn);
count = getGroupCount(txn, groupId);
txn.setComplete();
} finally {
db.endTransaction(txn);
}
long timestamp = clock.currentTimeMillis();
timestamp = Math.max(timestamp, count.getLatestMsgTime());
public ForumPost createLocalPost(final GroupId groupId, final String body,
final long timestamp, final @Nullable MessageId parentId,
final LocalAuthor author) {
ForumPost p;
try {
p = forumPostFactory

View File

@@ -77,16 +77,13 @@ public class PrivateGroupManagerImpl extends BdfIncomingMessageHook implements
@Override
public GroupMessage createLocalMessage(GroupId groupId, String body,
@Nullable MessageId parentId) throws DbException {
long timestamp = clock.currentTimeMillis();
LocalAuthor author = identityManager.getLocalAuthor();
long timestamp, @Nullable MessageId parentId, LocalAuthor author) {
try {
return groupMessageFactory
.createGroupMessage(groupId, timestamp, parentId, author,
body);
} catch (FormatException e) {
throw new DbException(e);
throw new RuntimeException(e);
} catch (GeneralSecurityException e) {
throw new RuntimeException(e);
}

View File

@@ -86,4 +86,11 @@ public class StringUtils {
public static String trim(String s) {
return s.trim();
}
/**
* Returns true if the string is longer than maxLength
*/
public static boolean isTooLong(String s, int maxLength) {
return toUtf8(s).length > maxLength;
}
}