Add constant for NO_AUTO_DELETE_TIMER, address review comments.

This commit is contained in:
akwizgran
2020-11-19 15:58:33 +00:00
parent dd9c6697b2
commit 3b6b77ccf5
13 changed files with 73 additions and 30 deletions

View File

@@ -58,12 +58,13 @@ import javax.annotation.concurrent.Immutable;
import javax.inject.Inject;
import static java.util.Collections.emptyList;
import static org.briarproject.bramble.api.autodelete.AutoDeleteConstants.NO_AUTO_DELETE_TIMER;
import static org.briarproject.bramble.api.sync.SyncConstants.MAX_MESSAGE_BODY_LENGTH;
import static org.briarproject.bramble.api.sync.validation.MessageState.DELIVERED;
import static org.briarproject.bramble.util.IoUtils.copyAndClose;
import static org.briarproject.briar.api.messaging.PrivateMessageFormat.TEXT;
import static org.briarproject.briar.api.messaging.PrivateMessageFormat.TEXT_IMAGES;
import static org.briarproject.briar.api.messaging.PrivateMessageFormat.TEXT_IMAGES_AUTO_DELETE;
import static org.briarproject.briar.api.messaging.PrivateMessageFormat.TEXT_ONLY;
import static org.briarproject.briar.client.MessageTrackerConstants.MSG_KEY_READ;
import static org.briarproject.briar.messaging.MessageTypes.ATTACHMENT;
import static org.briarproject.briar.messaging.MessageTypes.PRIVATE_MESSAGE;
@@ -201,7 +202,8 @@ class MessagingManagerImpl implements MessagingManager, IncomingMessageHook,
long timestamp = meta.getLong(MSG_KEY_TIMESTAMP);
boolean local = meta.getBoolean(MSG_KEY_LOCAL);
boolean read = meta.getBoolean(MSG_KEY_READ);
long timer = meta.getLong(MSG_KEY_AUTO_DELETE_TIMER, -1L);
long timer = meta.getLong(MSG_KEY_AUTO_DELETE_TIMER,
NO_AUTO_DELETE_TIMER);
PrivateMessageHeader header =
new PrivateMessageHeader(m.getId(), groupId, timestamp, local,
read, false, false, hasText, headers, timer);
@@ -240,7 +242,7 @@ class MessagingManagerImpl implements MessagingManager, IncomingMessageHook,
meta.put(MSG_KEY_TIMESTAMP, m.getMessage().getTimestamp());
meta.put(MSG_KEY_LOCAL, true);
meta.put(MSG_KEY_READ, true);
if (m.getFormat() != TEXT) {
if (m.getFormat() != TEXT_ONLY) {
meta.put(MSG_KEY_MSG_TYPE, PRIVATE_MESSAGE);
meta.put(MSG_KEY_HAS_TEXT, m.hasText());
BdfList headers = new BdfList();
@@ -251,7 +253,9 @@ class MessagingManagerImpl implements MessagingManager, IncomingMessageHook,
meta.put(MSG_KEY_ATTACHMENT_HEADERS, headers);
if (m.getFormat() == TEXT_IMAGES_AUTO_DELETE) {
long timer = m.getAutoDeleteTimer();
if (timer != -1) meta.put(MSG_KEY_AUTO_DELETE_TIMER, timer);
if (timer != NO_AUTO_DELETE_TIMER) {
meta.put(MSG_KEY_AUTO_DELETE_TIMER, timer);
}
}
}
// Mark attachments as shared and permanent now we're ready to send
@@ -365,10 +369,11 @@ class MessagingManagerImpl implements MessagingManager, IncomingMessageHook,
if (messageType == null) {
headers.add(new PrivateMessageHeader(id, g, timestamp,
local, read, s.isSent(), s.isSeen(), true,
emptyList(), -1));
emptyList(), NO_AUTO_DELETE_TIMER));
} else {
boolean hasText = meta.getBoolean(MSG_KEY_HAS_TEXT);
long timer = meta.getLong(MSG_KEY_AUTO_DELETE_TIMER, -1L);
long timer = meta.getLong(MSG_KEY_AUTO_DELETE_TIMER,
NO_AUTO_DELETE_TIMER);
headers.add(new PrivateMessageHeader(id, g, timestamp,
local, read, s.isSent(), s.isSeen(), hasText,
parseAttachmentHeaders(meta), timer));
@@ -439,7 +444,7 @@ class MessagingManagerImpl implements MessagingManager, IncomingMessageHook,
.getClientMinorVersion(txn, c, CLIENT_ID, 0);
if (minorVersion >= 3) return TEXT_IMAGES_AUTO_DELETE;
else if (minorVersion >= 1) return TEXT_IMAGES;
else return TEXT;
else return TEXT_ONLY;
}
@Override

View File

