mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-13 11:19:04 +01:00
Upgrade messaging client to support attachments.
This commit is contained in:
@@ -4,26 +4,30 @@ import org.briarproject.bramble.api.identity.Author;
|
||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||
import org.briarproject.bramble.api.sync.Message;
|
||||
import org.briarproject.bramble.api.sync.MessageId;
|
||||
import org.briarproject.briar.api.messaging.PrivateMessage;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import javax.annotation.concurrent.Immutable;
|
||||
|
||||
@Immutable
|
||||
@NotNullByDefault
|
||||
public abstract class ThreadedMessage extends PrivateMessage {
|
||||
public abstract class ThreadedMessage {
|
||||
|
||||
private final Message message;
|
||||
@Nullable
|
||||
private final MessageId parent;
|
||||
private final Author author;
|
||||
|
||||
public ThreadedMessage(Message message, @Nullable MessageId parent,
|
||||
Author author) {
|
||||
super(message);
|
||||
this.message = message;
|
||||
this.parent = parent;
|
||||
this.author = author;
|
||||
}
|
||||
|
||||
public Message getMessage() {
|
||||
return message;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public MessageId getParent() {
|
||||
return parent;
|
||||
|
||||
@@ -18,7 +18,8 @@ public abstract class ConversationMessageReceivedEvent<H extends ConversationMes
|
||||
private final H messageHeader;
|
||||
private final ContactId contactId;
|
||||
|
||||
public ConversationMessageReceivedEvent(H messageHeader, ContactId contactId) {
|
||||
public ConversationMessageReceivedEvent(H messageHeader,
|
||||
ContactId contactId) {
|
||||
this.messageHeader = messageHeader;
|
||||
this.contactId = contactId;
|
||||
}
|
||||
|
||||
@@ -9,6 +9,16 @@ public interface MessagingConstants {
|
||||
*/
|
||||
int MAX_PRIVATE_MESSAGE_TEXT_LENGTH = MAX_MESSAGE_BODY_LENGTH - 1024;
|
||||
|
||||
/**
|
||||
* The maximum number of attachments per private message.
|
||||
*/
|
||||
int MAX_ATTACHMENTS_PER_MESSAGE = 10;
|
||||
|
||||
/**
|
||||
* The maximum length of an attachment's content type in UTF-8 bytes.
|
||||
*/
|
||||
int MAX_CONTENT_TYPE_BYTES = 50;
|
||||
|
||||
/**
|
||||
* The supported mime types for image attachments.
|
||||
*/
|
||||
@@ -22,6 +32,6 @@ public interface MessagingConstants {
|
||||
* The maximum allowed size of image attachments.
|
||||
* TODO: Different limit for GIFs?
|
||||
*/
|
||||
int MAX_IMAGE_SIZE = MAX_MESSAGE_BODY_LENGTH; // 6 * 1024 * 1024;
|
||||
int MAX_IMAGE_SIZE = MAX_MESSAGE_BODY_LENGTH - 100; // 6 * 1024 * 1024;
|
||||
|
||||
}
|
||||
|
||||
@@ -12,6 +12,8 @@ import org.briarproject.briar.api.conversation.ConversationManager.ConversationC
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
@NotNullByDefault
|
||||
public interface MessagingManager extends ConversationClient {
|
||||
|
||||
@@ -28,7 +30,7 @@ public interface MessagingManager extends ConversationClient {
|
||||
/**
|
||||
* The current minor version of the messaging client.
|
||||
*/
|
||||
int MINOR_VERSION = 0;
|
||||
int MINOR_VERSION = 1;
|
||||
|
||||
/**
|
||||
* Stores a local private message.
|
||||
@@ -59,8 +61,10 @@ public interface MessagingManager extends ConversationClient {
|
||||
GroupId getConversationId(ContactId c) throws DbException;
|
||||
|
||||
/**
|
||||
* Returns the text of the private message with the given ID.
|
||||
* Returns the text of the private message with the given ID, or null if
|
||||
* the private message has no text.
|
||||
*/
|
||||
@Nullable
|
||||
String getMessageText(MessageId m) throws DbException;
|
||||
|
||||
/**
|
||||
|
||||
@@ -3,20 +3,56 @@ package org.briarproject.briar.api.messaging;
|
||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||
import org.briarproject.bramble.api.sync.Message;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import javax.annotation.concurrent.Immutable;
|
||||
|
||||
import static java.util.Collections.emptyList;
|
||||
|
||||
@Immutable
|
||||
@NotNullByDefault
|
||||
public class PrivateMessage {
|
||||
|
||||
private final Message message;
|
||||
private final boolean legacyFormat, hasText;
|
||||
private final List<AttachmentHeader> attachmentHeaders;
|
||||
|
||||
/**
|
||||
* Constructor for private messages in the legacy format, which does not
|
||||
* support attachments.
|
||||
*/
|
||||
public PrivateMessage(Message message) {
|
||||
this.message = message;
|
||||
legacyFormat = true;
|
||||
hasText = true;
|
||||
attachmentHeaders = emptyList();
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor for private messages in the current format, which supports
|
||||
* attachments.
|
||||
*/
|
||||
public PrivateMessage(Message message, boolean hasText,
|
||||
List<AttachmentHeader> headers) {
|
||||
this.message = message;
|
||||
this.hasText = hasText;
|
||||
this.attachmentHeaders = headers;
|
||||
legacyFormat = false;
|
||||
}
|
||||
|
||||
public Message getMessage() {
|
||||
return message;
|
||||
}
|
||||
|
||||
public boolean isLegacyFormat() {
|
||||
return legacyFormat;
|
||||
}
|
||||
|
||||
public boolean hasText() {
|
||||
return hasText;
|
||||
}
|
||||
|
||||
public List<AttachmentHeader> getAttachmentHeaders() {
|
||||
return attachmentHeaders;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,11 +6,16 @@ import org.briarproject.bramble.api.sync.GroupId;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
@NotNullByDefault
|
||||
public interface PrivateMessageFactory {
|
||||
|
||||
PrivateMessage createLegacyPrivateMessage(GroupId groupId, long timestamp,
|
||||
String text) throws FormatException;
|
||||
|
||||
PrivateMessage createPrivateMessage(GroupId groupId, long timestamp,
|
||||
String text, List<AttachmentHeader> attachments)
|
||||
@Nullable String text, List<AttachmentHeader> headers)
|
||||
throws FormatException;
|
||||
|
||||
}
|
||||
|
||||
@@ -19,10 +19,10 @@ public class PrivateMessageHeader extends ConversationMessageHeader {
|
||||
|
||||
public PrivateMessageHeader(MessageId id, GroupId groupId, long timestamp,
|
||||
boolean local, boolean read, boolean sent, boolean seen,
|
||||
boolean hasText, List<AttachmentHeader> attachmentHeaders) {
|
||||
boolean hasText, List<AttachmentHeader> headers) {
|
||||
super(id, groupId, timestamp, local, read, sent, seen);
|
||||
this.hasText = hasText;
|
||||
this.attachmentHeaders = attachmentHeaders;
|
||||
this.attachmentHeaders = headers;
|
||||
}
|
||||
|
||||
public boolean hasText() {
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
package org.briarproject.briar.api.messaging.event;
|
||||
|
||||
import org.briarproject.bramble.api.contact.ContactId;
|
||||
import org.briarproject.bramble.api.event.Event;
|
||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||
import org.briarproject.bramble.api.sync.MessageId;
|
||||
|
||||
import javax.annotation.concurrent.Immutable;
|
||||
|
||||
/**
|
||||
* An event that is broadcast when a new attachment is received.
|
||||
*/
|
||||
@Immutable
|
||||
@NotNullByDefault
|
||||
public class AttachmentReceivedEvent extends Event {
|
||||
|
||||
private final MessageId messageId;
|
||||
private final ContactId contactId;
|
||||
|
||||
public AttachmentReceivedEvent(MessageId messageId, ContactId contactId) {
|
||||
this.messageId = messageId;
|
||||
this.contactId = contactId;
|
||||
}
|
||||
|
||||
public MessageId getMessageId() {
|
||||
return messageId;
|
||||
}
|
||||
|
||||
public ContactId getContactId() {
|
||||
return contactId;
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,5 @@
|
||||
package org.briarproject.briar.api.test;
|
||||
|
||||
import org.briarproject.bramble.api.FormatException;
|
||||
import org.briarproject.bramble.api.contact.Contact;
|
||||
import org.briarproject.bramble.api.db.DbException;
|
||||
import org.briarproject.bramble.api.lifecycle.IoExecutor;
|
||||
@@ -24,9 +23,4 @@ public interface TestDataCreator {
|
||||
|
||||
@IoExecutor
|
||||
Contact addContact(String name) throws DbException;
|
||||
|
||||
@IoExecutor
|
||||
void addPrivateMessage(Contact contact, String text, long time,
|
||||
boolean local) throws DbException, FormatException;
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user