mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-11 18:29:05 +01:00
Merge branch 'desktop-98-transactional' into 'master'
Add transactional versions of some API calls for Briar Desktop See merge request briar/briar!1557
This commit is contained in:
@@ -107,6 +107,12 @@ public interface ContactManager {
|
||||
*/
|
||||
String getHandshakeLink() throws DbException;
|
||||
|
||||
/**
|
||||
* Returns the handshake link that needs to be sent to a contact we want
|
||||
* to add.
|
||||
*/
|
||||
String getHandshakeLink(Transaction txn) throws DbException;
|
||||
|
||||
/**
|
||||
* Creates a {@link PendingContact} from the given handshake link and
|
||||
* alias, adds it to the database and returns it.
|
||||
|
||||
@@ -121,8 +121,12 @@ class ContactManagerImpl implements ContactManager, EventListener {
|
||||
|
||||
@Override
|
||||
public String getHandshakeLink() throws DbException {
|
||||
KeyPair keyPair = db.transactionWithResult(true,
|
||||
identityManager::getHandshakeKeys);
|
||||
return db.transactionWithResult(true, this::getHandshakeLink);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHandshakeLink(Transaction txn) throws DbException {
|
||||
KeyPair keyPair = identityManager.getHandshakeKeys(txn);
|
||||
return pendingContactFactory.createHandshakeLink(keyPair.getPublic());
|
||||
}
|
||||
|
||||
|
||||
@@ -38,6 +38,15 @@ public interface ConversationManager {
|
||||
Collection<ConversationMessageHeader> getMessageHeaders(ContactId c)
|
||||
throws DbException;
|
||||
|
||||
/**
|
||||
* Returns the headers of all messages in the given private conversation.
|
||||
* <p>
|
||||
* Only {@link MessagingManager} returns only headers.
|
||||
* The others also return the message text.
|
||||
*/
|
||||
Collection<ConversationMessageHeader> getMessageHeaders(Transaction txn, ContactId c)
|
||||
throws DbException;
|
||||
|
||||
/**
|
||||
* Returns the unified group count for all private conversation messages.
|
||||
*/
|
||||
@@ -72,6 +81,9 @@ public interface ConversationManager {
|
||||
void setReadFlag(GroupId g, MessageId m, boolean read)
|
||||
throws DbException;
|
||||
|
||||
void setReadFlag(Transaction txn, GroupId g, MessageId m, boolean read)
|
||||
throws DbException;
|
||||
|
||||
/**
|
||||
* Returns a timestamp for an outgoing message, which is later than the
|
||||
* timestamp of any message in the conversation with the given contact.
|
||||
|
||||
@@ -74,6 +74,13 @@ public interface MessagingManager extends ConversationClient {
|
||||
@Nullable
|
||||
String getMessageText(MessageId m) throws DbException;
|
||||
|
||||
/**
|
||||
* Returns the text of the private message with the given ID, or null if
|
||||
* the private message has no text.
|
||||
*/
|
||||
@Nullable
|
||||
String getMessageText(Transaction txn, MessageId m) throws DbException;
|
||||
|
||||
/**
|
||||
* Returns the private message format supported by the given contact.
|
||||
*/
|
||||
|
||||
@@ -58,15 +58,16 @@ class ConversationManagerImpl implements ConversationManager {
|
||||
@Override
|
||||
public Collection<ConversationMessageHeader> getMessageHeaders(ContactId c)
|
||||
throws DbException {
|
||||
return db.transactionWithResult(true,
|
||||
txn -> getMessageHeaders(txn, c));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<ConversationMessageHeader> getMessageHeaders(Transaction txn, ContactId c)
|
||||
throws DbException {
|
||||
List<ConversationMessageHeader> messages = new ArrayList<>();
|
||||
Transaction txn = db.startTransaction(true);
|
||||
try {
|
||||
for (ConversationClient client : clients) {
|
||||
messages.addAll(client.getMessageHeaders(txn, c));
|
||||
}
|
||||
db.commitTransaction(txn);
|
||||
} finally {
|
||||
db.endTransaction(txn);
|
||||
for (ConversationClient client : clients) {
|
||||
messages.addAll(client.getMessageHeaders(txn, c));
|
||||
}
|
||||
return messages;
|
||||
}
|
||||
@@ -125,10 +126,14 @@ class ConversationManagerImpl implements ConversationManager {
|
||||
@Override
|
||||
public void setReadFlag(GroupId g, MessageId m, boolean read)
|
||||
throws DbException {
|
||||
db.transaction(false, txn -> {
|
||||
boolean wasRead = messageTracker.setReadFlag(txn, g, m, read);
|
||||
if (read && !wasRead) db.startCleanupTimer(txn, m);
|
||||
});
|
||||
db.transaction(false, txn -> setReadFlag(txn, g, m, read));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setReadFlag(Transaction txn, GroupId g, MessageId m, boolean read)
|
||||
throws DbException {
|
||||
boolean wasRead = messageTracker.setReadFlag(txn, g, m, read);
|
||||
if (read && !wasRead) db.startCleanupTimer(txn, m);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -466,8 +466,14 @@ class MessagingManagerImpl implements MessagingManager, IncomingMessageHook,
|
||||
|
||||
@Override
|
||||
public String getMessageText(MessageId m) throws DbException {
|
||||
return db.transactionWithNullableResult(true, txn ->
|
||||
getMessageText(txn, m));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMessageText(Transaction txn, MessageId m) throws DbException {
|
||||
try {
|
||||
BdfList body = clientHelper.getMessageAsList(m);
|
||||
BdfList body = clientHelper.getMessageAsList(txn, m);
|
||||
if (body.size() == 1) return body.getString(0); // Legacy format
|
||||
else return body.getOptionalString(1);
|
||||
} catch (FormatException e) {
|
||||
|
||||
Reference in New Issue
Block a user