Skip to content

Write original message timestamp into saved attachment file metadata.#14739

Open
Trigus42 wants to merge 1 commit into
signalapp:mainfrom
Trigus42:main
Open

Write original message timestamp into saved attachment file metadata.#14739
Trigus42 wants to merge 1 commit into
signalapp:mainfrom
Trigus42:main

Conversation

@Trigus42
Copy link
Copy Markdown

First time contributor checklist

Contributor checklist

  • I am following the Code Style Guidelines
  • I have tested my contribution on these devices:
    • OnePlus Nord 4, Android 16 (OOS 16.0.5)
  • My contribution is fully baked and ready to be merged as is
  • I ensure that all the open issues my contribution fixes are mentioned in the commit message of my first commit using the Fixes #1234 syntax

Description

Fixes #14584 - saved attachments appearing with the save date instead of the original message date in the gallery.

Commit 237ac9f set DATE_ADDED and DATE_MODIFIED in the Android MediaStore database when saving attachments. The MediaStore is Android's media index - a SQLite database that catalogs files on the device. However, many gallery apps read dates from embedded file metadata rather than MediaStore columns. In my testing on a OnePlus Nord 4 (Android 16), saved attachments still appeared sorted by save date after that commit.

This PR writes the original message timestamp (dateSent) directly into the saved file:

  • EXIF metadata for JPEG, PNG, and WebP images - sets DateTime and DateTimeOriginal via AndroidX ExifInterface. DateTimeOriginal is used here because Signal strips EXIF before sending, so no original capture date exists in the file - the sent date is the best available approximation and is what gallery apps sort by.
  • MP4 container timestamps for MP4-family videos (video/mp4, video/3gpp, video/3gpp2, video/mp2ts, video/quicktime) - binary-patches creation_time and modification_time in the mvhd, tkhd, and mdhd boxes in-place, without loading the full file into memory.

Other formats (GIF, WebM, etc.) are skipped gracefully - the save still succeeds, just without embedded timestamp metadata.

Testing: Bulk-saved all 4,533 attachments from a real Signal account on the device above. 4,529 succeeded (4 failures were pre-existing missing attachment data, unrelated). Verified correct timestamps via ffprobe on saved videos and an EXIF reader on saved images.

Note: This code was written with AI assistance and tested by a human with real-world data on a physical device.

Set EXIF DateTime and DateTimeOriginal for images (JPEG/PNG/WebP) and
update MP4 mvhd/tkhd/mdhd creation_time for videos (mp4/3gpp/quicktime
etc.) when saving attachments to the device gallery. This ensures
gallery apps sort saved media by the original sent date rather than
the save date.

Fixes signalapp#14584
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Saved images use download date instead of sent/received date in gallery

1 participant