mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-18 05:39:53 +01:00
Add transactional variant of getGroupCount().
This commit is contained in:
@@ -43,6 +43,11 @@ public interface ConversationManager {
|
|||||||
*/
|
*/
|
||||||
GroupCount getGroupCount(ContactId c) throws DbException;
|
GroupCount getGroupCount(ContactId c) throws DbException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the unified group count for all private conversation messages.
|
||||||
|
*/
|
||||||
|
GroupCount getGroupCount(Transaction txn, ContactId c) throws DbException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Deletes all messages exchanged with the given contact.
|
* Deletes all messages exchanged with the given contact.
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -57,20 +57,21 @@ class ConversationManagerImpl implements ConversationManager {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public GroupCount getGroupCount(ContactId contactId) throws DbException {
|
public GroupCount getGroupCount(ContactId contactId) throws DbException {
|
||||||
|
return db.transactionWithResult(true, txn ->
|
||||||
|
getGroupCount(txn, contactId));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public GroupCount getGroupCount(Transaction txn, ContactId contactId)
|
||||||
|
throws DbException {
|
||||||
int msgCount = 0, unreadCount = 0;
|
int msgCount = 0, unreadCount = 0;
|
||||||
long latestTime = 0;
|
long latestTime = 0;
|
||||||
Transaction txn = db.startTransaction(true);
|
for (ConversationClient client : clients) {
|
||||||
try {
|
GroupCount count = client.getGroupCount(txn, contactId);
|
||||||
for (ConversationClient client : clients) {
|
msgCount += count.getMsgCount();
|
||||||
GroupCount count = client.getGroupCount(txn, contactId);
|
unreadCount += count.getUnreadCount();
|
||||||
msgCount += count.getMsgCount();
|
if (count.getLatestMsgTime() > latestTime)
|
||||||
unreadCount += count.getUnreadCount();
|
latestTime = count.getLatestMsgTime();
|
||||||
if (count.getLatestMsgTime() > latestTime)
|
|
||||||
latestTime = count.getLatestMsgTime();
|
|
||||||
}
|
|
||||||
db.commitTransaction(txn);
|
|
||||||
} finally {
|
|
||||||
db.endTransaction(txn);
|
|
||||||
}
|
}
|
||||||
return new GroupCount(msgCount, unreadCount, latestTime);
|
return new GroupCount(msgCount, unreadCount, latestTime);
|
||||||
}
|
}
|
||||||
@@ -87,8 +88,8 @@ class ConversationManagerImpl implements ConversationManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public DeletionResult deleteMessages(ContactId c, Collection<MessageId> toDelete)
|
public DeletionResult deleteMessages(ContactId c,
|
||||||
throws DbException {
|
Collection<MessageId> toDelete) throws DbException {
|
||||||
return db.transactionWithResult(false, txn -> {
|
return db.transactionWithResult(false, txn -> {
|
||||||
DeletionResult result = new DeletionResult();
|
DeletionResult result = new DeletionResult();
|
||||||
for (ConversationClient client : clients) {
|
for (ConversationClient client : clients) {
|
||||||
|
|||||||
Reference in New Issue
Block a user