Disable restore on open if auto-download is off.

This commit is contained in:
Clark
2024-05-30 09:07:16 -04:00
committed by Cody Henthorne
parent 17581a7a5e
commit ad9b1f05b4
2 changed files with 19 additions and 1 deletions

View File

@@ -48,6 +48,7 @@ import org.thoughtcrime.securesms.mms.SlideClickListener;
import org.thoughtcrime.securesms.mms.SlidesClickedListener;
import org.thoughtcrime.securesms.mms.VideoSlide;
import org.thoughtcrime.securesms.stories.StoryTextPostModel;
import org.thoughtcrime.securesms.util.AttachmentUtil;
import org.thoughtcrime.securesms.util.MediaUtil;
import org.thoughtcrime.securesms.util.Util;
import org.thoughtcrime.securesms.util.views.Stub;
@@ -370,7 +371,7 @@ public class ThumbnailView extends FrameLayout {
transferControlViewStub.get().setSlides(List.of(slide));
}
int transferState = TransferControlView.getTransferState(List.of(slide));
boolean isOffloadedImage = transferState == AttachmentTable.TRANSFER_RESTORE_OFFLOADED && MediaUtil.isImageType(slide.getContentType());
boolean isOffloadedImage = (transferState == AttachmentTable.TRANSFER_RESTORE_OFFLOADED && MediaUtil.isImageType(slide.getContentType())) && AttachmentUtil.isRestoreOnOpenPermitted(getContext(), slide.asAttachment());
if (!showControls ||
transferState == AttachmentTable.TRANSFER_PROGRESS_DONE ||

View File

@@ -4,11 +4,13 @@ package org.thoughtcrime.securesms.util;
import android.content.Context;
import android.text.TextUtils;
import androidx.annotation.MainThread;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.WorkerThread;
import org.signal.core.util.logging.Log;
import org.thoughtcrime.securesms.attachments.Attachment;
import org.thoughtcrime.securesms.attachments.AttachmentId;
import org.thoughtcrime.securesms.attachments.DatabaseAttachment;
import org.thoughtcrime.securesms.database.NoSuchMessageException;
@@ -24,6 +26,21 @@ public class AttachmentUtil {
private static final String TAG = Log.tag(AttachmentUtil.class);
@MainThread
public static boolean isRestoreOnOpenPermitted(@NonNull Context context, @Nullable Attachment attachment) {
if (attachment == null) {
Log.w(TAG, "attachment was null, returning vacuous true");
return true;
}
Set<String> allowedTypes = getAllowedAutoDownloadTypes(context);
String contentType = attachment.contentType;
if (MediaUtil.isImageType(contentType)) {
return NotInCallConstraint.isNotInConnectedCall() && allowedTypes.contains(MediaUtil.getDiscreteMimeType(contentType));
}
return false;
}
@WorkerThread
public static boolean isAutoDownloadPermitted(@NonNull Context context, @Nullable DatabaseAttachment attachment) {
if (attachment == null) {