mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-12 18:59:06 +01:00
Added new database events to support updating the UI.
This commit is contained in:
@@ -0,0 +1,17 @@
|
||||
package net.sf.briar.api.db.event;
|
||||
|
||||
import net.sf.briar.api.messaging.GroupId;
|
||||
|
||||
/** An event that is broadcast when the user subscribes to a group. */
|
||||
public class SubscriptionAddedEvent extends DatabaseEvent {
|
||||
|
||||
private final GroupId groupId;
|
||||
|
||||
public SubscriptionAddedEvent(GroupId groupId) {
|
||||
this.groupId = groupId;
|
||||
}
|
||||
|
||||
public GroupId getGroupId() {
|
||||
return groupId;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package net.sf.briar.api.db.event;
|
||||
|
||||
import net.sf.briar.api.messaging.GroupId;
|
||||
|
||||
/** An event that is broadcast when the user unsubscribes from a group. */
|
||||
public class SubscriptionRemovedEvent extends DatabaseEvent {
|
||||
|
||||
private final GroupId groupId;
|
||||
|
||||
public SubscriptionRemovedEvent(GroupId groupId) {
|
||||
this.groupId = groupId;
|
||||
}
|
||||
|
||||
public GroupId getGroupId() {
|
||||
return groupId;
|
||||
}
|
||||
}
|
||||
@@ -50,6 +50,8 @@ import net.sf.briar.api.db.event.RatingChangedEvent;
|
||||
import net.sf.briar.api.db.event.RemoteRetentionTimeUpdatedEvent;
|
||||
import net.sf.briar.api.db.event.RemoteSubscriptionsUpdatedEvent;
|
||||
import net.sf.briar.api.db.event.RemoteTransportsUpdatedEvent;
|
||||
import net.sf.briar.api.db.event.SubscriptionAddedEvent;
|
||||
import net.sf.briar.api.db.event.SubscriptionRemovedEvent;
|
||||
import net.sf.briar.api.db.event.TransportAddedEvent;
|
||||
import net.sf.briar.api.db.event.TransportRemovedEvent;
|
||||
import net.sf.briar.api.lifecycle.ShutdownManager;
|
||||
@@ -1778,15 +1780,14 @@ DatabaseCleaner.Callback {
|
||||
}
|
||||
|
||||
public boolean subscribe(Group g) throws DbException {
|
||||
boolean added = false;
|
||||
subscriptionLock.writeLock().lock();
|
||||
try {
|
||||
T txn = db.startTransaction();
|
||||
try {
|
||||
boolean added = false;
|
||||
if(!db.containsSubscription(txn, g.getId()))
|
||||
added = db.addSubscription(txn, g);
|
||||
db.commitTransaction(txn);
|
||||
return added;
|
||||
} catch(DbException e) {
|
||||
db.abortTransaction(txn);
|
||||
throw e;
|
||||
@@ -1794,7 +1795,8 @@ DatabaseCleaner.Callback {
|
||||
} finally {
|
||||
subscriptionLock.writeLock().unlock();
|
||||
}
|
||||
// Listeners will be notified when the group's visibility is set
|
||||
if(added) callListeners(new SubscriptionAddedEvent(g.getId()));
|
||||
return added;
|
||||
}
|
||||
|
||||
public void unsubscribe(GroupId g) throws DbException {
|
||||
@@ -1820,6 +1822,7 @@ DatabaseCleaner.Callback {
|
||||
} finally {
|
||||
messageLock.writeLock().unlock();
|
||||
}
|
||||
callListeners(new SubscriptionRemovedEvent(g));
|
||||
callListeners(new LocalSubscriptionsUpdatedEvent(affected));
|
||||
}
|
||||
|
||||
|
||||
@@ -27,6 +27,8 @@ import net.sf.briar.api.db.event.DatabaseListener;
|
||||
import net.sf.briar.api.db.event.LocalSubscriptionsUpdatedEvent;
|
||||
import net.sf.briar.api.db.event.MessageAddedEvent;
|
||||
import net.sf.briar.api.db.event.RatingChangedEvent;
|
||||
import net.sf.briar.api.db.event.SubscriptionAddedEvent;
|
||||
import net.sf.briar.api.db.event.SubscriptionRemovedEvent;
|
||||
import net.sf.briar.api.lifecycle.ShutdownManager;
|
||||
import net.sf.briar.api.messaging.Ack;
|
||||
import net.sf.briar.api.messaging.Author;
|
||||
@@ -150,6 +152,9 @@ public abstract class DatabaseComponentTest extends BriarTestCase {
|
||||
oneOf(database).containsSubscription(txn, groupId);
|
||||
will(returnValue(false));
|
||||
oneOf(database).addSubscription(txn, group);
|
||||
will(returnValue(true));
|
||||
oneOf(listener).eventOccurred(with(any(
|
||||
SubscriptionAddedEvent.class)));
|
||||
// subscribe(group) again
|
||||
oneOf(database).containsSubscription(txn, groupId);
|
||||
will(returnValue(true));
|
||||
@@ -167,6 +172,8 @@ public abstract class DatabaseComponentTest extends BriarTestCase {
|
||||
oneOf(database).getVisibility(txn, groupId);
|
||||
will(returnValue(Collections.emptyList()));
|
||||
oneOf(database).removeSubscription(txn, groupId);
|
||||
oneOf(listener).eventOccurred(with(any(
|
||||
SubscriptionRemovedEvent.class)));
|
||||
oneOf(listener).eventOccurred(with(any(
|
||||
LocalSubscriptionsUpdatedEvent.class)));
|
||||
// removeContact(contactId)
|
||||
|
||||
Reference in New Issue
Block a user