From 16fc4f45279d6b7148bacb8b4bc125b6cc9a03e5 Mon Sep 17 00:00:00 2001 From: akwizgran Date: Wed, 3 Aug 2022 16:36:32 +0100 Subject: [PATCH] Allow read-only transaction when not marking message as sent. --- .../org/briarproject/bramble/api/db/DatabaseComponent.java | 2 ++ .../org/briarproject/bramble/db/DatabaseComponentImpl.java | 4 +++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/bramble-api/src/main/java/org/briarproject/bramble/api/db/DatabaseComponent.java b/bramble-api/src/main/java/org/briarproject/bramble/api/db/DatabaseComponent.java index c28c07fe9..f68d666d6 100644 --- a/bramble-api/src/main/java/org/briarproject/bramble/api/db/DatabaseComponent.java +++ b/bramble-api/src/main/java/org/briarproject/bramble/api/db/DatabaseComponent.java @@ -492,6 +492,8 @@ public interface DatabaseComponent extends TransactionManager { * Returns the message with the given ID for transmission to the given * contact over a transport with the given maximum latency. Returns null * if the message is no longer visible to the contact. + *

+ * Read-only if {@code markAsSent} is false. * * @param markAsSent True if the message should be marked as sent. * If false it can be marked as sent by calling diff --git a/bramble-core/src/main/java/org/briarproject/bramble/db/DatabaseComponentImpl.java b/bramble-core/src/main/java/org/briarproject/bramble/db/DatabaseComponentImpl.java index cfc20ecce..01c1497fe 100644 --- a/bramble-core/src/main/java/org/briarproject/bramble/db/DatabaseComponentImpl.java +++ b/bramble-core/src/main/java/org/briarproject/bramble/db/DatabaseComponentImpl.java @@ -746,7 +746,9 @@ class DatabaseComponentImpl implements DatabaseComponent { public Message getMessageToSend(Transaction transaction, ContactId c, MessageId m, long maxLatency, boolean markAsSent) throws DbException { - if (transaction.isReadOnly()) throw new IllegalArgumentException(); + if (markAsSent && transaction.isReadOnly()) { + throw new IllegalArgumentException(); + } T txn = unbox(transaction); if (!db.containsContact(txn, c)) throw new NoSuchContactException();