From 77a18e337bf30ef1791ef437888b35c8a6df9eba Mon Sep 17 00:00:00 2001 From: 0x330a <92654767+0x330a@users.noreply.github.com> Date: Wed, 4 Oct 2023 15:17:07 +1100 Subject: [PATCH] Maybe fix oob in media preview adapter cursor adapter (#1324) * fix: maybe fix oob exception? * fix: attachment download was broken again * refactor: wrap in an if and log warning in the bad state --- .../securesms/MediaPreviewActivity.java | 13 ++++++++----- .../messaging/jobs/AttachmentDownloadJob.kt | 3 ++- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/org/thoughtcrime/securesms/MediaPreviewActivity.java b/app/src/main/java/org/thoughtcrime/securesms/MediaPreviewActivity.java index f19a1fc45e..b74638fec7 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/MediaPreviewActivity.java +++ b/app/src/main/java/org/thoughtcrime/securesms/MediaPreviewActivity.java @@ -47,7 +47,6 @@ import android.widget.Toast; import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.appcompat.app.ActionBar; -import androidx.appcompat.app.AlertDialog; import androidx.core.util.Pair; import androidx.lifecycle.ViewModelProvider; import androidx.loader.app.LoaderManager; @@ -534,11 +533,15 @@ public class MediaPreviewActivity extends PassphraseRequiredActionBarActivity im viewModel.setCursor(this, data.first, leftIsRecent); - int item = restartItem >= 0 ? restartItem : data.second; - mediaPager.setCurrentItem(item); + if (restartItem >= 0 || data.second >= 0) { + int item = restartItem >= 0 ? restartItem : data.second; + mediaPager.setCurrentItem(item); - if (item == 0) { - viewPagerListener.onPageSelected(0); + if (item == 0) { + viewPagerListener.onPageSelected(0); + } + } else { + Log.w(TAG, "one of restartItem "+restartItem+" and data.second "+data.second+" would cause OOB exception"); } } } diff --git a/libsession/src/main/java/org/session/libsession/messaging/jobs/AttachmentDownloadJob.kt b/libsession/src/main/java/org/session/libsession/messaging/jobs/AttachmentDownloadJob.kt index 451081fd1a..1697c088bb 100644 --- a/libsession/src/main/java/org/session/libsession/messaging/jobs/AttachmentDownloadJob.kt +++ b/libsession/src/main/java/org/session/libsession/messaging/jobs/AttachmentDownloadJob.kt @@ -100,9 +100,10 @@ class AttachmentDownloadJob(val attachmentID: Long, val databaseMessageID: Long) handleFailure(Error.NoSender, null) return } - if (!threadRecipient.isGroupRecipient && (contact?.isTrusted == true || storage.getUserPublicKey() != sender)) { + if (!threadRecipient.isGroupRecipient || (contact?.isTrusted != true && storage.getUserPublicKey() != sender)) { // if we aren't receiving a group message, a message from ourselves (self-send) and the contact sending is not trusted: // do not continue, but do not fail + handleFailure(Error.NoSender, null) return }