mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-12 10:49:06 +01:00
Code cleanup, added FIXMEs for bigger issues.
This commit is contained in:
@@ -21,7 +21,6 @@ import org.briarproject.api.sync.GroupId;
|
||||
import org.briarproject.api.sync.MessageId;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
@@ -38,8 +37,6 @@ public class BlogActivity extends BriarActivity implements BlogPostListener,
|
||||
static final String IS_NEW_BLOG = "briar.IS_NEW_BLOG";
|
||||
|
||||
private static final String BLOG_PAGER_ADAPTER = "briar.BLOG_PAGER_ADAPTER";
|
||||
private static final Logger LOG =
|
||||
Logger.getLogger(BlogActivity.class.getName());
|
||||
|
||||
private ProgressBar progressBar;
|
||||
private ViewPager pager;
|
||||
|
||||
@@ -7,14 +7,14 @@ import org.briarproject.android.controller.handler.ResultHandler;
|
||||
import org.briarproject.api.sync.GroupId;
|
||||
import org.briarproject.api.sync.MessageId;
|
||||
|
||||
import java.util.TreeSet;
|
||||
import java.util.SortedSet;
|
||||
|
||||
public interface BlogController extends ActivityLifecycleController {
|
||||
|
||||
void loadBlog(final GroupId groupId, final boolean reload,
|
||||
final ResultHandler<Boolean> resultHandler);
|
||||
void loadBlog(GroupId groupId, boolean reload,
|
||||
ResultHandler<Boolean> resultHandler);
|
||||
|
||||
TreeSet<BlogPostItem> getBlogPosts();
|
||||
SortedSet<BlogPostItem> getBlogPosts();
|
||||
|
||||
@Nullable
|
||||
BlogPostItem getBlogPost(MessageId postId);
|
||||
@@ -22,10 +22,10 @@ public interface BlogController extends ActivityLifecycleController {
|
||||
@Nullable
|
||||
MessageId getBlogPostId(int position);
|
||||
|
||||
void deleteBlog(final ResultHandler<Boolean> resultHandler);
|
||||
void deleteBlog(ResultHandler<Boolean> resultHandler);
|
||||
|
||||
interface BlogPostListener {
|
||||
void onBlogPostAdded(final BlogPostItem post, final boolean local);
|
||||
void onBlogPostAdded(BlogPostItem post, boolean local);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -19,6 +19,7 @@ import org.briarproject.api.sync.MessageId;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.SortedSet;
|
||||
import java.util.TreeSet;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
@@ -42,6 +43,7 @@ public class BlogControllerImpl extends DbControllerImpl
|
||||
|
||||
private volatile BlogPostListener listener;
|
||||
private volatile GroupId groupId = null;
|
||||
// FIXME: This collection isn't thread-safe, isn't updated atomically
|
||||
private volatile TreeSet<BlogPostItem> posts = null;
|
||||
|
||||
@Inject
|
||||
@@ -81,9 +83,11 @@ public class BlogControllerImpl extends DbControllerImpl
|
||||
LOG.info("New blog post added");
|
||||
if (posts == null) {
|
||||
LOG.info("Posts have not loaded, yet");
|
||||
// FIXME: Race condition, new post may not get loaded
|
||||
return;
|
||||
}
|
||||
final BlogPostHeader header = m.getHeader();
|
||||
// FIXME: Don't make blocking calls in event handlers
|
||||
try {
|
||||
final byte[] body = blogManager.getPostBody(header.getId());
|
||||
final BlogPostItem post = new BlogPostItem(header, body);
|
||||
@@ -112,7 +116,6 @@ public class BlogControllerImpl extends DbControllerImpl
|
||||
public void loadBlog(final GroupId g, final boolean reload,
|
||||
final ResultHandler<Boolean> resultHandler) {
|
||||
|
||||
LOG.info("Loading blog...");
|
||||
runOnDbThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
@@ -132,8 +135,7 @@ public class BlogControllerImpl extends DbControllerImpl
|
||||
posts.addAll(newPosts);
|
||||
long duration = System.currentTimeMillis() - now;
|
||||
if (LOG.isLoggable(INFO))
|
||||
LOG.info("Post header load took " + duration +
|
||||
" ms");
|
||||
LOG.info("Loading blog took " + duration + " ms");
|
||||
}
|
||||
resultHandler.onResult(true);
|
||||
} catch (DbException e) {
|
||||
@@ -147,7 +149,7 @@ public class BlogControllerImpl extends DbControllerImpl
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public TreeSet<BlogPostItem> getBlogPosts() {
|
||||
public SortedSet<BlogPostItem> getBlogPosts() {
|
||||
return posts;
|
||||
}
|
||||
|
||||
|
||||
@@ -4,7 +4,6 @@ import android.support.annotation.Nullable;
|
||||
|
||||
import org.briarproject.android.controller.ActivityLifecycleController;
|
||||
import org.briarproject.android.controller.handler.ResultHandler;
|
||||
import org.briarproject.android.controller.handler.UiResultHandler;
|
||||
import org.briarproject.api.forum.Forum;
|
||||
import org.briarproject.api.sync.GroupId;
|
||||
import org.briarproject.api.sync.MessageId;
|
||||
@@ -15,17 +14,25 @@ import java.util.List;
|
||||
public interface ForumController extends ActivityLifecycleController {
|
||||
|
||||
void loadForum(GroupId groupId, ResultHandler<Boolean> resultHandler);
|
||||
|
||||
@Nullable
|
||||
Forum getForum();
|
||||
|
||||
List<ForumEntry> getForumEntries();
|
||||
void unsubscribe(UiResultHandler<Boolean> resultHandler);
|
||||
|
||||
void unsubscribe(ResultHandler<Boolean> resultHandler);
|
||||
|
||||
void entryRead(ForumEntry forumEntry);
|
||||
|
||||
void entriesRead(Collection<ForumEntry> messageIds);
|
||||
|
||||
void createPost(byte[] body);
|
||||
|
||||
void createPost(byte[] body, MessageId parentId);
|
||||
|
||||
interface ForumPostListener {
|
||||
void addLocalEntry(int index, ForumEntry entry);
|
||||
|
||||
void addForeignEntry(int index, ForumEntry entry);
|
||||
}
|
||||
|
||||
|
||||
@@ -5,7 +5,6 @@ import android.support.annotation.Nullable;
|
||||
|
||||
import org.briarproject.android.controller.DbControllerImpl;
|
||||
import org.briarproject.android.controller.handler.ResultHandler;
|
||||
import org.briarproject.android.controller.handler.UiResultHandler;
|
||||
import org.briarproject.api.FormatException;
|
||||
import org.briarproject.api.clients.MessageTree;
|
||||
import org.briarproject.api.crypto.CryptoComponent;
|
||||
@@ -34,10 +33,10 @@ import java.security.GeneralSecurityException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Stack;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.Executor;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
@@ -69,11 +68,12 @@ public class ForumControllerImpl extends DbControllerImpl
|
||||
@Inject
|
||||
protected volatile IdentityManager identityManager;
|
||||
|
||||
private volatile MessageTree<ForumPostHeader> tree =
|
||||
new MessageTreeImpl<>();
|
||||
private volatile Map<MessageId, byte[]> bodyCache = new HashMap<>();
|
||||
private final Map<MessageId, byte[]> bodyCache = new ConcurrentHashMap<>();
|
||||
private final MessageTree<ForumPostHeader> tree = new MessageTreeImpl<>();
|
||||
|
||||
private volatile LocalAuthor localAuthor = null;
|
||||
private volatile Forum forum = null;
|
||||
// FIXME: This collection isn't thread-safe, isn't updated atomically
|
||||
private volatile List<ForumEntry> forumEntries = null;
|
||||
|
||||
private ForumPostListener listener;
|
||||
@@ -116,6 +116,7 @@ public class ForumControllerImpl extends DbControllerImpl
|
||||
ForumPostReceivedEvent pe = (ForumPostReceivedEvent) e;
|
||||
if (pe.getGroupId().equals(forum.getId())) {
|
||||
LOG.info("Forum Post received, adding...");
|
||||
// FIXME: Don't make blocking calls in event handlers
|
||||
addNewPost(pe.getForumPostHeader());
|
||||
}
|
||||
} else if (e instanceof GroupRemovedEvent) {
|
||||
@@ -272,9 +273,10 @@ public class ForumControllerImpl extends DbControllerImpl
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unsubscribe(final UiResultHandler<Boolean> resultHandler) {
|
||||
public void unsubscribe(final ResultHandler<Boolean> resultHandler) {
|
||||
if (forum == null) return;
|
||||
runOnDbThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
long now = System.currentTimeMillis();
|
||||
@@ -300,6 +302,7 @@ public class ForumControllerImpl extends DbControllerImpl
|
||||
@Override
|
||||
public void entriesRead(final Collection<ForumEntry> forumEntries) {
|
||||
runOnDbThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
long now = System.currentTimeMillis();
|
||||
@@ -325,6 +328,7 @@ public class ForumControllerImpl extends DbControllerImpl
|
||||
@Override
|
||||
public void createPost(final byte[] body, final MessageId parentId) {
|
||||
cryptoExecutor.execute(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
long timestamp = System.currentTimeMillis();
|
||||
long newestTimeStamp = 0;
|
||||
@@ -353,6 +357,7 @@ public class ForumControllerImpl extends DbControllerImpl
|
||||
}
|
||||
bodyCache.put(p.getMessage().getId(), body);
|
||||
storePost(p);
|
||||
// FIXME: Don't make DB calls on the crypto executor
|
||||
addNewPost(p);
|
||||
}
|
||||
});
|
||||
@@ -378,6 +383,7 @@ public class ForumControllerImpl extends DbControllerImpl
|
||||
|
||||
private void storePost(final ForumPost p) {
|
||||
runOnDbThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
long now = System.currentTimeMillis();
|
||||
|
||||
Reference in New Issue
Block a user