Commit 934f14ef authored by Torsten Grote's avatar Torsten Grote

[core] Add attachment support to private messages

parent e3abff5a
......@@ -63,16 +63,16 @@ import org.briarproject.briar.api.android.AndroidNotificationManager;
import org.briarproject.briar.api.blog.BlogSharingManager;
import org.briarproject.briar.api.client.ProtocolStateException;
import org.briarproject.briar.api.client.SessionId;
import org.briarproject.briar.api.conversation.ConversationManager;
import org.briarproject.briar.api.conversation.ConversationMessageHeader;
import org.briarproject.briar.api.conversation.ConversationRequest;
import org.briarproject.briar.api.conversation.ConversationResponse;
import org.briarproject.briar.api.forum.ForumSharingManager;
import org.briarproject.briar.api.introduction.IntroductionManager;
import org.briarproject.briar.api.conversation.ConversationManager;
import org.briarproject.briar.api.messaging.MessagingManager;
import org.briarproject.briar.api.messaging.PrivateMessage;
import org.briarproject.briar.api.messaging.PrivateMessageFactory;
import org.briarproject.briar.api.messaging.PrivateMessageHeader;
import org.briarproject.briar.api.conversation.ConversationRequest;
import org.briarproject.briar.api.conversation.ConversationResponse;
import org.briarproject.briar.api.messaging.event.PrivateMessageReceivedEvent;
import org.briarproject.briar.api.privategroup.invitation.GroupInvitationManager;
......@@ -96,6 +96,7 @@ import uk.co.samuelwall.materialtaptargetprompt.MaterialTapTargetPrompt.PromptSt
import static android.support.v4.view.ViewCompat.setTransitionName;
import static android.support.v7.util.SortedList.INVALID_POSITION;
import static android.widget.Toast.LENGTH_SHORT;
import static java.util.Collections.emptyList;
import static java.util.Objects.requireNonNull;
import static java.util.logging.Level.INFO;
import static java.util.logging.Level.WARNING;
......@@ -534,7 +535,8 @@ public class ConversationActivity extends BriarActivity
Message message = m.getMessage();
PrivateMessageHeader h = new PrivateMessageHeader(
message.getId(), message.getGroupId(),
message.getTimestamp(), true, false, false, false);
message.getTimestamp(), true, false, false, false,
emptyList());
textCache.put(message.getId(), text);
addConversationItem(h.accept(visitor));
} catch (DbException e) {
......
package org.briarproject.briar.api.messaging;
import java.nio.ByteBuffer;
public class Attachment {
private final ByteBuffer data;
public Attachment(ByteBuffer data) {
this.data = data;
}
public ByteBuffer getData() {
return data;
}
}
package org.briarproject.briar.api.messaging;
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
import org.briarproject.bramble.api.sync.MessageId;
import javax.annotation.concurrent.Immutable;
@Immutable
@NotNullByDefault
public class AttachmentHeader {
private final MessageId messageId;
private final String contentType;
public AttachmentHeader(MessageId messageId, String contentType) {
this.messageId = messageId;
this.contentType = contentType;
}
public MessageId getMessageId() {
return messageId;
}
public String getContentType() {
return contentType;
}
}
......@@ -6,15 +6,25 @@ import org.briarproject.bramble.api.sync.MessageId;
import org.briarproject.briar.api.conversation.ConversationMessageHeader;
import org.briarproject.briar.api.conversation.ConversationMessageVisitor;
import java.util.List;
import javax.annotation.concurrent.Immutable;
@Immutable
@NotNullByDefault
public class PrivateMessageHeader extends ConversationMessageHeader {
private final List<AttachmentHeader> attachmentHeaders;
public PrivateMessageHeader(MessageId id, GroupId groupId, long timestamp,
boolean local, boolean read, boolean sent, boolean seen) {
boolean local, boolean read, boolean sent, boolean seen,
List<AttachmentHeader> attachmentHeaders) {
super(id, groupId, timestamp, local, read, sent, seen);
this.attachmentHeaders = attachmentHeaders;
}
public List<AttachmentHeader> getAttachmentHeaders() {
return attachmentHeaders;
}
@Override
......
......@@ -37,6 +37,7 @@ import java.util.Map;
import javax.annotation.concurrent.Immutable;
import javax.inject.Inject;
import static java.util.Collections.emptyList;
import static org.briarproject.briar.client.MessageTrackerConstants.MSG_KEY_READ;
@Immutable
......@@ -114,8 +115,9 @@ class MessagingManagerImpl extends ConversationClientImpl
long timestamp = meta.getLong("timestamp");
boolean local = meta.getBoolean("local");
boolean read = meta.getBoolean(MSG_KEY_READ);
PrivateMessageHeader header = new PrivateMessageHeader(
m.getId(), groupId, timestamp, local, read, false, false);
PrivateMessageHeader header =
new PrivateMessageHeader(m.getId(), groupId, timestamp, local,
read, false, false, emptyList());
ContactId contactId = getContactId(txn, groupId);
PrivateMessageReceivedEvent event =
new PrivateMessageReceivedEvent(header, contactId);
......@@ -201,7 +203,7 @@ class MessagingManagerImpl extends ConversationClientImpl
boolean local = meta.getBoolean("local");
boolean read = meta.getBoolean("read");
headers.add(new PrivateMessageHeader(id, g, timestamp, local,
read, s.isSent(), s.isSeen()));
read, s.isSent(), s.isSeen(), emptyList()));
} catch (FormatException e) {
throw new DbException(e);
}
......
......@@ -21,7 +21,7 @@ internal class WebSocketControllerTest : ControllerTest() {
private val controller = WebSocketControllerImpl(ImmediateExecutor())
private val header =
PrivateMessageHeader(message.id, group.id, timestamp, true, true, true, true)
PrivateMessageHeader(message.id, group.id, timestamp, true, true, true, true, emptyList())
private val event = PrivateMessageReceivedEvent(header, contact.id)
private val outputEvent = OutputEvent(EVENT_PRIVATE_MESSAGE, event.output(text))
......
......@@ -16,8 +16,11 @@ import org.briarproject.bramble.util.StringUtils.getRandomString
import org.briarproject.briar.api.client.SessionId
import org.briarproject.briar.api.conversation.ConversationManager
import org.briarproject.briar.api.introduction.IntroductionRequest
import org.briarproject.briar.api.messaging.*
import org.briarproject.briar.api.messaging.MessagingConstants.MAX_PRIVATE_MESSAGE_TEXT_LENGTH
import org.briarproject.briar.api.messaging.MessagingManager
import org.briarproject.briar.api.messaging.PrivateMessage
import org.briarproject.briar.api.messaging.PrivateMessageFactory
import org.briarproject.briar.api.messaging.PrivateMessageHeader
import org.briarproject.briar.api.messaging.event.PrivateMessageReceivedEvent
import org.briarproject.briar.headless.ControllerTest
import org.briarproject.briar.headless.event.WebSocketController
......@@ -47,7 +50,7 @@ internal class MessagingControllerImplTest : ControllerTest() {
)
private val header =
PrivateMessageHeader(message.id, group.id, timestamp, true, true, true, true)
PrivateMessageHeader(message.id, group.id, timestamp, true, true, true, true, emptyList())
private val sessionId = SessionId(getRandomId())
private val privateMessage = PrivateMessage(message)
......@@ -76,10 +79,10 @@ internal class MessagingControllerImplTest : ControllerTest() {
}
@Test
fun emptyList() {
fun testEmptyList() {
every { ctx.pathParam("contactId") } returns contact.id.int.toString()
every { contactManager.getContact(contact.id) } returns contact
every { conversationManager.getMessageHeaders(contact.id) } returns emptyList<PrivateMessageHeader>()
every { conversationManager.getMessageHeaders(contact.id) } returns emptyList()
every { ctx.json(emptyList<Any>()) } returns ctx
controller.list(ctx)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment