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