Repository navigation
Conversation
…nds, and stop failing photos the cache removed. Telegram puts a tiny copy of every photo (its stripped thumbnail, about 40 px) inside the message. chatd now rebuilds it into a JPEG from Telegram's fixed header and keeps it on disk as soon as the message is read, without asking the network. It reaches the shell as the new optional Attachment.preview. The tile draws it stretched over the photo's place while the chat-sized thumbnail downloads, and the thumbnail replaces it in the same place at the same size. Load images and spoilers hide it exactly as they hide the photo. A photo with no usable preview shows the image icon as before. Album tiles use the same code. What came inside a message is kept at once, on the thread that reads the message, so a preview never waits behind the downloads it stands in for. Each write has its own part file, so two writers of the same file never cut each other short. The media cache retried a Telegram file it had evicted at Telegram's internal tg://file/ name, which no host serves, and marked it "Telegram does not serve files from that address." The photo then said it could not load, with a Retry that could not work, until Telegram read the message again. The cache now leaves those files to Telegram and never marks them failed, so the box shows the preview or the icon, and chatd clears the old failures once at start. Signal, Messages and web addresses are unchanged. The e2e scenario telegram-photo-preview holds the thumbnail on the fake wire, checks the screen shows the preview, lets the thumbnail go, and checks it lands in the same place.
…and of what is off screen. Telegram's files come one at a time, 250 ms apart, and every thumbnail a page named waited in one line: a channel opened after an image-heavy one waited behind all of the first one's thumbnails, and behind its own that were not on screen, for 15 to 20 seconds. The file worker now keeps three lines: the original the viewer waits on, then the pictures messages show that the shell asked for because they are on screen (Command::Wanted), the latest asked first, then the rest in the order pages named them. Telegram keeps the place of each picture a message shows, as it kept the originals', so an ask moves it ahead. An ask for a picture no page has named yet is remembered for 30 s and goes ahead when a page does. A file waiting keeps one place, with the newest page's reference, so repeated asks are one download. The line still holds no more than 256: asks are never refused, and the worker lets go of the last-named background file first. Avatars, custom emoji and a picker's tiles keep their turn. What is remembered forgets its oldest half, never all at once. With TinyComms#262, a thumbnail the cache removed is fetched again as soon as the shell asks for it on screen; its test and the docs now say so. The fake wire gains photo-pages (photo posts in Field Notes and a real JPEG in Trail crew, read only with their pages) and flood-file. The e2e scenario telegram-visible-image-priority opens Field Notes, switches to Trail crew with Ctrl+K while the channel's thumbnails wait, checks from the wire's log that the group's photo went first and from the screen that it is drawn.
Contributor
Author
|
Pls note it depends on #262 - both features complement each other and have a bit of conflicting changes, not to mention developing them separately will require a follow-up PR to correctly wire them together when both are merged, so i decided to just make one dependent on the other. Before these changes, i often saw empty pictures placeholders when switching channels for 15-20s which is beyond acceptable. With these 2 applied together, it's usually up to 1s for thumbnail and extra 1s to load full picture, which is still not perfect but huge improvement nonetheless, with them it actually becomes usable. |
6 of 11 tasks
Collaborator
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.
Depends on #262. This branch is #262's commit plus one. Review the last commit. Once #262 is squash-merged, this is rebased onto
mainand the diff shrinks to that commit.What changed and why
A Telegram chat opened while another channel's thumbnails are still downloading now shows its own pictures first. Before, every thumbnail a page named waited in one line, one file at a time, 250 ms apart. The pictures on screen sat behind the off-screen ones and behind every thumbnail of the channel just left, for the 15 to 20 seconds reported. With this and #262 on a real account, a new channel's preview shows at once, its thumbnail in about a second, and the sharp picture a second later.
The Telegram file worker now takes three lines in order:
The shell already asks for what it draws (
Request::Fetch). chatd already hands an id the media cache does not know, or (since #262) a Telegram file that left the disk, to the adapter asCommand::Wanted. Telegram used that only for the viewer's originals. Nothing in the shell or the protocol changes.Changes
files.rs):Fileskeeps the place of each picture a message shows (a photo's thumbnail, a video's, GIF's or sticker's still), next to the originals it already kept. When the shell asks for one, it goes ahead of everything not on screen.Files::want_tiles, used bycatalog.rs). The sidebar, people list and pickers ask for those by the hundred, whether in sight or not. Chat-list avatars still wait for their rows, and go back ahead of the rest when their rows come back.docs/architecture.md,blobs.rsandCommand::Wantedsay so.photo-pages Nwrites N photo posts into Field Notes and one photo into Trail crew, where the next page read finds them, with no update. The group's thumbnail is a real JPEG (fake_crew_m.jpg, magenta across a green band).flood-file Nrefuses the nextupload.GetFilewith a flood wait.Type
Platforms
Proof
Scenario: e2e/scenarios/telegram-visible-image-priority
Lab run: pending.
The real window opens Field Notes with 30 uncached photo posts. It then switches with Ctrl+K, "Trail crew", Enter while most of the channel's thumbnails wait.
telegram.calls: the group's thumbnail must be asked for before channel thumbnails that were already waiting when the group opened.The base build's fake wire does not know
photo-pages, so the base run stops at "Field Notes opens, and Telegram is asked for its 30 photos' thumbnails one at a time". A base that had the posts would ask for the group's thumbnail after every channel thumbnail and fail the order step.scenario.jsonsays why macOS and the phones are not recorded.test_drive.pycovers the pixel check on drawn frames, including decoys.Tests:
cargo test -p chatd --lib --tests: all pass.tests/telegram.rs, through chatd's socket and the fake wire. The first four fail with Show the preview Telegram sends inside a photo until its thumbnail lands, and stop failing photos the cache removed #262's ownfiles.rs:the_pictures_on_screen_are_fetched_before_those_still_waiting_from_a_channel_left_or_off_screen: the picture asked for waits only for what was in flight.a_picture_asked_for_before_its_page_is_read_goes_ahead_once_the_page_names_itthe_original_the_viewer_waits_on_goes_before_the_pictures_on_screen: a flood wait holds the worker while both are asked for, so the order is the line's.a_thumbnail_gone_from_disk_is_never_marked_failed_and_telegram_keeps_it_again, which now asserts the thumbnail is fetched again once, without a page read.a_flood_wait_on_a_picture_on_screen_holds_every_file_until_it_has_passed, which guards behaviour that already held.files.rs: the line's order, one place per file with the newest reference, the trim order, the half-forgetting memory, early asks only while recent, and a picker's tiles keeping their turn.Compatibility
No protocol, store or server change. An older shell sends the same
Fetchit sends now.Risk and rollback
upload.GetFileeach time, instead of only when a page names it again.Release note
Telegram photos on screen load first, instead of waiting behind the pictures of a channel you just left.