mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-14 11:49:04 +01:00
Moved subscription updates to the client layer.
This commit is contained in:
@@ -17,11 +17,10 @@ import org.briarproject.api.db.NoSuchGroupException;
|
||||
import org.briarproject.api.event.Event;
|
||||
import org.briarproject.api.event.EventBus;
|
||||
import org.briarproject.api.event.EventListener;
|
||||
import org.briarproject.api.event.GroupAddedEvent;
|
||||
import org.briarproject.api.event.GroupRemovedEvent;
|
||||
import org.briarproject.api.event.MessageValidatedEvent;
|
||||
import org.briarproject.api.forum.Forum;
|
||||
import org.briarproject.api.forum.ForumManager;
|
||||
import org.briarproject.api.sync.GroupId;
|
||||
import org.briarproject.api.forum.ForumSharingManager;
|
||||
import org.briarproject.api.sync.ClientId;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
@@ -44,7 +43,7 @@ implements EventListener, OnItemClickListener {
|
||||
private ListView list = null;
|
||||
|
||||
// Fields that are accessed from background threads must be volatile
|
||||
@Inject private volatile ForumManager forumManager;
|
||||
@Inject private volatile ForumSharingManager forumSharingManager;
|
||||
@Inject private volatile EventBus eventBus;
|
||||
|
||||
@Override
|
||||
@@ -76,11 +75,10 @@ implements EventListener, OnItemClickListener {
|
||||
Collection<ForumContacts> available =
|
||||
new ArrayList<ForumContacts>();
|
||||
long now = System.currentTimeMillis();
|
||||
for (Forum f : forumManager.getAvailableForums()) {
|
||||
for (Forum f : forumSharingManager.getAvailableForums()) {
|
||||
try {
|
||||
GroupId id = f.getId();
|
||||
Collection<Contact> c =
|
||||
forumManager.getSubscribers(id);
|
||||
forumSharingManager.getSharedBy(f.getId());
|
||||
available.add(new ForumContacts(f, c));
|
||||
} catch (NoSuchGroupException e) {
|
||||
// Continue
|
||||
@@ -122,17 +120,12 @@ implements EventListener, OnItemClickListener {
|
||||
}
|
||||
|
||||
public void eventOccurred(Event e) {
|
||||
// TODO: What other events are needed here?
|
||||
if (e instanceof GroupAddedEvent) {
|
||||
GroupAddedEvent g = (GroupAddedEvent) e;
|
||||
if (g.getGroup().getClientId().equals(forumManager.getClientId())) {
|
||||
LOG.info("Forum added, reloading");
|
||||
loadForums();
|
||||
}
|
||||
} else if (e instanceof GroupRemovedEvent) {
|
||||
GroupRemovedEvent g = (GroupRemovedEvent) e;
|
||||
if (g.getGroup().getClientId().equals(forumManager.getClientId())) {
|
||||
LOG.info("Forum removed, reloading");
|
||||
if (e instanceof MessageValidatedEvent) {
|
||||
MessageValidatedEvent m = (MessageValidatedEvent) e;
|
||||
ClientId c = m.getClientId();
|
||||
if (m.isValid() && !m.isLocal()
|
||||
&& c.equals(forumSharingManager.getClientId())) {
|
||||
LOG.info("Available forums updated, reloading");
|
||||
loadForums();
|
||||
}
|
||||
}
|
||||
@@ -141,20 +134,20 @@ implements EventListener, OnItemClickListener {
|
||||
public void onItemClick(AdapterView<?> parent, View view, int position,
|
||||
long id) {
|
||||
AvailableForumsItem item = adapter.getItem(position);
|
||||
Collection<ContactId> visible = new ArrayList<ContactId>();
|
||||
for (Contact c : item.getContacts()) visible.add(c.getId());
|
||||
addSubscription(item.getForum(), visible);
|
||||
Collection<ContactId> shared = new ArrayList<ContactId>();
|
||||
for (Contact c : item.getContacts()) shared.add(c.getId());
|
||||
subscribe(item.getForum(), shared);
|
||||
String subscribed = getString(R.string.subscribed_toast);
|
||||
Toast.makeText(this, subscribed, LENGTH_SHORT).show();
|
||||
loadForums();
|
||||
}
|
||||
|
||||
private void addSubscription(final Forum f,
|
||||
final Collection<ContactId> visible) {
|
||||
private void subscribe(final Forum f, final Collection<ContactId> shared) {
|
||||
runOnDbThread(new Runnable() {
|
||||
public void run() {
|
||||
try {
|
||||
forumManager.addForum(f);
|
||||
forumManager.setVisibility(f.getId(), visible);
|
||||
forumSharingManager.addForum(f);
|
||||
forumSharingManager.setSharedWith(f.getId(), shared);
|
||||
} catch (DbException e) {
|
||||
if (LOG.isLoggable(WARNING))
|
||||
LOG.log(WARNING, e.toString(), e);
|
||||
|
||||
@@ -18,7 +18,7 @@ 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.ForumManager;
|
||||
import org.briarproject.api.forum.ForumSharingManager;
|
||||
import org.briarproject.util.StringUtils;
|
||||
|
||||
import java.util.logging.Logger;
|
||||
@@ -51,7 +51,7 @@ implements OnEditorActionListener, OnClickListener {
|
||||
private TextView feedback = null;
|
||||
|
||||
// Fields that are accessed from background threads must be volatile
|
||||
@Inject private volatile ForumManager forumManager;
|
||||
@Inject private volatile ForumSharingManager forumSharingManager;
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle state) {
|
||||
@@ -138,8 +138,8 @@ implements OnEditorActionListener, OnClickListener {
|
||||
public void run() {
|
||||
try {
|
||||
long now = System.currentTimeMillis();
|
||||
Forum f = forumManager.createForum(name);
|
||||
forumManager.addForum(f);
|
||||
Forum f = forumSharingManager.createForum(name);
|
||||
forumSharingManager.addForum(f);
|
||||
long duration = System.currentTimeMillis() - now;
|
||||
if (LOG.isLoggable(INFO))
|
||||
LOG.info("Storing forum took " + duration + " ms");
|
||||
|
||||
@@ -25,6 +25,7 @@ import org.briarproject.android.util.LayoutUtils;
|
||||
import org.briarproject.android.util.ListLoadingProgressBar;
|
||||
import org.briarproject.api.db.DbException;
|
||||
import org.briarproject.api.db.NoSuchGroupException;
|
||||
import org.briarproject.api.event.ContactRemovedEvent;
|
||||
import org.briarproject.api.event.Event;
|
||||
import org.briarproject.api.event.GroupAddedEvent;
|
||||
import org.briarproject.api.event.GroupRemovedEvent;
|
||||
@@ -32,6 +33,7 @@ import org.briarproject.api.event.MessageValidatedEvent;
|
||||
import org.briarproject.api.forum.Forum;
|
||||
import org.briarproject.api.forum.ForumManager;
|
||||
import org.briarproject.api.forum.ForumPostHeader;
|
||||
import org.briarproject.api.forum.ForumSharingManager;
|
||||
import org.briarproject.api.sync.ClientId;
|
||||
import org.briarproject.api.sync.GroupId;
|
||||
|
||||
@@ -81,8 +83,8 @@ public class ForumListFragment extends BaseEventFragment implements
|
||||
private ImageButton newForumButton = null;
|
||||
|
||||
// Fields that are accessed from background threads must be volatile
|
||||
@Inject
|
||||
private volatile ForumManager forumManager;
|
||||
@Inject private volatile ForumManager forumManager;
|
||||
@Inject private volatile ForumSharingManager forumSharingManager;
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
@@ -171,7 +173,8 @@ public class ForumListFragment extends BaseEventFragment implements
|
||||
// Continue
|
||||
}
|
||||
}
|
||||
int available = forumManager.getAvailableForums().size();
|
||||
int available =
|
||||
forumSharingManager.getAvailableForums().size();
|
||||
long duration = System.currentTimeMillis() - now;
|
||||
if (LOG.isLoggable(INFO))
|
||||
LOG.info("Full load took " + duration + " ms");
|
||||
@@ -252,14 +255,9 @@ public class ForumListFragment extends BaseEventFragment implements
|
||||
}
|
||||
|
||||
public void eventOccurred(Event e) {
|
||||
// TODO: What other events are needed here?
|
||||
if (e instanceof MessageValidatedEvent) {
|
||||
MessageValidatedEvent m = (MessageValidatedEvent) e;
|
||||
ClientId c = m.getClientId();
|
||||
if (m.isValid() && c.equals(forumManager.getClientId())) {
|
||||
LOG.info("Message added, reloading");
|
||||
loadHeaders(m.getMessage().getGroupId());
|
||||
}
|
||||
if (e instanceof ContactRemovedEvent) {
|
||||
LOG.info("Contact removed, reloading");
|
||||
loadAvailable();
|
||||
} else if (e instanceof GroupAddedEvent) {
|
||||
GroupAddedEvent g = (GroupAddedEvent) e;
|
||||
if (g.getGroup().getClientId().equals(forumManager.getClientId())) {
|
||||
@@ -272,6 +270,18 @@ public class ForumListFragment extends BaseEventFragment implements
|
||||
LOG.info("Forum removed, reloading");
|
||||
loadHeaders();
|
||||
}
|
||||
} else if (e instanceof MessageValidatedEvent) {
|
||||
MessageValidatedEvent m = (MessageValidatedEvent) e;
|
||||
if (m.isValid()) {
|
||||
ClientId c = m.getClientId();
|
||||
if (c.equals(forumManager.getClientId())) {
|
||||
LOG.info("Forum post added, reloading");
|
||||
loadHeaders(m.getMessage().getGroupId());
|
||||
} else if (c.equals(forumSharingManager.getClientId())) {
|
||||
LOG.info("Available forums updated, reloading");
|
||||
loadAvailable();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -319,7 +329,8 @@ public class ForumListFragment extends BaseEventFragment implements
|
||||
public void run() {
|
||||
try {
|
||||
long now = System.currentTimeMillis();
|
||||
int available = forumManager.getAvailableForums().size();
|
||||
int available =
|
||||
forumSharingManager.getAvailableForums().size();
|
||||
long duration = System.currentTimeMillis() - now;
|
||||
if (LOG.isLoggable(INFO))
|
||||
LOG.info("Loading available took " + duration + " ms");
|
||||
@@ -363,22 +374,22 @@ public class ForumListFragment extends BaseEventFragment implements
|
||||
ContextMenuInfo info = menuItem.getMenuInfo();
|
||||
int position = ((AdapterContextMenuInfo) info).position;
|
||||
ForumListItem item = adapter.getItem(position);
|
||||
removeSubscription(item.getForum());
|
||||
unsubscribe(item.getForum());
|
||||
String unsubscribed = getString(R.string.unsubscribed_toast);
|
||||
Toast.makeText(getContext(), unsubscribed, LENGTH_SHORT).show();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private void removeSubscription(final Forum f) {
|
||||
private void unsubscribe(final Forum f) {
|
||||
listener.runOnDbThread(new Runnable() {
|
||||
public void run() {
|
||||
try {
|
||||
long now = System.currentTimeMillis();
|
||||
forumManager.removeForum(f);
|
||||
forumSharingManager.removeForum(f);
|
||||
long duration = System.currentTimeMillis() - now;
|
||||
if (LOG.isLoggable(INFO))
|
||||
LOG.info("Removing group took " + duration + " ms");
|
||||
LOG.info("Removing forum took " + duration + " ms");
|
||||
} catch (DbException e) {
|
||||
if (LOG.isLoggable(WARNING))
|
||||
LOG.log(WARNING, e.toString(), e);
|
||||
|
||||
@@ -19,7 +19,7 @@ import org.briarproject.api.contact.Contact;
|
||||
import org.briarproject.api.contact.ContactId;
|
||||
import org.briarproject.api.contact.ContactManager;
|
||||
import org.briarproject.api.db.DbException;
|
||||
import org.briarproject.api.forum.ForumManager;
|
||||
import org.briarproject.api.forum.ForumSharingManager;
|
||||
import org.briarproject.api.sync.GroupId;
|
||||
|
||||
import java.util.Collection;
|
||||
@@ -52,7 +52,7 @@ SelectContactsDialog.Listener {
|
||||
|
||||
// Fields that are accessed from background threads must be volatile
|
||||
@Inject private volatile ContactManager contactManager;
|
||||
@Inject private volatile ForumManager forumManager;
|
||||
@Inject private volatile ForumSharingManager forumSharingManager;
|
||||
private volatile GroupId groupId = null;
|
||||
private volatile Collection<Contact> contacts = null;
|
||||
private volatile Collection<ContactId> selected = null;
|
||||
@@ -139,7 +139,7 @@ SelectContactsDialog.Listener {
|
||||
try {
|
||||
long now = System.currentTimeMillis();
|
||||
contacts = contactManager.getContacts();
|
||||
selected = forumManager.getVisibility(groupId);
|
||||
selected = forumSharingManager.getSharedWith(groupId);
|
||||
long duration = System.currentTimeMillis() - now;
|
||||
if (LOG.isLoggable(INFO))
|
||||
LOG.info("Load took " + duration + " ms");
|
||||
@@ -175,8 +175,9 @@ SelectContactsDialog.Listener {
|
||||
public void run() {
|
||||
try {
|
||||
long now = System.currentTimeMillis();
|
||||
forumManager.setVisibleToAll(groupId, all);
|
||||
if (!all) forumManager.setVisibility(groupId, selected);
|
||||
if (all) forumSharingManager.setSharedWithAll(groupId);
|
||||
else forumSharingManager.setSharedWith(groupId,
|
||||
selected);
|
||||
long duration = System.currentTimeMillis() - now;
|
||||
if (LOG.isLoggable(INFO))
|
||||
LOG.info("Update took " + duration + " ms");
|
||||
|
||||
Reference in New Issue
Block a user