mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-14 11:49:04 +01:00
Facades for forums. #172
This commit is contained in:
@@ -170,7 +170,7 @@ public class BriarService extends RoboService implements EventListener {
|
||||
public void eventOccurred(Event e) {
|
||||
if (e instanceof MessageAddedEvent) {
|
||||
MessageAddedEvent m = (MessageAddedEvent) e;
|
||||
GroupId g = m.getGroup().getId();
|
||||
GroupId g = m.getGroupId();
|
||||
ContactId c = m.getContactId();
|
||||
if (c != null) showMessageNotification(g, c);
|
||||
}
|
||||
|
||||
@@ -347,7 +347,7 @@ implements EventListener, OnClickListener, OnItemClickListener {
|
||||
finishOnUiThread();
|
||||
}
|
||||
} else if (e instanceof MessageAddedEvent) {
|
||||
GroupId g = ((MessageAddedEvent) e).getGroup().getId();
|
||||
GroupId g = ((MessageAddedEvent) e).getGroupId();
|
||||
if (g.equals(groupId)) {
|
||||
LOG.info("Message added, reloading");
|
||||
loadHeaders();
|
||||
|
||||
@@ -20,8 +20,8 @@ import org.briarproject.api.event.EventListener;
|
||||
import org.briarproject.api.event.RemoteSubscriptionsUpdatedEvent;
|
||||
import org.briarproject.api.event.SubscriptionAddedEvent;
|
||||
import org.briarproject.api.event.SubscriptionRemovedEvent;
|
||||
import org.briarproject.api.forum.Forum;
|
||||
import org.briarproject.api.forum.ForumManager;
|
||||
import org.briarproject.api.sync.Group;
|
||||
import org.briarproject.api.sync.GroupId;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@@ -43,7 +43,6 @@ implements EventListener, OnItemClickListener {
|
||||
|
||||
private AvailableForumsAdapter adapter = null;
|
||||
private ListView list = null;
|
||||
private ListLoadingProgressBar loading = null;
|
||||
|
||||
// Fields that are accessed from background threads must be volatile
|
||||
@Inject private volatile ForumManager forumManager;
|
||||
@@ -60,7 +59,7 @@ implements EventListener, OnItemClickListener {
|
||||
list.setOnItemClickListener(this);
|
||||
|
||||
// Show a progress bar while the list is loading
|
||||
loading = new ListLoadingProgressBar(this);
|
||||
ListLoadingProgressBar loading = new ListLoadingProgressBar(this);
|
||||
setContentView(loading);
|
||||
}
|
||||
|
||||
@@ -78,12 +77,12 @@ implements EventListener, OnItemClickListener {
|
||||
Collection<ForumContacts> available =
|
||||
new ArrayList<ForumContacts>();
|
||||
long now = System.currentTimeMillis();
|
||||
for (Group g : forumManager.getAvailableGroups()) {
|
||||
for (Forum f : forumManager.getAvailableForums()) {
|
||||
try {
|
||||
GroupId id = g.getId();
|
||||
GroupId id = f.getId();
|
||||
Collection<Contact> c =
|
||||
forumManager.getSubscribers(id);
|
||||
available.add(new ForumContacts(g, c));
|
||||
available.add(new ForumContacts(f, c));
|
||||
} catch (NoSuchSubscriptionException e) {
|
||||
// Continue
|
||||
}
|
||||
@@ -142,18 +141,18 @@ implements EventListener, OnItemClickListener {
|
||||
AvailableForumsItem item = adapter.getItem(position);
|
||||
Collection<ContactId> visible = new ArrayList<ContactId>();
|
||||
for (Contact c : item.getContacts()) visible.add(c.getId());
|
||||
addSubscription(item.getGroup(), visible);
|
||||
addSubscription(item.getForum(), visible);
|
||||
String subscribed = getString(R.string.subscribed_toast);
|
||||
Toast.makeText(this, subscribed, LENGTH_SHORT).show();
|
||||
}
|
||||
|
||||
private void addSubscription(final Group g,
|
||||
private void addSubscription(final Forum f,
|
||||
final Collection<ContactId> visible) {
|
||||
runOnDbThread(new Runnable() {
|
||||
public void run() {
|
||||
try {
|
||||
forumManager.addGroup(g);
|
||||
forumManager.setVisibility(g.getId(), visible);
|
||||
forumManager.addForum(f);
|
||||
forumManager.setVisibility(f.getId(), visible);
|
||||
} catch (DbException e) {
|
||||
if (LOG.isLoggable(WARNING))
|
||||
LOG.log(WARNING, e.toString(), e);
|
||||
|
||||
@@ -41,7 +41,7 @@ class AvailableForumsAdapter extends ArrayAdapter<AvailableForumsItem> {
|
||||
name.setSingleLine();
|
||||
name.setEllipsize(END);
|
||||
name.setPadding(pad, pad, pad, pad);
|
||||
name.setText(item.getGroup().getName());
|
||||
name.setText(item.getForum().getName());
|
||||
layout.addView(name);
|
||||
|
||||
TextView status = new TextView(ctx);
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package org.briarproject.android.forum;
|
||||
|
||||
import org.briarproject.api.contact.Contact;
|
||||
import org.briarproject.api.sync.Group;
|
||||
import org.briarproject.api.forum.Forum;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
@@ -13,8 +13,8 @@ class AvailableForumsItem {
|
||||
this.forumContacts = forumContacts;
|
||||
}
|
||||
|
||||
Group getGroup() {
|
||||
return forumContacts.getGroup();
|
||||
Forum getForum() {
|
||||
return forumContacts.getForum();
|
||||
}
|
||||
|
||||
Collection<Contact> getContacts() {
|
||||
|
||||
@@ -9,8 +9,8 @@ class AvailableForumsItemComparator implements Comparator<AvailableForumsItem> {
|
||||
|
||||
public int compare(AvailableForumsItem a, AvailableForumsItem b) {
|
||||
if (a == b) return 0;
|
||||
String aName = a.getGroup().getName();
|
||||
String bName = b.getGroup().getName();
|
||||
String aName = a.getForum().getName();
|
||||
String bName = b.getForum().getName();
|
||||
return String.CASE_INSENSITIVE_ORDER.compare(aName, bName);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,9 +17,9 @@ import org.briarproject.R;
|
||||
import org.briarproject.android.BriarActivity;
|
||||
import org.briarproject.android.util.LayoutUtils;
|
||||
import org.briarproject.api.db.DbException;
|
||||
import org.briarproject.api.forum.Forum;
|
||||
import org.briarproject.api.forum.ForumFactory;
|
||||
import org.briarproject.api.forum.ForumManager;
|
||||
import org.briarproject.api.sync.Group;
|
||||
import org.briarproject.api.sync.GroupFactory;
|
||||
import org.briarproject.util.StringUtils;
|
||||
|
||||
import java.util.logging.Logger;
|
||||
@@ -52,7 +52,7 @@ implements OnEditorActionListener, OnClickListener {
|
||||
private TextView feedback = null;
|
||||
|
||||
// Fields that are accessed from background threads must be volatile
|
||||
@Inject private volatile GroupFactory groupFactory;
|
||||
@Inject private volatile ForumFactory forumFactory;
|
||||
@Inject private volatile ForumManager forumManager;
|
||||
|
||||
@Override
|
||||
@@ -138,13 +138,13 @@ implements OnEditorActionListener, OnClickListener {
|
||||
runOnDbThread(new Runnable() {
|
||||
public void run() {
|
||||
try {
|
||||
Group g = groupFactory.createGroup(name);
|
||||
Forum f = forumFactory.createForum(name);
|
||||
long now = System.currentTimeMillis();
|
||||
forumManager.addGroup(g);
|
||||
forumManager.addForum(f);
|
||||
long duration = System.currentTimeMillis() - now;
|
||||
if (LOG.isLoggable(INFO))
|
||||
LOG.info("Storing forum took " + duration + " ms");
|
||||
displayForum(g);
|
||||
displayForum(f);
|
||||
} catch (DbException e) {
|
||||
if (LOG.isLoggable(WARNING))
|
||||
LOG.log(WARNING, e.toString(), e);
|
||||
@@ -154,13 +154,13 @@ implements OnEditorActionListener, OnClickListener {
|
||||
});
|
||||
}
|
||||
|
||||
private void displayForum(final Group g) {
|
||||
private void displayForum(final Forum f) {
|
||||
runOnUiThread(new Runnable() {
|
||||
public void run() {
|
||||
Intent i = new Intent(CreateForumActivity.this,
|
||||
ForumActivity.class);
|
||||
i.putExtra("briar.GROUP_ID", g.getId().getBytes());
|
||||
i.putExtra("briar.FORUM_NAME", g.getName());
|
||||
i.putExtra("briar.GROUP_ID", f.getId().getBytes());
|
||||
i.putExtra("briar.FORUM_NAME", f.getName());
|
||||
startActivity(i);
|
||||
Toast.makeText(CreateForumActivity.this,
|
||||
R.string.forum_created_toast, LENGTH_LONG).show();
|
||||
|
||||
@@ -26,9 +26,9 @@ import org.briarproject.api.event.EventBus;
|
||||
import org.briarproject.api.event.EventListener;
|
||||
import org.briarproject.api.event.MessageAddedEvent;
|
||||
import org.briarproject.api.event.SubscriptionRemovedEvent;
|
||||
import org.briarproject.api.forum.Forum;
|
||||
import org.briarproject.api.forum.ForumManager;
|
||||
import org.briarproject.api.identity.Author;
|
||||
import org.briarproject.api.sync.Group;
|
||||
import org.briarproject.api.sync.GroupId;
|
||||
import org.briarproject.api.sync.MessageHeader;
|
||||
import org.briarproject.api.sync.MessageId;
|
||||
@@ -74,7 +74,7 @@ OnClickListener, OnItemClickListener {
|
||||
@Inject private volatile ForumManager forumManager;
|
||||
@Inject private volatile EventBus eventBus;
|
||||
private volatile GroupId groupId = null;
|
||||
private volatile Group group = null;
|
||||
private volatile Forum forum = null;
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle state) {
|
||||
@@ -152,10 +152,10 @@ OnClickListener, OnItemClickListener {
|
||||
public void run() {
|
||||
try {
|
||||
long now = System.currentTimeMillis();
|
||||
group = forumManager.getGroup(groupId);
|
||||
forum = forumManager.getForum(groupId);
|
||||
long duration = System.currentTimeMillis() - now;
|
||||
if (LOG.isLoggable(INFO))
|
||||
LOG.info("Loading group " + duration + " ms");
|
||||
LOG.info("Loading forum " + duration + " ms");
|
||||
displayForumName();
|
||||
} catch (NoSuchSubscriptionException e) {
|
||||
finishOnUiThread();
|
||||
@@ -170,7 +170,7 @@ OnClickListener, OnItemClickListener {
|
||||
private void displayForumName() {
|
||||
runOnUiThread(new Runnable() {
|
||||
public void run() {
|
||||
setTitle(group.getName());
|
||||
setTitle(forum.getName());
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -313,7 +313,7 @@ OnClickListener, OnItemClickListener {
|
||||
|
||||
public void eventOccurred(Event e) {
|
||||
if (e instanceof MessageAddedEvent) {
|
||||
if (((MessageAddedEvent) e).getGroup().getId().equals(groupId)) {
|
||||
if (((MessageAddedEvent) e).getGroupId().equals(groupId)) {
|
||||
LOG.info("Message added, reloading");
|
||||
loadHeaders();
|
||||
}
|
||||
@@ -330,13 +330,13 @@ OnClickListener, OnItemClickListener {
|
||||
if (view == composeButton) {
|
||||
Intent i = new Intent(this, WriteForumPostActivity.class);
|
||||
i.putExtra("briar.GROUP_ID", groupId.getBytes());
|
||||
i.putExtra("briar.FORUM_NAME", group.getName());
|
||||
i.putExtra("briar.FORUM_NAME", forum.getName());
|
||||
i.putExtra("briar.MIN_TIMESTAMP", getMinTimestampForNewMessage());
|
||||
startActivity(i);
|
||||
} else if (view == shareButton) {
|
||||
Intent i = new Intent(this, ShareForumActivity.class);
|
||||
i.putExtra("briar.GROUP_ID", groupId.getBytes());
|
||||
i.putExtra("briar.FORUM_NAME", group.getName());
|
||||
i.putExtra("briar.FORUM_NAME", forum.getName());
|
||||
startActivity(i);
|
||||
}
|
||||
}
|
||||
@@ -361,7 +361,7 @@ OnClickListener, OnItemClickListener {
|
||||
MessageHeader item = adapter.getItem(position).getHeader();
|
||||
Intent i = new Intent(this, ReadForumPostActivity.class);
|
||||
i.putExtra("briar.GROUP_ID", groupId.getBytes());
|
||||
i.putExtra("briar.FORUM_NAME", group.getName());
|
||||
i.putExtra("briar.FORUM_NAME", forum.getName());
|
||||
i.putExtra("briar.MESSAGE_ID", item.getId().getBytes());
|
||||
Author author = item.getAuthor();
|
||||
if (author != null) i.putExtra("briar.AUTHOR_NAME", author.getName());
|
||||
|
||||
@@ -1,22 +1,22 @@
|
||||
package org.briarproject.android.forum;
|
||||
|
||||
import org.briarproject.api.contact.Contact;
|
||||
import org.briarproject.api.sync.Group;
|
||||
import org.briarproject.api.forum.Forum;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
class ForumContacts {
|
||||
|
||||
private final Group group;
|
||||
private final Forum forum;
|
||||
private final Collection<Contact> contacts;
|
||||
|
||||
ForumContacts(Group group, Collection<Contact> contacts) {
|
||||
this.group = group;
|
||||
ForumContacts(Forum forum, Collection<Contact> contacts) {
|
||||
this.forum = forum;
|
||||
this.contacts = contacts;
|
||||
}
|
||||
|
||||
Group getGroup() {
|
||||
return group;
|
||||
Forum getForum() {
|
||||
return forum;
|
||||
}
|
||||
|
||||
Collection<Contact> getContacts() {
|
||||
|
||||
@@ -32,6 +32,7 @@ import org.briarproject.api.event.MessageAddedEvent;
|
||||
import org.briarproject.api.event.RemoteSubscriptionsUpdatedEvent;
|
||||
import org.briarproject.api.event.SubscriptionAddedEvent;
|
||||
import org.briarproject.api.event.SubscriptionRemovedEvent;
|
||||
import org.briarproject.api.forum.Forum;
|
||||
import org.briarproject.api.forum.ForumManager;
|
||||
import org.briarproject.api.sync.Group;
|
||||
import org.briarproject.api.sync.GroupId;
|
||||
@@ -153,16 +154,16 @@ OnCreateContextMenuListener {
|
||||
public void run() {
|
||||
try {
|
||||
long now = System.currentTimeMillis();
|
||||
for (Group g : forumManager.getGroups()) {
|
||||
for (Forum f : forumManager.getForums()) {
|
||||
try {
|
||||
Collection<MessageHeader> headers =
|
||||
forumManager.getMessageHeaders(g.getId());
|
||||
displayHeaders(g, headers);
|
||||
forumManager.getMessageHeaders(f.getId());
|
||||
displayHeaders(f, headers);
|
||||
} catch (NoSuchSubscriptionException e) {
|
||||
// Continue
|
||||
}
|
||||
}
|
||||
int available = forumManager.getAvailableGroups().size();
|
||||
int available = forumManager.getAvailableForums().size();
|
||||
long duration = System.currentTimeMillis() - now;
|
||||
if (LOG.isLoggable(INFO))
|
||||
LOG.info("Full load took " + duration + " ms");
|
||||
@@ -189,11 +190,11 @@ OnCreateContextMenuListener {
|
||||
});
|
||||
}
|
||||
|
||||
private void displayHeaders(final Group g,
|
||||
private void displayHeaders(final Forum f,
|
||||
final Collection<MessageHeader> headers) {
|
||||
runOnUiThread(new Runnable() {
|
||||
public void run() {
|
||||
GroupId id = g.getId();
|
||||
GroupId id = f.getId();
|
||||
groupIds.put(id, id);
|
||||
list.setVisibility(VISIBLE);
|
||||
loading.setVisibility(GONE);
|
||||
@@ -201,7 +202,7 @@ OnCreateContextMenuListener {
|
||||
ForumListItem item = findForum(id);
|
||||
if (item != null) adapter.remove(item);
|
||||
// Add a new item
|
||||
adapter.add(new ForumListItem(g, headers));
|
||||
adapter.add(new ForumListItem(f, headers));
|
||||
adapter.sort(ForumListItemComparator.INSTANCE);
|
||||
adapter.notifyDataSetChanged();
|
||||
selectFirstUnread();
|
||||
@@ -230,7 +231,7 @@ OnCreateContextMenuListener {
|
||||
int count = adapter.getCount();
|
||||
for (int i = 0; i < count; i++) {
|
||||
ForumListItem item = adapter.getItem(i);
|
||||
if (item.getGroup().getId().equals(g)) return item;
|
||||
if (item.getForum().getId().equals(g)) return item;
|
||||
}
|
||||
return null; // Not found
|
||||
}
|
||||
@@ -255,8 +256,8 @@ OnCreateContextMenuListener {
|
||||
|
||||
public void eventOccurred(Event e) {
|
||||
if (e instanceof MessageAddedEvent) {
|
||||
Group g = ((MessageAddedEvent) e).getGroup();
|
||||
if (groupIds.containsKey(g.getId())) {
|
||||
GroupId g = ((MessageAddedEvent) e).getGroupId();
|
||||
if (groupIds.containsKey(g)) {
|
||||
LOG.info("Message added, reloading");
|
||||
loadHeaders(g);
|
||||
}
|
||||
@@ -275,19 +276,20 @@ OnCreateContextMenuListener {
|
||||
}
|
||||
}
|
||||
|
||||
private void loadHeaders(final Group g) {
|
||||
private void loadHeaders(final GroupId g) {
|
||||
runOnDbThread(new Runnable() {
|
||||
public void run() {
|
||||
try {
|
||||
long now = System.currentTimeMillis();
|
||||
Forum f = forumManager.getForum(g);
|
||||
Collection<MessageHeader> headers =
|
||||
forumManager.getMessageHeaders(g.getId());
|
||||
forumManager.getMessageHeaders(g);
|
||||
long duration = System.currentTimeMillis() - now;
|
||||
if (LOG.isLoggable(INFO))
|
||||
LOG.info("Partial load took " + duration + " ms");
|
||||
displayHeaders(g, headers);
|
||||
displayHeaders(f, headers);
|
||||
} catch (NoSuchSubscriptionException e) {
|
||||
removeForum(g.getId());
|
||||
removeForum(g);
|
||||
} catch (DbException e) {
|
||||
if (LOG.isLoggable(WARNING))
|
||||
LOG.log(WARNING, e.toString(), e);
|
||||
@@ -320,7 +322,7 @@ OnCreateContextMenuListener {
|
||||
public void run() {
|
||||
try {
|
||||
long now = System.currentTimeMillis();
|
||||
int available = forumManager.getAvailableGroups().size();
|
||||
int available = forumManager.getAvailableForums().size();
|
||||
long duration = System.currentTimeMillis() - now;
|
||||
if (LOG.isLoggable(INFO))
|
||||
LOG.info("Loading available took " + duration + " ms");
|
||||
@@ -344,9 +346,9 @@ OnCreateContextMenuListener {
|
||||
public void onItemClick(AdapterView<?> parent, View view, int position,
|
||||
long id) {
|
||||
Intent i = new Intent(this, ForumActivity.class);
|
||||
Group g = adapter.getItem(position).getGroup();
|
||||
i.putExtra("briar.GROUP_ID", g.getId().getBytes());
|
||||
i.putExtra("briar.FORUM_NAME", g.getName());
|
||||
Forum f = adapter.getItem(position).getForum();
|
||||
i.putExtra("briar.GROUP_ID", f.getId().getBytes());
|
||||
i.putExtra("briar.FORUM_NAME", f.getName());
|
||||
startActivity(i);
|
||||
}
|
||||
|
||||
@@ -363,19 +365,19 @@ OnCreateContextMenuListener {
|
||||
ContextMenuInfo info = menuItem.getMenuInfo();
|
||||
int position = ((AdapterContextMenuInfo) info).position;
|
||||
ForumListItem item = adapter.getItem(position);
|
||||
removeSubscription(item.getGroup());
|
||||
removeSubscription(item.getForum());
|
||||
String unsubscribed = getString(R.string.unsubscribed_toast);
|
||||
Toast.makeText(this, unsubscribed, LENGTH_SHORT).show();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private void removeSubscription(final Group g) {
|
||||
private void removeSubscription(final Forum f) {
|
||||
runOnDbThread(new Runnable() {
|
||||
public void run() {
|
||||
try {
|
||||
long now = System.currentTimeMillis();
|
||||
forumManager.removeGroup(g);
|
||||
forumManager.removeForum(f);
|
||||
long duration = System.currentTimeMillis() - now;
|
||||
if (LOG.isLoggable(INFO))
|
||||
LOG.info("Removing group took " + duration + " ms");
|
||||
|
||||
@@ -46,7 +46,7 @@ class ForumListAdapter extends ArrayAdapter<ForumListItem> {
|
||||
name.setSingleLine();
|
||||
name.setEllipsize(END);
|
||||
name.setPadding(pad, pad, pad, pad);
|
||||
String forumName = item.getGroup().getName();
|
||||
String forumName = item.getForum().getName();
|
||||
if (unread > 0) name.setText(forumName + " (" + unread + ")");
|
||||
else name.setText(forumName);
|
||||
layout.addView(name);
|
||||
|
||||
@@ -1,19 +1,19 @@
|
||||
package org.briarproject.android.forum;
|
||||
|
||||
import org.briarproject.api.sync.Group;
|
||||
import org.briarproject.api.forum.Forum;
|
||||
import org.briarproject.api.sync.MessageHeader;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
class ForumListItem {
|
||||
|
||||
private final Group group;
|
||||
private final Forum forum;
|
||||
private final boolean empty;
|
||||
private final long timestamp;
|
||||
private final int unread;
|
||||
|
||||
ForumListItem(Group group, Collection<MessageHeader> headers) {
|
||||
this.group = group;
|
||||
ForumListItem(Forum forum, Collection<MessageHeader> headers) {
|
||||
this.forum = forum;
|
||||
empty = headers.isEmpty();
|
||||
if (empty) {
|
||||
timestamp = 0;
|
||||
@@ -34,8 +34,8 @@ class ForumListItem {
|
||||
}
|
||||
}
|
||||
|
||||
Group getGroup() {
|
||||
return group;
|
||||
Forum getForum() {
|
||||
return forum;
|
||||
}
|
||||
|
||||
boolean isEmpty() {
|
||||
|
||||
@@ -9,13 +9,13 @@ class ForumListItemComparator implements Comparator<ForumListItem> {
|
||||
|
||||
public int compare(ForumListItem a, ForumListItem b) {
|
||||
if (a == b) return 0;
|
||||
// The item with the newest message comes first
|
||||
// The forum with the newest message comes first
|
||||
long aTime = a.getTimestamp(), bTime = b.getTimestamp();
|
||||
if (aTime > bTime) return -1;
|
||||
if (aTime < bTime) return 1;
|
||||
// Break ties by group name
|
||||
String aName = a.getGroup().getName();
|
||||
String bName = b.getGroup().getName();
|
||||
// Break ties by forum name
|
||||
String aName = a.getForum().getName();
|
||||
String bName = b.getForum().getName();
|
||||
return String.CASE_INSENSITIVE_ORDER.compare(aName, bName);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,14 +28,14 @@ import org.briarproject.api.crypto.CryptoExecutor;
|
||||
import org.briarproject.api.crypto.KeyParser;
|
||||
import org.briarproject.api.crypto.PrivateKey;
|
||||
import org.briarproject.api.db.DbException;
|
||||
import org.briarproject.api.forum.Forum;
|
||||
import org.briarproject.api.forum.ForumManager;
|
||||
import org.briarproject.api.forum.ForumPostFactory;
|
||||
import org.briarproject.api.identity.AuthorId;
|
||||
import org.briarproject.api.identity.IdentityManager;
|
||||
import org.briarproject.api.identity.LocalAuthor;
|
||||
import org.briarproject.api.sync.Group;
|
||||
import org.briarproject.api.sync.GroupId;
|
||||
import org.briarproject.api.sync.Message;
|
||||
import org.briarproject.api.sync.MessageFactory;
|
||||
import org.briarproject.api.sync.MessageId;
|
||||
import org.briarproject.util.StringUtils;
|
||||
|
||||
@@ -79,11 +79,11 @@ implements OnItemSelectedListener, OnClickListener {
|
||||
@Inject private volatile IdentityManager identityManager;
|
||||
@Inject private volatile ForumManager forumManager;
|
||||
@Inject private volatile CryptoComponent crypto;
|
||||
@Inject private volatile MessageFactory messageFactory;
|
||||
@Inject private volatile ForumPostFactory forumPostFactory;
|
||||
private volatile MessageId parentId = null;
|
||||
private volatile long minTimestamp = -1;
|
||||
private volatile LocalAuthor localAuthor = null;
|
||||
private volatile Group group = null;
|
||||
private volatile Forum forum = null;
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle state) {
|
||||
@@ -138,7 +138,7 @@ implements OnItemSelectedListener, OnClickListener {
|
||||
sendButton.setId(3);
|
||||
sendButton.setBackgroundResource(0);
|
||||
sendButton.setImageResource(R.drawable.social_send_now);
|
||||
sendButton.setEnabled(false); // Enabled after loading the group
|
||||
sendButton.setEnabled(false); // Enabled after loading the forum
|
||||
sendButton.setOnClickListener(this);
|
||||
RelativeLayout.LayoutParams right = CommonLayoutParams.relative();
|
||||
right.addRule(ALIGN_PARENT_RIGHT);
|
||||
@@ -170,7 +170,7 @@ implements OnItemSelectedListener, OnClickListener {
|
||||
long now = System.currentTimeMillis();
|
||||
Collection<LocalAuthor> localAuthors =
|
||||
identityManager.getLocalAuthors();
|
||||
group = forumManager.getGroup(groupId);
|
||||
forum = forumManager.getForum(groupId);
|
||||
long duration = System.currentTimeMillis() - now;
|
||||
if (LOG.isLoggable(INFO))
|
||||
LOG.info("Load took " + duration + " ms");
|
||||
@@ -204,7 +204,7 @@ implements OnItemSelectedListener, OnClickListener {
|
||||
break;
|
||||
}
|
||||
}
|
||||
setTitle(group.getName());
|
||||
setTitle(forum.getName());
|
||||
sendButton.setEnabled(true);
|
||||
}
|
||||
});
|
||||
@@ -253,7 +253,7 @@ implements OnItemSelectedListener, OnClickListener {
|
||||
}
|
||||
|
||||
public void onClick(View view) {
|
||||
if (group == null) throw new IllegalStateException();
|
||||
if (forum == null) throw new IllegalStateException();
|
||||
String message = content.getText().toString();
|
||||
if (message.equals("")) return;
|
||||
createMessage(StringUtils.toUtf8(message));
|
||||
@@ -270,14 +270,14 @@ implements OnItemSelectedListener, OnClickListener {
|
||||
Message m;
|
||||
try {
|
||||
if (localAuthor == null) {
|
||||
m = messageFactory.createAnonymousMessage(parentId,
|
||||
group, "text/plain", timestamp, body);
|
||||
m = forumPostFactory.createAnonymousPost(parentId,
|
||||
forum, "text/plain", timestamp, body);
|
||||
} else {
|
||||
KeyParser keyParser = crypto.getSignatureKeyParser();
|
||||
byte[] b = localAuthor.getPrivateKey();
|
||||
PrivateKey authorKey = keyParser.parsePrivateKey(b);
|
||||
m = messageFactory.createPseudonymousMessage(parentId,
|
||||
group, localAuthor, authorKey, "text/plain",
|
||||
m = forumPostFactory.createPseudonymousPost(parentId,
|
||||
forum, localAuthor, authorKey, "text/plain",
|
||||
timestamp, body);
|
||||
}
|
||||
} catch (GeneralSecurityException e) {
|
||||
|
||||
Reference in New Issue
Block a user