Broadcast an event when an author's rating changes.

This commit is contained in:
akwizgran
2011-10-26 15:40:38 +01:00
parent 097d11f471
commit 94722a9f2a
3 changed files with 50 additions and 7 deletions

View File

@@ -35,6 +35,7 @@ import net.sf.briar.api.db.event.ContactRemovedEvent;
import net.sf.briar.api.db.event.DatabaseEvent;
import net.sf.briar.api.db.event.DatabaseListener;
import net.sf.briar.api.db.event.MessagesAddedEvent;
import net.sf.briar.api.db.event.RatingChangedEvent;
import net.sf.briar.api.db.event.SubscriptionsUpdatedEvent;
import net.sf.briar.api.db.event.TransportsUpdatedEvent;
import net.sf.briar.api.protocol.Ack;
@@ -1233,6 +1234,7 @@ DatabaseCleaner.Callback {
}
public void setRating(AuthorId a, Rating r) throws DbException {
boolean changed;
messageLock.writeLock().lock();
try {
ratingLock.writeLock().lock();
@@ -1240,6 +1242,7 @@ DatabaseCleaner.Callback {
T txn = db.startTransaction();
try {
Rating old = db.setRating(txn, a, r);
changed = (old != r);
// Update the sendability of the author's messages
if(r == Rating.GOOD && old != Rating.GOOD)
updateAuthorSendability(txn, a, true);
@@ -1256,6 +1259,8 @@ DatabaseCleaner.Callback {
} finally {
messageLock.writeLock().unlock();
}
// Call the listeners outside the lock
if(changed) callListeners(new RatingChangedEvent(a, r));
}
public void setSeen(ContactId c, Collection<MessageId> seen)