@@ -16,6 +16,7 @@ import javax.annotation.Nullable;
import javax.annotation.concurrent.Immutable;
import javax.inject.Inject;
import static org.briarproject.bramble.api.autodelete.AutoDeleteConstants.NO_AUTO_DELETE_TIMER;
import static org.briarproject.bramble.util.StringUtils.utf8IsTooLong;
import static org.briarproject.briar.api.messaging.MessagingConstants.MAX_PRIVATE_MESSAGE_TEXT_LENGTH;
import static org.briarproject.briar.messaging.MessageTypes.PRIVATE_MESSAGE;
@@ -52,7 +53,7 @@ class PrivateMessageFactoryImpl implements PrivateMessageFactory {
// Serialise the message
BdfList body = BdfList.of(PRIVATE_MESSAGE, text, attachmentList);
Message m = clientHelper.createMessage(groupId, timestamp, body);
return new PrivateMessage(m, text != null, headers, -1);
return new PrivateMessage(m, text != null, headers);
}
@Override
@@ -62,7 +63,8 @@ class PrivateMessageFactoryImpl implements PrivateMessageFactory {
validateTextAndAttachmentHeaders(text, headers);
BdfList attachmentList = serialiseAttachmentHeaders(headers);
// Serialise the message
Long timer = autoDeleteTimer == -1 ? null : autoDeleteTimer;
Long timer = autoDeleteTimer == NO_AUTO_DELETE_TIMER ?
null : autoDeleteTimer;
BdfList body = BdfList.of(PRIVATE_MESSAGE, text, attachmentList, timer);
Message m = clientHelper.createMessage(groupId, timestamp, body);
return new PrivateMessage(m, text != null, headers, autoDeleteTimer);

View File

@@ -55,6 +55,7 @@ import static java.util.Collections.emptyList;
import static java.util.logging.Level.INFO;
import static java.util.logging.Level.WARNING;
import static org.briarproject.bramble.api.autodelete.AutoDeleteConstants.MIN_AUTO_DELETE_TIMER_MS;
import static org.briarproject.bramble.api.autodelete.AutoDeleteConstants.NO_AUTO_DELETE_TIMER;
import static org.briarproject.bramble.api.plugin.BluetoothConstants.UUID_BYTES;
import static org.briarproject.bramble.api.sync.Group.Visibility.SHARED;
import static org.briarproject.bramble.util.StringUtils.getRandomString;
@@ -324,7 +325,8 @@ public class TestDataCreatorImpl implements TestDataCreator {
private void createPrivateMessage(GroupId groupId, String text,
long timestamp, boolean local, boolean autoDelete)
throws DbException, FormatException {
long timer = autoDelete ? MIN_AUTO_DELETE_TIMER_MS : -1;
long timer = autoDelete ?
MIN_AUTO_DELETE_TIMER_MS : NO_AUTO_DELETE_TIMER;
PrivateMessage m = privateMessageFactory.createPrivateMessage(groupId,
timestamp, text, emptyList(), timer);
BdfDictionary meta = new BdfDictionary();

View File

@@ -33,6 +33,7 @@ import static java.util.Collections.emptySet;
import static java.util.Collections.singleton;
import static java.util.Collections.singletonList;
import static org.briarproject.bramble.api.autodelete.AutoDeleteConstants.MIN_AUTO_DELETE_TIMER_MS;
import static org.briarproject.bramble.api.autodelete.AutoDeleteConstants.NO_AUTO_DELETE_TIMER;
import static org.briarproject.bramble.api.sync.validation.MessageState.DELIVERED;
import static org.briarproject.bramble.api.sync.validation.MessageState.PENDING;
import static org.briarproject.bramble.test.TestUtils.getRandomBytes;
@@ -111,8 +112,8 @@ public class MessagingManagerIntegrationTest
assertTrue(m1.hasText());
assertEquals(0, m0.getAttachmentHeaders().size());
assertEquals(0, m1.getAttachmentHeaders().size());
assertEquals(-1, m0.getAutoDeleteTimer());
assertEquals(-1, m1.getAutoDeleteTimer());
assertEquals(NO_AUTO_DELETE_TIMER, m0.getAutoDeleteTimer());
assertEquals(NO_AUTO_DELETE_TIMER, m1.getAutoDeleteTimer());
assertTrue(m0.isRead());
assertFalse(m1.isRead());
assertGroupCounts(c0, 1, 0);
@@ -148,8 +149,8 @@ public class MessagingManagerIntegrationTest
assertFalse(m1.hasText());
assertEquals(1, m0.getAttachmentHeaders().size());
assertEquals(1, m1.getAttachmentHeaders().size());
assertEquals(-1, m0.getAutoDeleteTimer());
assertEquals(-1, m1.getAutoDeleteTimer());
assertEquals(NO_AUTO_DELETE_TIMER, m0.getAutoDeleteTimer());
assertEquals(NO_AUTO_DELETE_TIMER, m1.getAutoDeleteTimer());
assertTrue(m0.isRead());
assertFalse(m1.isRead());
assertGroupCounts(c0, 1, 0);
@@ -374,7 +375,7 @@ public class MessagingManagerIntegrationTest
private PrivateMessage sendMessage(BriarIntegrationTestComponent from,
BriarIntegrationTestComponent to, @Nullable String text,
List<AttachmentHeader> attachments) throws Exception {
return sendMessage(from, to, text, attachments, -1);
return sendMessage(from, to, text, attachments, NO_AUTO_DELETE_TIMER);
}
private PrivateMessage sendMessage(BriarIntegrationTestComponent from,

View File

@@ -34,6 +34,7 @@ import java.util.concurrent.CountDownLatch;
import static java.util.Collections.singletonList;
import static java.util.concurrent.TimeUnit.MILLISECONDS;
import static org.briarproject.bramble.api.autodelete.AutoDeleteConstants.NO_AUTO_DELETE_TIMER;
import static org.briarproject.bramble.api.sync.validation.MessageState.DELIVERED;
import static org.briarproject.bramble.test.TestPluginConfigModule.SIMPLEX_TRANSPORT_ID;
import static org.briarproject.bramble.test.TestUtils.deleteTestDirectory;
@@ -123,7 +124,8 @@ public class SimplexMessagingIntegrationTest extends BriarTestCase {
PrivateMessageFactory privateMessageFactory =
device.getPrivateMessageFactory();
PrivateMessage message = privateMessageFactory.createPrivateMessage(
groupId, timestamp, "Hi!", singletonList(attachmentHeader), -1);
groupId, timestamp, "Hi!", singletonList(attachmentHeader),
NO_AUTO_DELETE_TIMER);
messagingManager.addLocalMessage(message);
}