Fix incorrect image showing in gallery when other media is unavailable.

This commit is contained in:
Cody Henthorne 2024-09-13 16:35:26 -04:00 committed by Greyson Parrelli
parent f57b1a8f5e
commit 6b9e921888

View file

@ -60,20 +60,28 @@ class MediaPreviewRepository {
val frontLimit: Int = limit / 2
val windowStart = if (startingRow >= frontLimit) startingRow - frontLimit else 0
itemPosition = startingRow - windowStart
cursor.moveToPosition(windowStart)
for (i in 0..limit) {
val element = MediaTable.MediaRecord.from(cursor)
if (element.attachment?.transferState == AttachmentTable.TRANSFER_PROGRESS_DONE || element.attachment?.transferState == AttachmentTable.TRANSFER_PROGRESS_STARTED) {
mediaRecords.add(element)
if (startingAttachmentId.id == cursor.requireLong(AttachmentTable.ID)) {
itemPosition = mediaRecords.lastIndex
}
}
if (!cursor.moveToNext()) {
break
}
}
if (itemPosition == -1) {
Log.w(TAG, "Unable to find target image for $startingAttachmentId")
}
}
val messageIds = mediaRecords.mapNotNull { it.attachment?.mmsId }.toSet()
val messages: Map<Long, SpannableString> = SignalDatabase.messages.getMessages(messageIds)
.map { it as MmsMessageRecord }