mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-20 06:39:54 +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.RemoteRetentionTimeUpdatedEvent;
|
||||||
import net.sf.briar.api.db.event.RemoteSubscriptionsUpdatedEvent;
|
import net.sf.briar.api.db.event.RemoteSubscriptionsUpdatedEvent;
|
||||||
import net.sf.briar.api.db.event.RemoteTransportsUpdatedEvent;
|
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.TransportAddedEvent;
|
||||||
import net.sf.briar.api.db.event.TransportRemovedEvent;
|
import net.sf.briar.api.db.event.TransportRemovedEvent;
|
||||||
import net.sf.briar.api.lifecycle.ShutdownManager;
|
import net.sf.briar.api.lifecycle.ShutdownManager;
|
||||||
@@ -1778,15 +1780,14 @@ DatabaseCleaner.Callback {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public boolean subscribe(Group g) throws DbException {
|
public boolean subscribe(Group g) throws DbException {
|
||||||
|
boolean added = false;
|
||||||
subscriptionLock.writeLock().lock();
|
subscriptionLock.writeLock().lock();
|
||||||
try {
|
try {
|
||||||
T txn = db.startTransaction();
|
T txn = db.startTransaction();
|
||||||
try {
|
try {
|
||||||
boolean added = false;
|
|
||||||
if(!db.containsSubscription(txn, g.getId()))
|
if(!db.containsSubscription(txn, g.getId()))
|
||||||
added = db.addSubscription(txn, g);
|
added = db.addSubscription(txn, g);
|
||||||
db.commitTransaction(txn);
|
db.commitTransaction(txn);
|
||||||
return added;
|
|
||||||
} catch(DbException e) {
|
} catch(DbException e) {
|
||||||
db.abortTransaction(txn);
|
db.abortTransaction(txn);
|
||||||
throw e;
|
throw e;
|
||||||
@@ -1794,7 +1795,8 @@ DatabaseCleaner.Callback {
|
|||||||
} finally {
|
} finally {
|
||||||
subscriptionLock.writeLock().unlock();
|
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 {
|
public void unsubscribe(GroupId g) throws DbException {
|
||||||
@@ -1820,6 +1822,7 @@ DatabaseCleaner.Callback {
|
|||||||
} finally {
|
} finally {
|
||||||
messageLock.writeLock().unlock();
|
messageLock.writeLock().unlock();
|
||||||
}
|
}
|
||||||
|
callListeners(new SubscriptionRemovedEvent(g));
|
||||||
callListeners(new LocalSubscriptionsUpdatedEvent(affected));
|
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.LocalSubscriptionsUpdatedEvent;
|
||||||
import net.sf.briar.api.db.event.MessageAddedEvent;
|
import net.sf.briar.api.db.event.MessageAddedEvent;
|
||||||
import net.sf.briar.api.db.event.RatingChangedEvent;
|
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.lifecycle.ShutdownManager;
|
||||||
import net.sf.briar.api.messaging.Ack;
|
import net.sf.briar.api.messaging.Ack;
|
||||||
import net.sf.briar.api.messaging.Author;
|
import net.sf.briar.api.messaging.Author;
|
||||||
@@ -150,6 +152,9 @@ public abstract class DatabaseComponentTest extends BriarTestCase {
|
|||||||
oneOf(database).containsSubscription(txn, groupId);
|
oneOf(database).containsSubscription(txn, groupId);
|
||||||
will(returnValue(false));
|
will(returnValue(false));
|
||||||
oneOf(database).addSubscription(txn, group);
|
oneOf(database).addSubscription(txn, group);
|
||||||
|
will(returnValue(true));
|
||||||
|
oneOf(listener).eventOccurred(with(any(
|
||||||
|
SubscriptionAddedEvent.class)));
|
||||||
// subscribe(group) again
|
// subscribe(group) again
|
||||||
oneOf(database).containsSubscription(txn, groupId);
|
oneOf(database).containsSubscription(txn, groupId);
|
||||||
will(returnValue(true));
|
will(returnValue(true));
|
||||||
@@ -167,6 +172,8 @@ public abstract class DatabaseComponentTest extends BriarTestCase {
|
|||||||
oneOf(database).getVisibility(txn, groupId);
|
oneOf(database).getVisibility(txn, groupId);
|
||||||
will(returnValue(Collections.emptyList()));
|
will(returnValue(Collections.emptyList()));
|
||||||
oneOf(database).removeSubscription(txn, groupId);
|
oneOf(database).removeSubscription(txn, groupId);
|
||||||
|
oneOf(listener).eventOccurred(with(any(
|
||||||
|
SubscriptionRemovedEvent.class)));
|
||||||
oneOf(listener).eventOccurred(with(any(
|
oneOf(listener).eventOccurred(with(any(
|
||||||
LocalSubscriptionsUpdatedEvent.class)));
|
LocalSubscriptionsUpdatedEvent.class)));
|
||||||
// removeContact(contactId)
|
// removeContact(contactId)
|
||||||
|
|||||||
Reference in New Issue
Block a user