Use commit action to add contacts to SharingController.

This commit is contained in:
akwizgran
2021-01-27 15:13:20 +00:00
committed by Torsten Grote
parent f2eca0fdb6
commit 98619df867
3 changed files with 14 additions and 26 deletions

View File

@@ -245,20 +245,16 @@ class GroupViewModel extends ThreadListViewModel<GroupMessageItem> {
}
public void loadSharingContacts() {
runOnDbThread(() -> {
try {
Collection<GroupMember> members =
privateGroupManager.getMembers(groupId);
Collection<ContactId> contactIds = new ArrayList<>();
for (GroupMember m : members) {
if (m.getContactId() != null)
contactIds.add(m.getContactId());
}
sharingController.addAll(contactIds);
} catch (DbException e) {
logException(LOG, WARNING, e);
runOnDbThread(true, txn -> {
Collection<GroupMember> members =
privateGroupManager.getMembers(txn, groupId);
Collection<ContactId> contactIds = new ArrayList<>();
for (GroupMember m : members) {
if (m.getContactId() != null)
contactIds.add(m.getContactId());
}
});
txn.attach(() -> sharingController.addAll(contactIds));
}, e -> logException(LOG, WARNING, e));
}
void deletePrivateGroup() {

View File

@@ -1,7 +1,6 @@
package org.briarproject.briar.android.sharing;
import org.briarproject.bramble.api.contact.ContactId;
import org.briarproject.bramble.api.db.DatabaseExecutor;
import org.briarproject.bramble.api.event.EventBus;
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
@@ -28,7 +27,7 @@ public interface SharingController {
/**
* Adds a collection of contacts to be tracked.
*/
@DatabaseExecutor
@UiThread
void addAll(Collection<ContactId> contacts);
/**

View File

@@ -2,14 +2,12 @@ package org.briarproject.briar.android.sharing;
import org.briarproject.bramble.api.connection.ConnectionRegistry;
import org.briarproject.bramble.api.contact.ContactId;
import org.briarproject.bramble.api.db.DatabaseExecutor;
import org.briarproject.bramble.api.event.Event;
import org.briarproject.bramble.api.event.EventBus;
import org.briarproject.bramble.api.event.EventListener;
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
import org.briarproject.bramble.api.plugin.event.ContactConnectedEvent;
import org.briarproject.bramble.api.plugin.event.ContactDisconnectedEvent;
import org.briarproject.bramble.api.system.AndroidExecutor;
import java.util.Collection;
import java.util.HashSet;
@@ -26,7 +24,6 @@ public class SharingControllerImpl implements SharingController, EventListener {
private final EventBus eventBus;
private final ConnectionRegistry connectionRegistry;
private final AndroidExecutor executor;
// UI thread
private final Set<ContactId> contacts = new HashSet<>();
@@ -35,11 +32,9 @@ public class SharingControllerImpl implements SharingController, EventListener {
@Inject
SharingControllerImpl(EventBus eventBus,
ConnectionRegistry connectionRegistry,
AndroidExecutor executor) {
ConnectionRegistry connectionRegistry) {
this.eventBus = eventBus;
this.connectionRegistry = connectionRegistry;
this.executor = executor;
eventBus.addListener(this);
}
@@ -78,13 +73,11 @@ public class SharingControllerImpl implements SharingController, EventListener {
return online;
}
@UiThread
@Override
@DatabaseExecutor
public void addAll(Collection<ContactId> c) {
executor.runOnUiThread(() -> {
contacts.addAll(c);
updateLiveData();
});
contacts.addAll(c);
updateLiveData();
}
@UiThread