mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-21 15:19:53 +01:00
[core] Add attachment support to private messages
This commit is contained in:
@@ -63,16 +63,16 @@ import org.briarproject.briar.api.android.AndroidNotificationManager;
|
|||||||
import org.briarproject.briar.api.blog.BlogSharingManager;
|
import org.briarproject.briar.api.blog.BlogSharingManager;
|
||||||
import org.briarproject.briar.api.client.ProtocolStateException;
|
import org.briarproject.briar.api.client.ProtocolStateException;
|
||||||
import org.briarproject.briar.api.client.SessionId;
|
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.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.forum.ForumSharingManager;
|
||||||
import org.briarproject.briar.api.introduction.IntroductionManager;
|
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.MessagingManager;
|
||||||
import org.briarproject.briar.api.messaging.PrivateMessage;
|
import org.briarproject.briar.api.messaging.PrivateMessage;
|
||||||
import org.briarproject.briar.api.messaging.PrivateMessageFactory;
|
import org.briarproject.briar.api.messaging.PrivateMessageFactory;
|
||||||
import org.briarproject.briar.api.messaging.PrivateMessageHeader;
|
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.messaging.event.PrivateMessageReceivedEvent;
|
||||||
import org.briarproject.briar.api.privategroup.invitation.GroupInvitationManager;
|
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.v4.view.ViewCompat.setTransitionName;
|
||||||
import static android.support.v7.util.SortedList.INVALID_POSITION;
|
import static android.support.v7.util.SortedList.INVALID_POSITION;
|
||||||
import static android.widget.Toast.LENGTH_SHORT;
|
import static android.widget.Toast.LENGTH_SHORT;
|
||||||
|
import static java.util.Collections.emptyList;
|
||||||
import static java.util.Objects.requireNonNull;
|
import static java.util.Objects.requireNonNull;
|
||||||
import static java.util.logging.Level.INFO;
|
import static java.util.logging.Level.INFO;
|
||||||
import static java.util.logging.Level.WARNING;
|
import static java.util.logging.Level.WARNING;
|
||||||
@@ -534,7 +535,8 @@ public class ConversationActivity extends BriarActivity
|
|||||||
Message message = m.getMessage();
|
Message message = m.getMessage();
|
||||||
PrivateMessageHeader h = new PrivateMessageHeader(
|
PrivateMessageHeader h = new PrivateMessageHeader(
|
||||||
message.getId(), message.getGroupId(),
|
message.getId(), message.getGroupId(),
|
||||||
message.getTimestamp(), true, false, false, false);
|
message.getTimestamp(), true, false, false, false,
|
||||||
|
emptyList());
|
||||||
textCache.put(message.getId(), text);
|
textCache.put(message.getId(), text);
|
||||||
addConversationItem(h.accept(visitor));
|
addConversationItem(h.accept(visitor));
|
||||||
} catch (DbException e) {
|
} catch (DbException e) {
|
||||||
|
|||||||
@@ -0,0 +1,17 @@
|
|||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,28 @@
|
|||||||
|
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.ConversationMessageHeader;
|
||||||
import org.briarproject.briar.api.conversation.ConversationMessageVisitor;
|
import org.briarproject.briar.api.conversation.ConversationMessageVisitor;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import javax.annotation.concurrent.Immutable;
|
import javax.annotation.concurrent.Immutable;
|
||||||
|
|
||||||
@Immutable
|
@Immutable
|
||||||
@NotNullByDefault
|
@NotNullByDefault
|
||||||
public class PrivateMessageHeader extends ConversationMessageHeader {
|
public class PrivateMessageHeader extends ConversationMessageHeader {
|
||||||
|
|
||||||
|
private final List<AttachmentHeader> attachmentHeaders;
|
||||||
|
|
||||||
public PrivateMessageHeader(MessageId id, GroupId groupId, long timestamp,
|
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);
|
super(id, groupId, timestamp, local, read, sent, seen);
|
||||||
|
this.attachmentHeaders = attachmentHeaders;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<AttachmentHeader> getAttachmentHeaders() {
|
||||||
|
return attachmentHeaders;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -37,6 +37,7 @@ import java.util.Map;
|
|||||||
import javax.annotation.concurrent.Immutable;
|
import javax.annotation.concurrent.Immutable;
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
|
|
||||||
|
import static java.util.Collections.emptyList;
|
||||||
import static org.briarproject.briar.client.MessageTrackerConstants.MSG_KEY_READ;
|
import static org.briarproject.briar.client.MessageTrackerConstants.MSG_KEY_READ;
|
||||||
|
|
||||||
@Immutable
|
@Immutable
|
||||||
@@ -114,8 +115,9 @@ class MessagingManagerImpl extends ConversationClientImpl
|
|||||||
long timestamp = meta.getLong("timestamp");
|
long timestamp = meta.getLong("timestamp");
|
||||||
boolean local = meta.getBoolean("local");
|
boolean local = meta.getBoolean("local");
|
||||||
boolean read = meta.getBoolean(MSG_KEY_READ);
|
boolean read = meta.getBoolean(MSG_KEY_READ);
|
||||||
PrivateMessageHeader header = new PrivateMessageHeader(
|
PrivateMessageHeader header =
|
||||||
m.getId(), groupId, timestamp, local, read, false, false);
|
new PrivateMessageHeader(m.getId(), groupId, timestamp, local,
|
||||||
|
read, false, false, emptyList());
|
||||||
ContactId contactId = getContactId(txn, groupId);
|
ContactId contactId = getContactId(txn, groupId);
|
||||||
PrivateMessageReceivedEvent event =
|
PrivateMessageReceivedEvent event =
|
||||||
new PrivateMessageReceivedEvent(header, contactId);
|
new PrivateMessageReceivedEvent(header, contactId);
|
||||||
@@ -201,7 +203,7 @@ class MessagingManagerImpl extends ConversationClientImpl
|
|||||||
boolean local = meta.getBoolean("local");
|
boolean local = meta.getBoolean("local");
|
||||||
boolean read = meta.getBoolean("read");
|
boolean read = meta.getBoolean("read");
|
||||||
headers.add(new PrivateMessageHeader(id, g, timestamp, local,
|
headers.add(new PrivateMessageHeader(id, g, timestamp, local,
|
||||||
read, s.isSent(), s.isSeen()));
|
read, s.isSent(), s.isSeen(), emptyList()));
|
||||||
} catch (FormatException e) {
|
} catch (FormatException e) {
|
||||||
throw new DbException(e);
|
throw new DbException(e);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ internal class WebSocketControllerTest : ControllerTest() {
|
|||||||
private val controller = WebSocketControllerImpl(ImmediateExecutor())
|
private val controller = WebSocketControllerImpl(ImmediateExecutor())
|
||||||
|
|
||||||
private val header =
|
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 event = PrivateMessageReceivedEvent(header, contact.id)
|
||||||
private val outputEvent = OutputEvent(EVENT_PRIVATE_MESSAGE, event.output(text))
|
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.client.SessionId
|
||||||
import org.briarproject.briar.api.conversation.ConversationManager
|
import org.briarproject.briar.api.conversation.ConversationManager
|
||||||
import org.briarproject.briar.api.introduction.IntroductionRequest
|
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.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.api.messaging.event.PrivateMessageReceivedEvent
|
||||||
import org.briarproject.briar.headless.ControllerTest
|
import org.briarproject.briar.headless.ControllerTest
|
||||||
import org.briarproject.briar.headless.event.WebSocketController
|
import org.briarproject.briar.headless.event.WebSocketController
|
||||||
@@ -47,7 +50,7 @@ internal class MessagingControllerImplTest : ControllerTest() {
|
|||||||
)
|
)
|
||||||
|
|
||||||
private val header =
|
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 sessionId = SessionId(getRandomId())
|
||||||
private val privateMessage = PrivateMessage(message)
|
private val privateMessage = PrivateMessage(message)
|
||||||
|
|
||||||
@@ -76,10 +79,10 @@ internal class MessagingControllerImplTest : ControllerTest() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun emptyList() {
|
fun testEmptyList() {
|
||||||
every { ctx.pathParam("contactId") } returns contact.id.int.toString()
|
every { ctx.pathParam("contactId") } returns contact.id.int.toString()
|
||||||
every { contactManager.getContact(contact.id) } returns contact
|
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
|
every { ctx.json(emptyList<Any>()) } returns ctx
|
||||||
|
|
||||||
controller.list(ctx)
|
controller.list(ctx)
|
||||||
|
|||||||
Reference in New Issue
Block a user