[core] Add API to add messages with attachments

This commit is contained in:
Torsten Grote
2018-11-05 10:32:38 -03:00
parent 483106e00c
commit cccaeeda6c
10 changed files with 37 additions and 8 deletions

View File

@@ -25,6 +25,7 @@ import org.briarproject.bramble.api.versioning.ClientVersioningManager.ClientVer
import org.briarproject.briar.api.client.MessageTracker;
import org.briarproject.briar.api.conversation.ConversationMessageHeader;
import org.briarproject.briar.api.messaging.Attachment;
import org.briarproject.briar.api.messaging.AttachmentHeader;
import org.briarproject.briar.api.messaging.MessagingManager;
import org.briarproject.briar.api.messaging.PrivateMessage;
import org.briarproject.briar.api.messaging.PrivateMessageHeader;
@@ -150,6 +151,15 @@ class MessagingManagerImpl extends ConversationClientImpl
}
}
@Override
public AttachmentHeader addLocalAttachment(GroupId groupId, long timestamp,
String contentType, ByteBuffer data) {
// TODO add real implementation
byte[] b = new byte[MessageId.LENGTH];
new Random().nextBytes(b);
return new AttachmentHeader(new MessageId(b), "image/png");
}
private ContactId getContactId(Transaction txn, GroupId g)
throws DbException {
try {

View File

@@ -6,9 +6,12 @@ import org.briarproject.bramble.api.data.BdfList;
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
import org.briarproject.bramble.api.sync.GroupId;
import org.briarproject.bramble.api.sync.Message;
import org.briarproject.briar.api.messaging.AttachmentHeader;
import org.briarproject.briar.api.messaging.PrivateMessage;
import org.briarproject.briar.api.messaging.PrivateMessageFactory;
import java.util.List;
import javax.annotation.concurrent.Immutable;
import javax.inject.Inject;
@@ -28,7 +31,8 @@ class PrivateMessageFactoryImpl implements PrivateMessageFactory {
@Override
public PrivateMessage createPrivateMessage(GroupId groupId, long timestamp,
String text) throws FormatException {
String text, List<AttachmentHeader> attachments)
throws FormatException {
// Validate the arguments
if (utf8IsTooLong(text, MAX_PRIVATE_MESSAGE_TEXT_LENGTH))
throw new IllegalArgumentException();

View File

@@ -53,6 +53,7 @@ import java.util.logging.Logger;
import javax.inject.Inject;
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.plugin.BluetoothConstants.UUID_BYTES;
@@ -327,7 +328,7 @@ public class TestDataCreatorImpl implements TestDataCreator {
private void createPrivateMessage(GroupId groupId, String text,
long timestamp, boolean local) throws DbException, FormatException {
PrivateMessage m = privateMessageFactory
.createPrivateMessage(groupId, timestamp, text);
.createPrivateMessage(groupId, timestamp, text, emptyList());
BdfDictionary meta = new BdfDictionary();
meta.put("timestamp", timestamp);
meta.put("local", local);

View File

@@ -24,6 +24,7 @@ import org.junit.Test;
import javax.inject.Inject;
import static java.util.Collections.emptyList;
import static org.briarproject.bramble.api.identity.AuthorConstants.MAX_AUTHOR_NAME_LENGTH;
import static org.briarproject.bramble.api.identity.AuthorConstants.MAX_PUBLIC_KEY_LENGTH;
import static org.briarproject.bramble.api.record.Record.MAX_RECORD_PAYLOAD_BYTES;
@@ -58,7 +59,7 @@ public class MessageSizeIntegrationTest extends BriarTestCase {
long timestamp = Long.MAX_VALUE;
String text = getRandomString(MAX_PRIVATE_MESSAGE_TEXT_LENGTH);
PrivateMessage message = privateMessageFactory.createPrivateMessage(
groupId, timestamp, text);
groupId, timestamp, text, emptyList());
// Check the size of the serialised message
int length = message.getMessage().getRawLength();
assertTrue(length > UniqueId.LENGTH + 8

View File

@@ -41,6 +41,7 @@ import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.InputStream;
import static java.util.Collections.emptyList;
import static org.briarproject.bramble.api.transport.TransportConstants.TAG_LENGTH;
import static org.briarproject.bramble.test.TestPluginConfigModule.MAX_LATENCY;
import static org.briarproject.bramble.test.TestPluginConfigModule.TRANSPORT_ID;
@@ -121,7 +122,7 @@ public class SimplexMessagingIntegrationTest extends BriarTestCase {
PrivateMessageFactory privateMessageFactory =
device.getPrivateMessageFactory();
PrivateMessage message = privateMessageFactory.createPrivateMessage(
groupId, System.currentTimeMillis(), "Hi!");
groupId, System.currentTimeMillis(), "Hi!", emptyList());
messagingManager.addLocalMessage(message);
}