Skip to content

The desktop app shows link previews and sends them, and group links in messages open the group - #188

Merged
pitis merged 3 commits into
mainfrom
feat/desktop-link-previews
Nov 14, 2026
Merged

pitis merged 3 commits into
mainfrom
feat/desktop-link-previews

Conversation

@pitis

@pitis pitis commented Nov 14, 2026 •

Copy link
Copy Markdown
Owner

What changed

New app/previews.rs and app/previews/view.rs, after the Mac app's LinkPreviewCard (AttachmentViews.swift), PreviewDraftCard and ComposerView, AppStore.composerChanged/dismissPreview/send, PreviewLink, MessageText.groupLinks and AppStore.handleLink, and the link-previews spec.

Showing

  • A message with a link preview shows the Mac's card in its bubble, under its files and above its text (the Mac's order): the picture (52pt, rounded), the title (semibold 13, up to two lines) and the host the link goes to (11, faded; a lookalike host shows as xn--…), 280pt wide plus padding, on a dark 18% fill. Like the Mac's card it has no description. A picture that doesn't decode isn't drawn.
  • A click opens the link in the browser, https only, through the house opener in files.rs. GPUI's open_url would log the link when it fails. The link is parsed with url, the same parser the core uses, and its serialized form is what opens. So the browser goes to the host the card names, and the opened text has no quotes or spaces. On Windows, the opener hands Explorer its target quoted whole (raw_arg). Explorer splits its own command line on , and =, so a ,/root,<path> inside a link (or a file name with a comma) could otherwise pick what it opens.
  • Previews come from the core's details (loaded with reactions and files). The app trusts the core's rules: since A received link preview shows only if its https link is in the message #168 a received preview is kept only when its https link is written whole in the text, and none is kept for view-once. As on the Mac, deleted, view-once and sticker messages show no card. The picture is decrypted in memory by the core and shows once the image has downloaded. Row heights are remeasured when a card comes or goes.

Writing

  • 700 ms after typing stops, or when a chat opens with a saved draft or an edit ends, the first https link in the composer (taken as typed, as the core finds it) is sent to link_preview_for. The draft card appears above the composer, in the accessories panel after the mention picker: picture (44pt), title (or the host), description (two lines), host, and ✕ ("Remove the link preview").
  • The Mac's rules: each link is fetched at most once per chat. A dismissed link isn't fetched again, and neither is a link whose page returned nothing. A draft goes away when its link leaves the text. A fetch that finishes after its link or its chat changed is dropped. While editing a message, nothing is fetched.
  • The draft goes with send_text only if its link is still in the message. It doesn't go with files (send_attachments has no preview, as on the Mac). If the send fails and the text comes back to the composer, the draft comes back with it.
  • Previews are off unless the phone allows them. The core checks the phone's "Generate link previews" (synced from the phone; unknown counts as off) and fetches nothing otherwise. The Mac app has no setting of its own for this.

