diff --git a/src/org/thoughtcrime/securesms/mms/MediaConstraints.java b/src/org/thoughtcrime/securesms/mms/MediaConstraints.java index 37bfd2b1af..ecee9337b7 100644 --- a/src/org/thoughtcrime/securesms/mms/MediaConstraints.java +++ b/src/org/thoughtcrime/securesms/mms/MediaConstraints.java @@ -36,13 +36,15 @@ public abstract class MediaConstraints { public abstract int getAudioMaxSize(); + public abstract int getDocumentMaxSize(); + public boolean isSatisfied(@NonNull Context context, @NonNull MasterSecret masterSecret, @NonNull Attachment attachment) { try { return (MediaUtil.isGif(attachment) && attachment.getSize() <= getGifMaxSize() && isWithinBounds(context, masterSecret, attachment.getDataUri())) || (MediaUtil.isImage(attachment) && attachment.getSize() <= getImageMaxSize() && isWithinBounds(context, masterSecret, attachment.getDataUri())) || (MediaUtil.isAudio(attachment) && attachment.getSize() <= getAudioMaxSize()) || (MediaUtil.isVideo(attachment) && attachment.getSize() <= getVideoMaxSize()) || - (!MediaUtil.isImage(attachment) && !MediaUtil.isAudio(attachment) && !MediaUtil.isVideo(attachment)); + (MediaUtil.isFile(attachment) && attachment.getSize() <= getDocumentMaxSize()); } catch (IOException ioe) { Log.w(TAG, "Failed to determine if media's constraints are satisfied.", ioe); return false; diff --git a/src/org/thoughtcrime/securesms/mms/MmsMediaConstraints.java b/src/org/thoughtcrime/securesms/mms/MmsMediaConstraints.java index f6db1eea1b..55bda06fa3 100644 --- a/src/org/thoughtcrime/securesms/mms/MmsMediaConstraints.java +++ b/src/org/thoughtcrime/securesms/mms/MmsMediaConstraints.java @@ -38,4 +38,9 @@ public class MmsMediaConstraints extends MediaConstraints { public int getAudioMaxSize() { return MAX_MESSAGE_SIZE; } + + @Override + public int getDocumentMaxSize() { + return MAX_MESSAGE_SIZE; + } } diff --git a/src/org/thoughtcrime/securesms/mms/PushMediaConstraints.java b/src/org/thoughtcrime/securesms/mms/PushMediaConstraints.java index f0ef8c0cef..b916e1b6b2 100644 --- a/src/org/thoughtcrime/securesms/mms/PushMediaConstraints.java +++ b/src/org/thoughtcrime/securesms/mms/PushMediaConstraints.java @@ -39,4 +39,9 @@ public class PushMediaConstraints extends MediaConstraints { public int getAudioMaxSize() { return 100 * MB; } + + @Override + public int getDocumentMaxSize() { + return 100 * MB; + } } diff --git a/src/org/thoughtcrime/securesms/util/MediaUtil.java b/src/org/thoughtcrime/securesms/util/MediaUtil.java index ede01923d3..5deaef079a 100644 --- a/src/org/thoughtcrime/securesms/util/MediaUtil.java +++ b/src/org/thoughtcrime/securesms/util/MediaUtil.java @@ -164,6 +164,10 @@ public class MediaUtil { return !TextUtils.isEmpty(contentType) && contentType.trim().startsWith("video/"); } + public static boolean isFile(Attachment attachment) { + return !isImage(attachment) && !isAudio(attachment) && !isVideo(attachment); + } + public static boolean hasVideoThumbnail(Uri uri) { Log.w(TAG, "Checking: " + uri);