Turn AttachmentReader into a proper class

and inject it where needed
This commit is contained in:
Torsten Grote
2020-11-26 11:20:05 -03:00
parent 5aa041f9e1
commit fe7121b4ec
31 changed files with 166 additions and 135 deletions

View File

@@ -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;
}

View File

@@ -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;
}

View File

@@ -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);
}
}

View File

@@ -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;
}

View File

@@ -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;
}

View File

@@ -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.

View File

@@ -9,7 +9,7 @@ import static org.briarproject.bramble.test.TestUtils.getRandomId;
import static org.briarproject.bramble.util.StringUtils.getRandomString;
import static org.briarproject.briar.api.identity.AuthorInfo.Status.NONE;
import static org.briarproject.briar.api.identity.AuthorInfo.Status.VERIFIED;
import static org.briarproject.briar.api.messaging.MessagingConstants.MAX_CONTENT_TYPE_BYTES;
import static org.briarproject.briar.api.media.MediaConstants.MAX_CONTENT_TYPE_BYTES;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotEquals;