Skip to content

The desktop app searches messages, everywhere or in one chat, and opens a found message in its chat - #182

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

pitis merged 3 commits into
mainfrom
feat/desktop-search

Conversation

@pitis

@pitis pitis commented Nov 14, 2026 •

Copy link
Copy Markdown
Owner

What changed

The desktop app's sidebar search now works like the Mac app's (SidebarView.swift, Search.swift, AppStore's search):

  • Chats and messages. While searching, a "Chats" section lists every chat whose name matches (archived ones too), with the Mac's match: part of the name, or its letters in order. A "Messages" section lists what the core's search finds (up to 50, newest first): the chat's picture and name, the time, and the sender (in groups, or "You") before the snippet, with the matches in bold, on two lines at most. While it's on its way it says "Searching…"; then "No messages found" or "Search failed: …". The old filter on chat names and last messages is gone, and so is its "No chats found".
  • Search in Chat (⇧⌘F, Ctrl+Shift+F elsewhere) searches the open chat only, under an "In " row with "All Chats" to go back. ⌘F / Ctrl+F puts the caret in the search field. Both are in a new "Chats" menu (shown on macOS) and work wherever the focus is, also with nothing focused or from the composer. Search in Chat does nothing while a dialog is open or no chat is open.
  • Keys in the field, as on the Mac: ↑/↓ step through the messages found when browsing them (in a chat search, or when no chat matches), each one opening as it's picked and kept in view in the list. ↩ opens the picked result (or the newest); otherwise it opens the open chat if it matches (or the first match) and ends the search. Esc clears the field; Esc on an empty field ends the search and its chat scope and gives the keys back to the composer, and so does leaving the field empty.
  • Opening a found message (click, arrows or ↩) opens its chat, loads it back to the message plus 50 older ones (count_newer, then messages), scrolls to it and outlines its bubble in yellow for 2 seconds. A message more than 10,000 back says "That message is too far back to show yet.", as on the Mac. A result whose message disappears (its timer runs out, or it's deleted for everyone) leaves the list. Once the timeline is back at its newest message, the chat loads only its newest page again.

The code is in its own module, core/desktop/src/app/search.rs. app/mod.rs and app/view.rs only hook it in: the field's events, where the sidebar lists chats and results, the arrows, the bubble's outline, and the timeline's load depth.

Paging back (#142)

Jumping needs only the part of #142 that loads older messages: the open chat now loads its newest depth messages. That's PAGE (100) normally, back to the found message after a jump, and PAGE again once the timeline is back at its newest message. The reload loop reads the wanted depth on each round, and a page fetched for a shallower depth than is now wanted is fetched again rather than shown. Scrolling back by itself still loads nothing older; #142 adds that.

Shortcuts (marked in the code or listed here)

How it was tested

  • Unit tests (new, in search.rs; each failed before the code): name matching, which chats a search lists (archived ones included; none in a chat search), snippet markers to bold ranges, the sender prefix, arrow stepping and its ends, the load depth and the too-far-back limit, and which chat ↩ opens.
  • Window tests (search.rs, window_tests; each failed before its fix): the real Hush (its demo, no core) in a headless GPUI test window, with real keystrokes and actions. They cover ⌘F with nothing focused and from the composer, ⇧⌘F, both menu actions, ⇧⌘F with a dialog open, Esc with text and then on an empty field, and the load depth going back to PAGE at the newest message. They need GPUI's test support, which snapshot turns on.
  • cargo test -p hush-desktop: 61 passed. cargo test -p hush-desktop --features snapshot: 65 passed.
  • cargo fmt --check, cargo clippy -p hush-desktop --all-targets -- -D warnings, the same with --features snapshot: clean. sig-core is untouched.
  • Snapshots (--snapshot, light and dark), with two new screens:
    • search: "book" across every chat. The "Chats" section has Book club and the archived Book swap; the "Messages" section has four results, bold matches, "You:" and group senders, and a third line cut with an ellipsis.
    • search-in-chat: "bring" in Family. The "In Family / All Chats" row, two results with the first one picked, and the opened message's bubble outlined in yellow in the timeline.
    • chat: the normal chat list (Pinned / Chats sections) is unchanged, and the archived demo chat doesn't show there.
  • Not tested: a live window with a linked phone, so not the real core search, the jump's loading and scrolling in a long chat, ↑/↓ through results, or a deleted result leaving the list. These need a core. ↑/↓ rest on the unit tests and on reading GPUI's dispatch (the field's ↑/↓ are taken in the capture phase, as Esc is, and Esc is tested). Windows and Linux builds weren't tried here; the only OS-specific part is choosing ⌘ or Ctrl with cfg!.

Closes #141
Part of #157

# Conflicts:
#	core/desktop/src/app/mod.rs
#	core/desktop/src/app/view.rs
#	core/desktop/src/demo.rs
#	core/desktop/src/main.rs
@pitis

pitis commented Nov 14, 2026

Copy link
Copy Markdown
Owner Author

Review findings and fixes

I merged main first (#180 message actions, then #181 files). Both sides are kept: the search's found outline now sits after the bubble's last child, on top of the quote, files and text, and the rows keep #180's identity ids.

Found while writing the tests, worse than finding 1: KeyBinding::new("secondary-f", …) panics in this GPUI (secondary- resolves only when the system is known, as in keymap files), so the app as first pushed would have crashed at startup. The snapshot run never binds keys, so it didn't show. Fixed: cmd-/ctrl- chosen with cfg!(target_os = "macos"), as QUIT_KEY is.

# Finding Fix
1 (Critical) ⌘F / ⇧⌘F and the menu items did nothing: the global handlers updated the window while it was mid-dispatch, and let _ hid the error. The handlers cx.defer the update until the dispatch is over. A failure is now logged with tracing::warn! (the crate has had tracing since #181); it can only mean the window is gone. Tested through GPUI: new #[gpui::test]s in search.rs (window_tests) open the real Hush (its --snapshot demo, no core) in a headless test window and send real keystrokes: ⌘F with nothing focused, ⌘F from the composer, ⇧⌘F, and the two menu actions via dispatch_action. Before the fix the first assertion failed. These tests need GPUI's test support, which the snapshot feature already enables, so they run with cargo test -p hush-desktop --features snapshot. Plain cargo test doesn't build them, and that keeps a third GPUI build off this Mac's disk.
2 Esc never ended a chat search. Esc on the search box is now caught before the field sees it. If the field has text, the field clears itself; if it's already empty, the search and its chat scope end and the keys go to the open chat's composer (or nowhere when no chat is open). Window test: type, Esc keeps the scope, Esc again ends it and the composer has focus. It failed before the fix.
3 ⇧⌘F with a dialog open changed the sidebar behind it. search_in_chat returns early under the same condition as ⌘F (chat list showing, no dialog) and when no chat is open. Window test with the New Group dialog open; it failed once finding 1 was fixed.
4 A deep jump stayed loaded, and was refetched and redrawn, until another chat opened. Done as ruled, in the existing timeline observer: once the timeline is back at its newest message, depth returns to PAGE and the newest page reloads. I used !is_scrolled_up(), the same "at the newest message" test the observer already uses to mark the chat read. It also counts a list scrolled to its end that hasn't resumed following yet, which is_following_tail() alone would miss until the next layout. Skipped while a jump is still on its way. Window test: depth 500 stays while a jump is pending and goes back to 100 once shown at the end; it failed before the fix.
5 The jump stayed armed after a failed load. A failed load disarms it (messages_failed, called from the load's error arm). No test: it needs a core whose load fails, and the demo has none. It's a one-line field reset.
6 The macOS menu didn't show ⌘F / ⇧⌘F. search::keys() is bound in main.rs before set_menus; shortcuts() now only registers the handlers once the window exists.
7 A message deleted for everyone kept its text in the results. On MessageChanged for a message among the results, the core's message(key) is read; if it's gone or deleted, it leaves the results. If the read fails, the result stays (a failed read isn't a deletion). No test: it needs a core.

One more interaction, found while merging main: opening a found message used to bump generation to drop a newest-page load still on its way. With #180/#181, generation also guards the reactions/details loader and the picture/recording loads, and select resets their state (actions.leave, clear_files). A bump outside select could leave actions.loading stuck and thumbnails stuck at "Loading". So generation is again bumped only by select. Instead, the reload loop reads the wanted depth on each round, and a page fetched for a shallower depth than is now wanted isn't shown but fetched again at the new depth. A jump therefore always lands on a page deep enough to hold it.

Rulings noted: Search in Chat's visible entry comes with Chat Options (#143), and ⌘F from the composer stays.

Checks (from core/)

  • cargo fmt --check: clean.
  • cargo clippy -p hush-desktop --all-targets -- -D warnings: clean. Same with --features snapshot: clean.
  • cargo test -p hush-desktop: 61 passed.
  • cargo test -p hush-desktop --features snapshot: 65 passed (the 4 window tests included).
  • Snapshots re-rendered on the new main. search and search-in-chat are as before, and the outline shows over The desktop app replies to, reacts to, edits, copies and deletes messages #180's bubble (quote, reactions, Retry). reply and files are unchanged.
  • make check wasn't run (it needs the signing certificate). sig-core is untouched.

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 searches messages

1 participant