mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-12 18:59:06 +01:00
Turn AttachmentReader into a proper class
and inject it where needed
This commit is contained in:
@@ -5,7 +5,6 @@ import org.briarproject.bramble.api.db.DbException;
|
||||
import org.briarproject.bramble.api.db.Transaction;
|
||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||
import org.briarproject.bramble.api.sync.ClientId;
|
||||
import org.briarproject.briar.api.media.Attachment;
|
||||
import org.briarproject.briar.api.media.AttachmentHeader;
|
||||
|
||||
import java.io.IOException;
|
||||
@@ -51,9 +50,4 @@ public interface AvatarManager {
|
||||
*/
|
||||
@Nullable
|
||||
AttachmentHeader getMyAvatarHeader(Transaction txn) throws DbException;
|
||||
|
||||
/**
|
||||
* Returns the profile image attachment for the given header.
|
||||
*/
|
||||
Attachment getAvatar(AttachmentHeader h) throws DbException;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
package org.briarproject.briar.api.media;
|
||||
|
||||
import org.briarproject.bramble.api.db.DbException;
|
||||
|
||||
public interface AttachmentReader {
|
||||
|
||||
/**
|
||||
* Returns the attachment with the given attachment header.
|
||||
*
|
||||
* @throws InvalidAttachmentException If the header refers to a message
|
||||
* that is not an attachment, or to an attachment that does not have the
|
||||
* expected content type
|
||||
*/
|
||||
Attachment getAttachment(AttachmentHeader h) throws DbException;
|
||||
|
||||
}
|
||||
@@ -11,4 +11,11 @@ import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||
*/
|
||||
@NotNullByDefault
|
||||
public class InvalidAttachmentException extends DbException {
|
||||
public InvalidAttachmentException() {
|
||||
super();
|
||||
}
|
||||
|
||||
public InvalidAttachmentException(Throwable t) {
|
||||
super(t);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
package org.briarproject.briar.api.media;
|
||||
|
||||
import static org.briarproject.bramble.api.sync.SyncConstants.MAX_MESSAGE_BODY_LENGTH;
|
||||
|
||||
public interface MediaConstants {
|
||||
|
||||
// Metadata keys for messages
|
||||
String MSG_KEY_CONTENT_TYPE = "contentType";
|
||||
String MSG_KEY_DESCRIPTOR_LENGTH = "descriptorLength";
|
||||
|
||||
/**
|
||||
* The maximum length of an attachment's content type in UTF-8 bytes.
|
||||
*/
|
||||
int MAX_CONTENT_TYPE_BYTES = 50;
|
||||
|
||||
/**
|
||||
* The maximum allowed size of image attachments.
|
||||
* TODO: Different limit for GIFs?
|
||||
*/
|
||||
int MAX_IMAGE_SIZE = MAX_MESSAGE_BODY_LENGTH - 100; // 6 * 1024 * 1024;
|
||||
}
|
||||
@@ -14,15 +14,4 @@ public interface MessagingConstants {
|
||||
*/
|
||||
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 maximum allowed size of image attachments.
|
||||
* TODO: Different limit for GIFs?
|
||||
*/
|
||||
int MAX_IMAGE_SIZE = MAX_MESSAGE_BODY_LENGTH - 100; // 6 * 1024 * 1024;
|
||||
|
||||
}
|
||||
|
||||
@@ -8,10 +8,8 @@ import org.briarproject.bramble.api.sync.ClientId;
|
||||
import org.briarproject.bramble.api.sync.GroupId;
|
||||
import org.briarproject.bramble.api.sync.MessageId;
|
||||
import org.briarproject.briar.api.conversation.ConversationManager.ConversationClient;
|
||||
import org.briarproject.briar.api.media.Attachment;
|
||||
import org.briarproject.briar.api.media.AttachmentHeader;
|
||||
import org.briarproject.briar.api.media.FileTooBigException;
|
||||
import org.briarproject.briar.api.media.InvalidAttachmentException;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
@@ -71,15 +69,6 @@ public interface MessagingManager extends ConversationClient {
|
||||
@Nullable
|
||||
String getMessageText(MessageId m) throws DbException;
|
||||
|
||||
/**
|
||||
* Returns the attachment with the given attachment header.
|
||||
*
|
||||
* @throws InvalidAttachmentException If the header refers to a message
|
||||
* that is not an attachment, or to an attachment that does not have the
|
||||
* expected content type
|
||||
*/
|
||||
Attachment getAttachment(AttachmentHeader h) throws DbException;
|
||||
|
||||
/**
|
||||
* Returns true if the contact with the given {@link ContactId} does support
|
||||
* image attachments.
|
||||
|
||||
Reference in New Issue
Block a user