Repository navigation
fix(media): stop re-downloading attachments the device already holds - #15
Merged
Merged
Conversation
Every chat open fetches the newest archive page and hands it to the same decrypt-and-store path as a live message. That path collected a media reference for every message in the page, including messages that were already stored and downloaded. The server deletes its copy once delivery is confirmed, so the second attempt came back 404 and `updatePrivateMessageMedia` wrote that failure onto the message: a perfectly good attachment flipped to "download failed" / "expired" the moment the chat was opened again. `downloadMediaMessage` now returns early when the message already has the attachment on disk, which covers the history page, the sync delta and a redelivery after reconnect in one place. Rows that already carry the stale status are healed by rendering: a message with a local file is drawn from that file whatever its status says, because the file is the truth. The status only decides what to show when there is no file. Verified on the running debug build: the same conversation that showed "Stažení selhalo" for several bubbles rendered its images and voice player after a hot reload.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Symptom: an attachment received while the chat is open shows fine; reopening the chat replaces it with "Stažení selhalo" / "Příloha neexistuje".
Root cause: every chat open fetches the newest archive page (
_loadHistory) and runs it through the same decrypt-and-store path as a live message (Utils.storeHistoryPage→_storeMessages). That path collected a media reference for every message in the page — including ones already stored and downloaded — and fireddownloadMediaMessagefor each. The server deletes its copy once delivery is confirmed, so the second attempt returned 404 andupdatePrivateMessageMediawrote that failure onto the healthy message.Fix:
downloadMediaMessagereturns early when the attachment is already on disk (CacheUtils.hasMediaLocally), covering the history page, the sync delta and a reconnect redelivery in one place. A message whose download genuinely failed has no local file, so a redelivery still retries it.downloadStatussays. The status only decides what to show when there is no file.media_guard_testcovers the local-file check for single media, albums, pending placeholders and another conversation.Verified on the running debug build (Android emulator, via the Flutter MCP toolkit): before the change the open chat had several
"Stažení selhalo"nodes; after a hot reload of this code the same conversation showsimagenodes (with its caption) and the voice player. Full end-to-end re-open with a live peer was not repeated.Verification:
flutter analyze --no-fatal-infosclean,flutter test152/152.