Links in message text

  • As on the Mac, the only clickable links in message text are group invite links (https://signal.group/#… or sgnl://signal.group/#…, the Mac's pattern). They're underlined. A click that selects nothing opens the Join dialog with the link filled in and asks for the group at once (the Mac's JoinGroupSheet(link:)), so the dialog shows the group's name, members and Join or Ask to Join. Dragging across a link still selects its text. Other links remain plain text, as on the Mac.
  • Selectable (the message text element) takes link ranges. It shows a pointing hand over a link and handles the click on release, the way gpui-base's inline links do.

Shortcuts (each has a code comment):

  • Links aren't clickable in a message with a hidden spoiler until it's revealed (the first click reveals it), and never in quotes. On the Mac they're clickable outside the spoiler, and in quotes too.
  • Preview pictures are decoded like chat photos (at most 640 px), more than a 52pt card needs.

Why

#140: the desktop app showed no link previews, sent none, and group links in messages did nothing.

How it was tested

  • Unit tests, written first. All new tests failed against stubbed logic before the code (each failure was checked; the review's tests failed before their fixes):
    • Explorer's argument: quoted whole with commas, =, /root,, spaces, and a file path with a comma; refused with a " or a final \
    • links parsed as the core parses them: a lookalike host as xn--…, \@ opens the host the card names
    • a picture that didn't decode isn't drawn
    • first link as typed, with surrounding punctuation trimmed and no-host links rejected
    • one fetch per link per chat, the draft dropped when its link changes, a late fetch for an old link ignored, a dismissed link not fetched again
    • the draft sent only with its link in the text, and back after a failed send
    • previews from details, where a message the core couldn't read keeps its preview
    • only downloaded pictures and the draft's decoded, each once
    • group links found as the Mac finds them, case-sensitive
    • link bytes marked over existing styles
    • the card's host, including port and IPv6
    • only https opened
  • Window tests (headless GPUI, --features snapshot):
    • a link is looked at only once typing has paused 700 ms, and also when a chat opens with a saved draft or an edit ends
    • a group link opens the Join dialog with the link
    • a click on a link in Selectable opens it, while a click off it or a drag across it doesn't. Removing either the click handling or the selection check makes this test fail.
  • cargo fmt --check; cargo clippy -p hush-desktop --all-targets -- -D warnings, with and without --features snapshot; cargo test -p hush-desktop (103 pass) and --features snapshot (124 pass), after merging The desktop app sends pictures and files #187.
  • --snapshot, light and dark, new link-preview screen: a received card with its picture, title and host above the text; an underlined group link; the draft card with ✕ above a composer holding a link. The other screens are unchanged.
  • Not run on Windows. The Windows opener was only type-checked, with clippy, against the x86_64-pc-windows-gnu std in a scratch crate holding the same function. Its argument building is unit-tested on every platform.
  • I didn't run make check: it needs the signing certificate, which this Mac doesn't have. The live window wasn't opened and no phone was linked. So real fetching, sending and receiving a preview, the pointer cursor over a link, and the browser actually opening on Windows and Linux are checked only by tests and by reading the code. On macOS I checked that /usr/bin/open -- takes a URL, using a scheme with no handler so no window opened.

One new direct dependency: url (already in the tree through the core), so the app parses links exactly as the core and browsers do. No core changes. files.rs: its opener takes a link too, quotes its target for Explorer, and says "no app here opens it"; thumbnail is shared.

Closes #140
Part of #157

@pitis

pitis commented Nov 14, 2026

Copy link
Copy Markdown
Owner Author

Review findings and fixes

All fixed on this branch in 9863253. Each test was written first and failed before its fix.

  1. Critical: on Windows, Explorer could open a target the sender chose. Rust quotes an argument only when it has a space, and Explorer splits its own command line on , and =. So a link like …/a,/root,file:///…/calc.exe, or a file name with a comma, could pick what it opens.
    • Fix: files::explorer_arg builds Explorer's whole command line, the target quoted, and open_with_system passes it with CommandExt::raw_arg on Windows. It refuses a target containing ", or ending in \ (which would escape the closing quote). No file path has either, and a link to open has neither.
    • The function is compiled on every platform and unit-tested with commas, =, /root,, spaces, a file path containing a comma, ", and a final \.
    • Not run on Windows. I type-checked the Windows branch, with clippy, against the x86_64-pc-windows-gnu std in a scratch crate holding the same function.
  2. \ encoding could change the host the browser opens. Fixed: links are parsed with url::Url (now a direct dependency; it was already in the tree through the core). The card shows host_str(), so a lookalike shows as xn--…, and as_str() is what opens. https://good.example\@evil.example/ now names and opens good.example. The first link in the composer is found with the same parse as the core, which removed the host shortcut. Tests cover both.
  3. A saved draft's link got no preview until the user typed. Fixed: composer_changed runs after the text is set in select (after the old chat's previews are cleared) and in stop_editing. Two window tests: opening a chat with a saved draft, and Esc out of an edit.
  4. A preview picture that failed to decode stayed a grey square. Fixed: pictures are Loading, Shown or Failed (as in files.rs). A failed one isn't drawn, on the card or on the draft. Tested.
  5. A failed link open said "no app here opens this kind of file". Fixed: the opener now says "no app here opens it", for files and links ("Couldn't open the link: no app here opens it").
  6. The old draft card stays while editing. Left as it is, for Mac parity (your ruling).

Rulings applied: only group links are clickable, the card sits above the text, and links are underlined in the bubble's text colour (all unchanged).

Checks: cargo fmt --check; cargo clippy -p hush-desktop --all-targets -- -D warnings with and without --features snapshot; cargo test -p hush-desktop (103 pass) and --features snapshot (124 pass). The link-preview snapshot was rendered again and is unchanged. make update: up to date with main.

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.

The desktop app shows link previews and sends them

1 participant