mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-15 20:29:52 +01:00
Facade for forum post headers. #172
This commit is contained in:
@@ -28,9 +28,9 @@ import org.briarproject.api.event.MessageAddedEvent;
|
|||||||
import org.briarproject.api.event.SubscriptionRemovedEvent;
|
import org.briarproject.api.event.SubscriptionRemovedEvent;
|
||||||
import org.briarproject.api.forum.Forum;
|
import org.briarproject.api.forum.Forum;
|
||||||
import org.briarproject.api.forum.ForumManager;
|
import org.briarproject.api.forum.ForumManager;
|
||||||
|
import org.briarproject.api.forum.ForumPostHeader;
|
||||||
import org.briarproject.api.identity.Author;
|
import org.briarproject.api.identity.Author;
|
||||||
import org.briarproject.api.sync.GroupId;
|
import org.briarproject.api.sync.GroupId;
|
||||||
import org.briarproject.api.sync.MessageHeader;
|
|
||||||
import org.briarproject.api.sync.MessageId;
|
import org.briarproject.api.sync.MessageId;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@@ -180,8 +180,8 @@ OnClickListener, OnItemClickListener {
|
|||||||
public void run() {
|
public void run() {
|
||||||
try {
|
try {
|
||||||
long now = System.currentTimeMillis();
|
long now = System.currentTimeMillis();
|
||||||
Collection<MessageHeader> headers =
|
Collection<ForumPostHeader> headers =
|
||||||
forumManager.getMessageHeaders(groupId);
|
forumManager.getPostHeaders(groupId);
|
||||||
long duration = System.currentTimeMillis() - now;
|
long duration = System.currentTimeMillis() - now;
|
||||||
if (LOG.isLoggable(INFO))
|
if (LOG.isLoggable(INFO))
|
||||||
LOG.info("Load took " + duration + " ms");
|
LOG.info("Load took " + duration + " ms");
|
||||||
@@ -196,7 +196,7 @@ OnClickListener, OnItemClickListener {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private void displayHeaders(final Collection<MessageHeader> headers) {
|
private void displayHeaders(final Collection<ForumPostHeader> headers) {
|
||||||
runOnUiThread(new Runnable() {
|
runOnUiThread(new Runnable() {
|
||||||
public void run() {
|
public void run() {
|
||||||
loading.setVisibility(GONE);
|
loading.setVisibility(GONE);
|
||||||
@@ -207,10 +207,10 @@ OnClickListener, OnItemClickListener {
|
|||||||
} else {
|
} else {
|
||||||
empty.setVisibility(GONE);
|
empty.setVisibility(GONE);
|
||||||
list.setVisibility(VISIBLE);
|
list.setVisibility(VISIBLE);
|
||||||
for (MessageHeader h : headers) {
|
for (ForumPostHeader h : headers) {
|
||||||
ForumItem item = new ForumItem(h);
|
ForumItem item = new ForumItem(h);
|
||||||
byte[] body = bodyCache.get(h.getId());
|
byte[] body = bodyCache.get(h.getId());
|
||||||
if (body == null) loadMessageBody(h);
|
if (body == null) loadPostBody(h);
|
||||||
else item.setBody(body);
|
else item.setBody(body);
|
||||||
adapter.add(item);
|
adapter.add(item);
|
||||||
}
|
}
|
||||||
@@ -223,16 +223,16 @@ OnClickListener, OnItemClickListener {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private void loadMessageBody(final MessageHeader h) {
|
private void loadPostBody(final ForumPostHeader h) {
|
||||||
runOnDbThread(new Runnable() {
|
runOnDbThread(new Runnable() {
|
||||||
public void run() {
|
public void run() {
|
||||||
try {
|
try {
|
||||||
long now = System.currentTimeMillis();
|
long now = System.currentTimeMillis();
|
||||||
byte[] body = forumManager.getMessageBody(h.getId());
|
byte[] body = forumManager.getPostBody(h.getId());
|
||||||
long duration = System.currentTimeMillis() - now;
|
long duration = System.currentTimeMillis() - now;
|
||||||
if (LOG.isLoggable(INFO))
|
if (LOG.isLoggable(INFO))
|
||||||
LOG.info("Loading message took " + duration + " ms");
|
LOG.info("Loading message took " + duration + " ms");
|
||||||
displayMessage(h.getId(), body);
|
displayPost(h.getId(), body);
|
||||||
} catch (NoSuchMessageException e) {
|
} catch (NoSuchMessageException e) {
|
||||||
// The item will be removed when we get the event
|
// The item will be removed when we get the event
|
||||||
} catch (DbException e) {
|
} catch (DbException e) {
|
||||||
@@ -243,7 +243,7 @@ OnClickListener, OnItemClickListener {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private void displayMessage(final MessageId m, final byte[] body) {
|
private void displayPost(final MessageId m, final byte[] body) {
|
||||||
runOnUiThread(new Runnable() {
|
runOnUiThread(new Runnable() {
|
||||||
public void run() {
|
public void run() {
|
||||||
bodyCache.put(m, body);
|
bodyCache.put(m, body);
|
||||||
@@ -268,7 +268,7 @@ OnClickListener, OnItemClickListener {
|
|||||||
if (request == REQUEST_READ && result == RESULT_PREV_NEXT) {
|
if (request == REQUEST_READ && result == RESULT_PREV_NEXT) {
|
||||||
int position = data.getIntExtra("briar.POSITION", -1);
|
int position = data.getIntExtra("briar.POSITION", -1);
|
||||||
if (position >= 0 && position < adapter.getCount())
|
if (position >= 0 && position < adapter.getCount())
|
||||||
displayMessage(position);
|
displayPost(position);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -276,24 +276,24 @@ OnClickListener, OnItemClickListener {
|
|||||||
public void onPause() {
|
public void onPause() {
|
||||||
super.onPause();
|
super.onPause();
|
||||||
eventBus.removeListener(this);
|
eventBus.removeListener(this);
|
||||||
if (isFinishing()) markMessagesRead();
|
if (isFinishing()) markPostsRead();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void markMessagesRead() {
|
private void markPostsRead() {
|
||||||
notificationManager.clearForumPostNotification(groupId);
|
notificationManager.clearForumPostNotification(groupId);
|
||||||
List<MessageId> unread = new ArrayList<MessageId>();
|
List<MessageId> unread = new ArrayList<MessageId>();
|
||||||
int count = adapter.getCount();
|
int count = adapter.getCount();
|
||||||
for (int i = 0; i < count; i++) {
|
for (int i = 0; i < count; i++) {
|
||||||
MessageHeader h = adapter.getItem(i).getHeader();
|
ForumPostHeader h = adapter.getItem(i).getHeader();
|
||||||
if (!h.isRead()) unread.add(h.getId());
|
if (!h.isRead()) unread.add(h.getId());
|
||||||
}
|
}
|
||||||
if (unread.isEmpty()) return;
|
if (unread.isEmpty()) return;
|
||||||
if (LOG.isLoggable(INFO))
|
if (LOG.isLoggable(INFO))
|
||||||
LOG.info("Marking " + unread.size() + " messages read");
|
LOG.info("Marking " + unread.size() + " posts read");
|
||||||
markMessagesRead(Collections.unmodifiableList(unread));
|
markPostsRead(Collections.unmodifiableList(unread));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void markMessagesRead(final Collection<MessageId> unread) {
|
private void markPostsRead(final Collection<MessageId> unread) {
|
||||||
runOnDbThread(new Runnable() {
|
runOnDbThread(new Runnable() {
|
||||||
public void run() {
|
public void run() {
|
||||||
try {
|
try {
|
||||||
@@ -331,7 +331,7 @@ OnClickListener, OnItemClickListener {
|
|||||||
Intent i = new Intent(this, WriteForumPostActivity.class);
|
Intent i = new Intent(this, WriteForumPostActivity.class);
|
||||||
i.putExtra("briar.GROUP_ID", groupId.getBytes());
|
i.putExtra("briar.GROUP_ID", groupId.getBytes());
|
||||||
i.putExtra("briar.FORUM_NAME", forum.getName());
|
i.putExtra("briar.FORUM_NAME", forum.getName());
|
||||||
i.putExtra("briar.MIN_TIMESTAMP", getMinTimestampForNewMessage());
|
i.putExtra("briar.MIN_TIMESTAMP", getMinTimestampForNewPost());
|
||||||
startActivity(i);
|
startActivity(i);
|
||||||
} else if (view == shareButton) {
|
} else if (view == shareButton) {
|
||||||
Intent i = new Intent(this, ShareForumActivity.class);
|
Intent i = new Intent(this, ShareForumActivity.class);
|
||||||
@@ -341,8 +341,8 @@ OnClickListener, OnItemClickListener {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private long getMinTimestampForNewMessage() {
|
private long getMinTimestampForNewPost() {
|
||||||
// Don't use an earlier timestamp than the newest message
|
// Don't use an earlier timestamp than the newest post
|
||||||
long timestamp = 0;
|
long timestamp = 0;
|
||||||
int count = adapter.getCount();
|
int count = adapter.getCount();
|
||||||
for (int i = 0; i < count; i++) {
|
for (int i = 0; i < count; i++) {
|
||||||
@@ -354,21 +354,21 @@ OnClickListener, OnItemClickListener {
|
|||||||
|
|
||||||
public void onItemClick(AdapterView<?> parent, View view, int position,
|
public void onItemClick(AdapterView<?> parent, View view, int position,
|
||||||
long id) {
|
long id) {
|
||||||
displayMessage(position);
|
displayPost(position);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void displayMessage(int position) {
|
private void displayPost(int position) {
|
||||||
MessageHeader item = adapter.getItem(position).getHeader();
|
ForumPostHeader header = adapter.getItem(position).getHeader();
|
||||||
Intent i = new Intent(this, ReadForumPostActivity.class);
|
Intent i = new Intent(this, ReadForumPostActivity.class);
|
||||||
i.putExtra("briar.GROUP_ID", groupId.getBytes());
|
i.putExtra("briar.GROUP_ID", groupId.getBytes());
|
||||||
i.putExtra("briar.FORUM_NAME", forum.getName());
|
i.putExtra("briar.FORUM_NAME", forum.getName());
|
||||||
i.putExtra("briar.MESSAGE_ID", item.getId().getBytes());
|
i.putExtra("briar.MESSAGE_ID", header.getId().getBytes());
|
||||||
Author author = item.getAuthor();
|
Author author = header.getAuthor();
|
||||||
if (author != null) i.putExtra("briar.AUTHOR_NAME", author.getName());
|
if (author != null) i.putExtra("briar.AUTHOR_NAME", author.getName());
|
||||||
i.putExtra("briar.AUTHOR_STATUS", item.getAuthorStatus().name());
|
i.putExtra("briar.AUTHOR_STATUS", header.getAuthorStatus().name());
|
||||||
i.putExtra("briar.CONTENT_TYPE", item.getContentType());
|
i.putExtra("briar.CONTENT_TYPE", header.getContentType());
|
||||||
i.putExtra("briar.TIMESTAMP", item.getTimestamp());
|
i.putExtra("briar.TIMESTAMP", header.getTimestamp());
|
||||||
i.putExtra("briar.MIN_TIMESTAMP", getMinTimestampForNewMessage());
|
i.putExtra("briar.MIN_TIMESTAMP", getMinTimestampForNewPost());
|
||||||
i.putExtra("briar.POSITION", position);
|
i.putExtra("briar.POSITION", position);
|
||||||
startActivityForResult(i, REQUEST_READ);
|
startActivityForResult(i, REQUEST_READ);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,8 +13,8 @@ import android.widget.TextView;
|
|||||||
import org.briarproject.R;
|
import org.briarproject.R;
|
||||||
import org.briarproject.android.util.AuthorView;
|
import org.briarproject.android.util.AuthorView;
|
||||||
import org.briarproject.android.util.LayoutUtils;
|
import org.briarproject.android.util.LayoutUtils;
|
||||||
|
import org.briarproject.api.forum.ForumPostHeader;
|
||||||
import org.briarproject.api.identity.Author;
|
import org.briarproject.api.identity.Author;
|
||||||
import org.briarproject.api.sync.MessageHeader;
|
|
||||||
import org.briarproject.util.StringUtils;
|
import org.briarproject.util.StringUtils;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@@ -38,7 +38,7 @@ class ForumAdapter extends ArrayAdapter<ForumItem> {
|
|||||||
@Override
|
@Override
|
||||||
public View getView(int position, View convertView, ViewGroup parent) {
|
public View getView(int position, View convertView, ViewGroup parent) {
|
||||||
ForumItem item = getItem(position);
|
ForumItem item = getItem(position);
|
||||||
MessageHeader header = item.getHeader();
|
ForumPostHeader header = item.getHeader();
|
||||||
Context ctx = getContext();
|
Context ctx = getContext();
|
||||||
Resources res = ctx.getResources();
|
Resources res = ctx.getResources();
|
||||||
|
|
||||||
|
|||||||
@@ -1,19 +1,19 @@
|
|||||||
package org.briarproject.android.forum;
|
package org.briarproject.android.forum;
|
||||||
|
|
||||||
import org.briarproject.api.sync.MessageHeader;
|
import org.briarproject.api.forum.ForumPostHeader;
|
||||||
|
|
||||||
// This class is not thread-safe
|
// This class is not thread-safe
|
||||||
class ForumItem {
|
class ForumItem {
|
||||||
|
|
||||||
private final MessageHeader header;
|
private final ForumPostHeader header;
|
||||||
private byte[] body;
|
private byte[] body;
|
||||||
|
|
||||||
ForumItem(MessageHeader header) {
|
ForumItem(ForumPostHeader header) {
|
||||||
this.header = header;
|
this.header = header;
|
||||||
body = null;
|
body = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
MessageHeader getHeader() {
|
ForumPostHeader getHeader() {
|
||||||
return header;
|
return header;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -34,9 +34,9 @@ import org.briarproject.api.event.SubscriptionAddedEvent;
|
|||||||
import org.briarproject.api.event.SubscriptionRemovedEvent;
|
import org.briarproject.api.event.SubscriptionRemovedEvent;
|
||||||
import org.briarproject.api.forum.Forum;
|
import org.briarproject.api.forum.Forum;
|
||||||
import org.briarproject.api.forum.ForumManager;
|
import org.briarproject.api.forum.ForumManager;
|
||||||
|
import org.briarproject.api.forum.ForumPostHeader;
|
||||||
import org.briarproject.api.sync.Group;
|
import org.briarproject.api.sync.Group;
|
||||||
import org.briarproject.api.sync.GroupId;
|
import org.briarproject.api.sync.GroupId;
|
||||||
import org.briarproject.api.sync.MessageHeader;
|
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
@@ -156,8 +156,8 @@ OnCreateContextMenuListener {
|
|||||||
long now = System.currentTimeMillis();
|
long now = System.currentTimeMillis();
|
||||||
for (Forum f : forumManager.getForums()) {
|
for (Forum f : forumManager.getForums()) {
|
||||||
try {
|
try {
|
||||||
Collection<MessageHeader> headers =
|
Collection<ForumPostHeader> headers =
|
||||||
forumManager.getMessageHeaders(f.getId());
|
forumManager.getPostHeaders(f.getId());
|
||||||
displayHeaders(f, headers);
|
displayHeaders(f, headers);
|
||||||
} catch (NoSuchSubscriptionException e) {
|
} catch (NoSuchSubscriptionException e) {
|
||||||
// Continue
|
// Continue
|
||||||
@@ -191,7 +191,7 @@ OnCreateContextMenuListener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void displayHeaders(final Forum f,
|
private void displayHeaders(final Forum f,
|
||||||
final Collection<MessageHeader> headers) {
|
final Collection<ForumPostHeader> headers) {
|
||||||
runOnUiThread(new Runnable() {
|
runOnUiThread(new Runnable() {
|
||||||
public void run() {
|
public void run() {
|
||||||
GroupId id = f.getId();
|
GroupId id = f.getId();
|
||||||
@@ -282,8 +282,8 @@ OnCreateContextMenuListener {
|
|||||||
try {
|
try {
|
||||||
long now = System.currentTimeMillis();
|
long now = System.currentTimeMillis();
|
||||||
Forum f = forumManager.getForum(g);
|
Forum f = forumManager.getForum(g);
|
||||||
Collection<MessageHeader> headers =
|
Collection<ForumPostHeader> headers =
|
||||||
forumManager.getMessageHeaders(g);
|
forumManager.getPostHeaders(g);
|
||||||
long duration = System.currentTimeMillis() - now;
|
long duration = System.currentTimeMillis() - now;
|
||||||
if (LOG.isLoggable(INFO))
|
if (LOG.isLoggable(INFO))
|
||||||
LOG.info("Partial load took " + duration + " ms");
|
LOG.info("Partial load took " + duration + " ms");
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
package org.briarproject.android.forum;
|
package org.briarproject.android.forum;
|
||||||
|
|
||||||
import org.briarproject.api.forum.Forum;
|
import org.briarproject.api.forum.Forum;
|
||||||
import org.briarproject.api.sync.MessageHeader;
|
import org.briarproject.api.forum.ForumPostHeader;
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
|
||||||
@@ -12,17 +12,17 @@ class ForumListItem {
|
|||||||
private final long timestamp;
|
private final long timestamp;
|
||||||
private final int unread;
|
private final int unread;
|
||||||
|
|
||||||
ForumListItem(Forum forum, Collection<MessageHeader> headers) {
|
ForumListItem(Forum forum, Collection<ForumPostHeader> headers) {
|
||||||
this.forum = forum;
|
this.forum = forum;
|
||||||
empty = headers.isEmpty();
|
empty = headers.isEmpty();
|
||||||
if (empty) {
|
if (empty) {
|
||||||
timestamp = 0;
|
timestamp = 0;
|
||||||
unread = 0;
|
unread = 0;
|
||||||
} else {
|
} else {
|
||||||
MessageHeader newest = null;
|
ForumPostHeader newest = null;
|
||||||
long timestamp = -1;
|
long timestamp = -1;
|
||||||
int unread = 0;
|
int unread = 0;
|
||||||
for (MessageHeader h : headers) {
|
for (ForumPostHeader h : headers) {
|
||||||
if (h.getTimestamp() > timestamp) {
|
if (h.getTimestamp() > timestamp) {
|
||||||
timestamp = h.getTimestamp();
|
timestamp = h.getTimestamp();
|
||||||
newest = h;
|
newest = h;
|
||||||
|
|||||||
@@ -120,7 +120,7 @@ implements OnClickListener {
|
|||||||
content = new TextView(this);
|
content = new TextView(this);
|
||||||
content.setPadding(pad, 0, pad, pad);
|
content.setPadding(pad, 0, pad, pad);
|
||||||
message.addView(content);
|
message.addView(content);
|
||||||
loadMessageBody();
|
loadPostBody();
|
||||||
}
|
}
|
||||||
scrollView.addView(message);
|
scrollView.addView(message);
|
||||||
layout.addView(scrollView);
|
layout.addView(scrollView);
|
||||||
@@ -161,10 +161,10 @@ implements OnClickListener {
|
|||||||
@Override
|
@Override
|
||||||
public void onPause() {
|
public void onPause() {
|
||||||
super.onPause();
|
super.onPause();
|
||||||
if (isFinishing()) markMessageRead();
|
if (isFinishing()) markPostRead();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void markMessageRead() {
|
private void markPostRead() {
|
||||||
runOnDbThread(new Runnable() {
|
runOnDbThread(new Runnable() {
|
||||||
public void run() {
|
public void run() {
|
||||||
try {
|
try {
|
||||||
@@ -181,16 +181,16 @@ implements OnClickListener {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private void loadMessageBody() {
|
private void loadPostBody() {
|
||||||
runOnDbThread(new Runnable() {
|
runOnDbThread(new Runnable() {
|
||||||
public void run() {
|
public void run() {
|
||||||
try {
|
try {
|
||||||
long now = System.currentTimeMillis();
|
long now = System.currentTimeMillis();
|
||||||
byte[] body = forumManager.getMessageBody(messageId);
|
byte[] body = forumManager.getPostBody(messageId);
|
||||||
long duration = System.currentTimeMillis() - now;
|
long duration = System.currentTimeMillis() - now;
|
||||||
if (LOG.isLoggable(INFO))
|
if (LOG.isLoggable(INFO))
|
||||||
LOG.info("Loading message took " + duration + " ms");
|
LOG.info("Loading post took " + duration + " ms");
|
||||||
displayMessageBody(StringUtils.fromUtf8(body));
|
displayPostBody(StringUtils.fromUtf8(body));
|
||||||
} catch (NoSuchMessageException e) {
|
} catch (NoSuchMessageException e) {
|
||||||
finishOnUiThread();
|
finishOnUiThread();
|
||||||
} catch (DbException e) {
|
} catch (DbException e) {
|
||||||
@@ -201,7 +201,7 @@ implements OnClickListener {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private void displayMessageBody(final String body) {
|
private void displayPostBody(final String body) {
|
||||||
runOnUiThread(new Runnable() {
|
runOnUiThread(new Runnable() {
|
||||||
public void run() {
|
public void run() {
|
||||||
content.setText(body);
|
content.setText(body);
|
||||||
|
|||||||
@@ -78,8 +78,8 @@ implements OnItemSelectedListener, OnClickListener {
|
|||||||
// Fields that are accessed from background threads must be volatile
|
// Fields that are accessed from background threads must be volatile
|
||||||
@Inject private volatile IdentityManager identityManager;
|
@Inject private volatile IdentityManager identityManager;
|
||||||
@Inject private volatile ForumManager forumManager;
|
@Inject private volatile ForumManager forumManager;
|
||||||
@Inject private volatile CryptoComponent crypto;
|
|
||||||
@Inject private volatile ForumPostFactory forumPostFactory;
|
@Inject private volatile ForumPostFactory forumPostFactory;
|
||||||
|
@Inject private volatile CryptoComponent crypto;
|
||||||
private volatile MessageId parentId = null;
|
private volatile MessageId parentId = null;
|
||||||
private volatile long minTimestamp = -1;
|
private volatile long minTimestamp = -1;
|
||||||
private volatile LocalAuthor localAuthor = null;
|
private volatile LocalAuthor localAuthor = null;
|
||||||
@@ -160,10 +160,10 @@ implements OnItemSelectedListener, OnClickListener {
|
|||||||
@Override
|
@Override
|
||||||
public void onResume() {
|
public void onResume() {
|
||||||
super.onResume();
|
super.onResume();
|
||||||
loadAuthorsAndGroup();
|
loadAuthorsAndForum();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void loadAuthorsAndGroup() {
|
private void loadAuthorsAndForum() {
|
||||||
runOnDbThread(new Runnable() {
|
runOnDbThread(new Runnable() {
|
||||||
public void run() {
|
public void run() {
|
||||||
try {
|
try {
|
||||||
@@ -174,7 +174,7 @@ implements OnItemSelectedListener, OnClickListener {
|
|||||||
long duration = System.currentTimeMillis() - now;
|
long duration = System.currentTimeMillis() - now;
|
||||||
if (LOG.isLoggable(INFO))
|
if (LOG.isLoggable(INFO))
|
||||||
LOG.info("Load took " + duration + " ms");
|
LOG.info("Load took " + duration + " ms");
|
||||||
displayAuthorsAndGroup(localAuthors);
|
displayAuthorsAndForum(localAuthors);
|
||||||
} catch (DbException e) {
|
} catch (DbException e) {
|
||||||
if (LOG.isLoggable(WARNING))
|
if (LOG.isLoggable(WARNING))
|
||||||
LOG.log(WARNING, e.toString(), e);
|
LOG.log(WARNING, e.toString(), e);
|
||||||
@@ -183,7 +183,7 @@ implements OnItemSelectedListener, OnClickListener {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private void displayAuthorsAndGroup(
|
private void displayAuthorsAndForum(
|
||||||
final Collection<LocalAuthor> localAuthors) {
|
final Collection<LocalAuthor> localAuthors) {
|
||||||
runOnUiThread(new Runnable() {
|
runOnUiThread(new Runnable() {
|
||||||
public void run() {
|
public void run() {
|
||||||
@@ -226,7 +226,7 @@ implements OnItemSelectedListener, OnClickListener {
|
|||||||
byte[] b = data.getByteArrayExtra("briar.LOCAL_AUTHOR_ID");
|
byte[] b = data.getByteArrayExtra("briar.LOCAL_AUTHOR_ID");
|
||||||
if (b == null) throw new IllegalStateException();
|
if (b == null) throw new IllegalStateException();
|
||||||
localAuthorId = new AuthorId(b);
|
localAuthorId = new AuthorId(b);
|
||||||
loadAuthorsAndGroup();
|
loadAuthorsAndForum();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -254,14 +254,14 @@ implements OnItemSelectedListener, OnClickListener {
|
|||||||
|
|
||||||
public void onClick(View view) {
|
public void onClick(View view) {
|
||||||
if (forum == null) throw new IllegalStateException();
|
if (forum == null) throw new IllegalStateException();
|
||||||
String message = content.getText().toString();
|
String body = content.getText().toString();
|
||||||
if (message.equals("")) return;
|
if (body.equals("")) return;
|
||||||
createMessage(StringUtils.toUtf8(message));
|
createPost(StringUtils.toUtf8(body));
|
||||||
Toast.makeText(this, R.string.post_sent_toast, LENGTH_LONG).show();
|
Toast.makeText(this, R.string.post_sent_toast, LENGTH_LONG).show();
|
||||||
finish();
|
finish();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void createMessage(final byte[] body) {
|
private void createPost(final byte[] body) {
|
||||||
cryptoExecutor.execute(new Runnable() {
|
cryptoExecutor.execute(new Runnable() {
|
||||||
public void run() {
|
public void run() {
|
||||||
// Don't use an earlier timestamp than the newest post
|
// Don't use an earlier timestamp than the newest post
|
||||||
@@ -285,17 +285,17 @@ implements OnItemSelectedListener, OnClickListener {
|
|||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
storeMessage(m);
|
storePost(m);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private void storeMessage(final Message m) {
|
private void storePost(final Message m) {
|
||||||
runOnDbThread(new Runnable() {
|
runOnDbThread(new Runnable() {
|
||||||
public void run() {
|
public void run() {
|
||||||
try {
|
try {
|
||||||
long now = System.currentTimeMillis();
|
long now = System.currentTimeMillis();
|
||||||
forumManager.addLocalMessage(m);
|
forumManager.addLocalPost(m);
|
||||||
long duration = System.currentTimeMillis() - now;
|
long duration = System.currentTimeMillis() - now;
|
||||||
if (LOG.isLoggable(INFO))
|
if (LOG.isLoggable(INFO))
|
||||||
LOG.info("Storing message took " + duration + " ms");
|
LOG.info("Storing message took " + duration + " ms");
|
||||||
|
|||||||
@@ -5,7 +5,6 @@ import org.briarproject.api.contact.ContactId;
|
|||||||
import org.briarproject.api.db.DbException;
|
import org.briarproject.api.db.DbException;
|
||||||
import org.briarproject.api.sync.GroupId;
|
import org.briarproject.api.sync.GroupId;
|
||||||
import org.briarproject.api.sync.Message;
|
import org.briarproject.api.sync.Message;
|
||||||
import org.briarproject.api.sync.MessageHeader;
|
|
||||||
import org.briarproject.api.sync.MessageId;
|
import org.briarproject.api.sync.MessageId;
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
@@ -18,8 +17,8 @@ public interface ForumManager {
|
|||||||
*/
|
*/
|
||||||
boolean addForum(Forum f) throws DbException;
|
boolean addForum(Forum f) throws DbException;
|
||||||
|
|
||||||
/** Stores a local message. */
|
/** Stores a local forum post. */
|
||||||
void addLocalMessage(Message m) throws DbException;
|
void addLocalPost(Message m) throws DbException;
|
||||||
|
|
||||||
/** Returns all forums to which the user could subscribe. */
|
/** Returns all forums to which the user could subscribe. */
|
||||||
Collection<Forum> getAvailableForums() throws DbException;
|
Collection<Forum> getAvailableForums() throws DbException;
|
||||||
@@ -30,12 +29,11 @@ public interface ForumManager {
|
|||||||
/** Returns all forums to which the user subscribes. */
|
/** Returns all forums to which the user subscribes. */
|
||||||
Collection<Forum> getForums() throws DbException;
|
Collection<Forum> getForums() throws DbException;
|
||||||
|
|
||||||
/** Returns the body of the message with the given ID. */
|
/** Returns the body of the forum post with the given ID. */
|
||||||
byte[] getMessageBody(MessageId m) throws DbException;
|
byte[] getPostBody(MessageId m) throws DbException;
|
||||||
|
|
||||||
/** Returns the headers of all messages in the given forum. */
|
/** Returns the headers of all posts in the given forum. */
|
||||||
Collection<MessageHeader> getMessageHeaders(GroupId g)
|
Collection<ForumPostHeader> getPostHeaders(GroupId g) throws DbException;
|
||||||
throws DbException;
|
|
||||||
|
|
||||||
/** Returns all contacts who subscribe to the given forum. */
|
/** Returns all contacts who subscribe to the given forum. */
|
||||||
Collection<Contact> getSubscribers(GroupId g) throws DbException;
|
Collection<Contact> getSubscribers(GroupId g) throws DbException;
|
||||||
@@ -49,7 +47,7 @@ public interface ForumManager {
|
|||||||
*/
|
*/
|
||||||
void removeForum(Forum f) throws DbException;
|
void removeForum(Forum f) throws DbException;
|
||||||
|
|
||||||
/** Marks a message as read or unread. */
|
/** Marks a forum post as read or unread. */
|
||||||
void setReadFlag(MessageId m, boolean read) throws DbException;
|
void setReadFlag(MessageId m, boolean read) throws DbException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -0,0 +1,19 @@
|
|||||||
|
package org.briarproject.api.forum;
|
||||||
|
|
||||||
|
import org.briarproject.api.identity.Author;
|
||||||
|
import org.briarproject.api.sync.MessageId;
|
||||||
|
|
||||||
|
public interface ForumPostHeader {
|
||||||
|
|
||||||
|
MessageId getId();
|
||||||
|
|
||||||
|
Author getAuthor();
|
||||||
|
|
||||||
|
Author.Status getAuthorStatus();
|
||||||
|
|
||||||
|
String getContentType();
|
||||||
|
|
||||||
|
long getTimestamp();
|
||||||
|
|
||||||
|
boolean isRead();
|
||||||
|
}
|
||||||
@@ -8,6 +8,7 @@ import org.briarproject.api.db.DatabaseComponent;
|
|||||||
import org.briarproject.api.db.DbException;
|
import org.briarproject.api.db.DbException;
|
||||||
import org.briarproject.api.forum.Forum;
|
import org.briarproject.api.forum.Forum;
|
||||||
import org.briarproject.api.forum.ForumManager;
|
import org.briarproject.api.forum.ForumManager;
|
||||||
|
import org.briarproject.api.forum.ForumPostHeader;
|
||||||
import org.briarproject.api.sync.Group;
|
import org.briarproject.api.sync.Group;
|
||||||
import org.briarproject.api.sync.GroupId;
|
import org.briarproject.api.sync.GroupId;
|
||||||
import org.briarproject.api.sync.Message;
|
import org.briarproject.api.sync.Message;
|
||||||
@@ -35,7 +36,7 @@ class ForumManagerImpl implements ForumManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void addLocalMessage(Message m) throws DbException {
|
public void addLocalPost(Message m) throws DbException {
|
||||||
db.addLocalMessage(m);
|
db.addLocalMessage(m);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -61,14 +62,19 @@ class ForumManagerImpl implements ForumManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public byte[] getMessageBody(MessageId m) throws DbException {
|
public byte[] getPostBody(MessageId m) throws DbException {
|
||||||
return db.getMessageBody(m);
|
return db.getMessageBody(m);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Collection<MessageHeader> getMessageHeaders(GroupId g)
|
public Collection<ForumPostHeader> getPostHeaders(GroupId g)
|
||||||
throws DbException {
|
throws DbException {
|
||||||
return db.getMessageHeaders(g);
|
Collection<MessageHeader> headers = db.getMessageHeaders(g);
|
||||||
|
List<ForumPostHeader> postHeaders =
|
||||||
|
new ArrayList<ForumPostHeader>(headers.size());
|
||||||
|
for (MessageHeader m : headers)
|
||||||
|
postHeaders.add(new ForumPostHeaderImpl(m));
|
||||||
|
return Collections.unmodifiableList(postHeaders);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -0,0 +1,46 @@
|
|||||||
|
package org.briarproject.forum;
|
||||||
|
|
||||||
|
import org.briarproject.api.forum.ForumPostHeader;
|
||||||
|
import org.briarproject.api.identity.Author;
|
||||||
|
import org.briarproject.api.sync.MessageHeader;
|
||||||
|
import org.briarproject.api.sync.MessageId;
|
||||||
|
|
||||||
|
// Temporary facade during sync protocol refactoring
|
||||||
|
class ForumPostHeaderImpl implements ForumPostHeader {
|
||||||
|
|
||||||
|
private final MessageHeader messageHeader;
|
||||||
|
|
||||||
|
ForumPostHeaderImpl(MessageHeader messageHeader) {
|
||||||
|
this.messageHeader = messageHeader;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public MessageId getId() {
|
||||||
|
return messageHeader.getId();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Author getAuthor() {
|
||||||
|
return messageHeader.getAuthor();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Author.Status getAuthorStatus() {
|
||||||
|
return messageHeader.getAuthorStatus();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getContentType() {
|
||||||
|
return messageHeader.getContentType();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public long getTimestamp() {
|
||||||
|
return messageHeader.getTimestamp();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isRead() {
|
||||||
|
return messageHeader.isRead();
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user