SES-1571 Large messages show warning toast

This commit is contained in:
Al Lansley 2024-08-19 16:22:08 +10:00
parent 27ca77d5c4
commit acc8d47c68
2 changed files with 31 additions and 3 deletions

View File

@ -1840,6 +1840,22 @@ class ConversationActivityV2 : PassphraseRequiredActionBarActivity(), InputBarDe
val mediaPreppedListener = object : ListenableFuture.Listener<Boolean> { val mediaPreppedListener = object : ListenableFuture.Listener<Boolean> {
override fun onSuccess(result: Boolean?) { override fun onSuccess(result: Boolean?) {
if (result == null) {
Log.w(TAG, "Media prepper returned a null result - bailing.")
return
}
// If the attachment was too large or MediaConstraints.isSatisfied failed for some
// other reason then we reset the attachment manager & shown buttons then bail..
if (!result) {
attachmentManager.clear()
if (isShowingAttachmentOptions) { toggleAttachmentOptions() }
return
}
// ..otherwise we can attempt to send the attachment(s).
// Note: The only multi-attachment message type is when sending images - all others
// attempt send on initial attachment selection.
sendAttachments(attachmentManager.buildSlideDeck().asAttachments(), null) sendAttachments(attachmentManager.buildSlideDeck().asAttachments(), null)
} }

View File

@ -65,6 +65,9 @@ public class AttachmentManager {
private final static String TAG = AttachmentManager.class.getSimpleName(); private final static String TAG = AttachmentManager.class.getSimpleName();
// Max attachment size is 10MB, above which we display a warning toast rather than sending the msg
private final long MAX_ATTACHMENTS_FILE_SIZE_BYTES = 10 * 1024 * 1024;
private final @NonNull Context context; private final @NonNull Context context;
private final @NonNull AttachmentListener attachmentListener; private final @NonNull AttachmentListener attachmentListener;
@ -360,9 +363,18 @@ public class AttachmentManager {
final @Nullable Slide slide, final @Nullable Slide slide,
final @NonNull MediaConstraints constraints) final @NonNull MediaConstraints constraints)
{ {
return slide == null || // Null attachment? Not satisfied.
constraints.isSatisfied(context, slide.asAttachment()) || if (slide == null) return false;
constraints.canResize(slide.asAttachment());
// Attachments are excessively large? Not satisfied.
if (slide.asAttachment().getSize() > MAX_ATTACHMENTS_FILE_SIZE_BYTES) {
Toast.makeText(context, R.string.attachmentsErrorSize, Toast.LENGTH_SHORT).show();
return false;
}
// Otherwise our constraints-satisfied condition becomes whether we can resize it (obviously
// this will only work on images).
return constraints.canResize(slide.asAttachment());
} }
public interface AttachmentListener { public interface AttachmentListener {