Skip to content

feat(downloads): save downloads into a folder named after the chat - #1010

Open
atahan150 wants to merge 19 commits into
rafatosta:mainfrom
atahan150:feat/downloads-chat-folders
Open

atahan150 wants to merge 19 commits into
rafatosta:mainfrom
atahan150:feat/downloads-chat-folders

Conversation

@atahan150

Copy link
Copy Markdown

Problem

All downloads land in one folder (by default ~/Downloads/WhatsApp). People who download a lot of media cannot tell which chat a file came from without opening WhatsApp again.

What this adds

A new switch under Settings > Downloads: "Save to a folder named after the chat". It is off by default, so nothing changes for existing users.

When it is on, a file is saved into a subfolder of the download directory named after the chat it came from, e.g. ~/Downloads/WhatsApp/Family/. The folder is created when the first file is saved.

  • It works in all three download modes. In "ask every time", the file picker opens in the chat folder.
  • Files from contact or group info (including its Media tab) go to that chat's folder.
  • Files from starred messages, chat list search or the all-chats media gallery go to the download directory, because there is no single chat they belong to.
  • If the chat folder cannot be created (permissions, a Flatpak path outside the shared folders), the file goes to the download directory. system/download_path is never changed.
  • Chat names are made safe for file names: slashes become _, the existing sanitize_file_name is reused, and a title with nothing visible left falls back to the download directory. The folder is always checked to stay inside the download directory, including through symlinks.

How it works

A small page script, chat_folder_tracker.js, is only installed while the setting is on. It watches pointer presses and tells ZapZap the open chat title through the existing theme QWebChannel (no second channel is created). The last press decides:

  • inside #main or the right drawer → the open chat title;
  • elsewhere on the main screen (chat list, left drawer) or in the all-chats gallery → no chat;
  • floating layers (media viewer, menus) → keep the previous value, unless the header now shows another chat.

The title is cleared on page load, renderer crash, closing the conversation and teardown. Turning the setting on or off reaches every open account through a new download_settings_events.organize_by_chat_changed signal, following the pdf_click_behavior_changed pattern.

Tests

  • New tests/test_chat_folder_tracker.py and new cases in tests/test_download_settings.py: the click rule, emoji titles (img alt), late or missing bridge, reset/destroy, a single listener after reinstall, folder creation before the dialog, fallback when makedirs fails, symlinks leaving the base folder, Unicode blank titles, and the settings switch.
  • Full suite in the Flatpak (com.rtosta.zapzap 7.5.1 runtime), as in AGENTS.md: 813 tests. The only failures are the same 8 that fail on main at 082e06c for me: 4 dictionary UI errors, the accounts context menu, the macOS PyInstaller packaging check and 2 zh_CN catalog tests. test_update_checker hover failed once in a full run and passed 3/3 alone; it looks flaky and is unrelated.
  • check_unused_code.py --packages-only, test_documentation_structure.py, compileall and git diff --check pass.
  • Checked inside the Flatpak sandbox: a chat folder under a path that is not shared falls back to the download directory without an error.
  • Tested by hand with a real WhatsApp account: contact chats, group chats, contact and group info media, starred messages, the all-chats gallery, "ask every time" and turning the setting off.

Not tested

  • Channels: the header selector was not checked on a channel page; if it does not match, downloads go to the download directory.
  • macOS and Windows builds.

Notes

  • Docs are updated in docs/architecture.md and docs/testing.md, and the changelog entry is under 7.5.2 - In development.
  • Translations: the new strings are translated for pt_BR, tr and zh_CN. The other catalogs only got regenerated line references from tools/translation_manager.py.
  • A file with the same name as an existing one still overwrites it. That is existing behaviour, also without this setting. I will send it as a separate PR.

🤖 Generated with Claude Code

atahan-claude and others added 19 commits November 16, 2026 09:33
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
When downloads are organized by chat, a page script reports the title of the
conversation the user last pressed in through the existing web channel
bridge. Presses in the chat list or drawers report no chat; floating layers
such as the media viewer and menus keep the previous value. The view keeps
the title for the download manager, drops the Save As suggestion only when a
different chat is opened, and forgets the title on page loads, conversation
close, renderer crashes and teardown. The setting applies live to every open
account through its change signal.

Tests:
- python -m unittest tests.test_chat_folder_tracker tests.test_download_settings tests.test_resizable_chat_list tests.test_quick_access_integration
- python -m unittest discover -s tests (no new failures besides the documentation structure check)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Chat titles made only of Unicode whitespace (no-break or ideographic
spaces) or dots produced a "download" folder. They now yield no chat
folder, so the file goes to the download directory.

Tests: python -m unittest tests.test_download_settings

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
_ensure_target_directory now only creates a missing chat folder and
leaves any existing directory alone. _begin_download catches only
RuntimeError and ValueError again, so failures other than the chat folder
fallback behave as before the feature.

Tests: python -m unittest tests.test_download_settings

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
In dialog mode DownloadDialog shows and opens download.downloadDirectory(),
which now points at the chat folder. Create it before building the dialog;
if it cannot be prepared, log and discard the unstarted download instead
of letting the error escape the Qt slot.

Tests: python -m unittest tests.test_download_settings

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The previous containment test used "../x", which is sanitized before the
containment check runs. A chat folder that is a symlink to a directory
outside the download directory now exercises the check and the fallback
to the configured directory. Also drop a stray blank line (E303).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A chat opened with the keyboard changes the header without a pointer
press, so a later click on a menu or the media viewer kept the previous
title and the download went to the wrong folder. On a floating layer the
tracker now re-reads the open chat title once and reports no chat when it
no longer matches. A title attribute holding only whitespace now falls
back to the header text.

Tests: python -m unittest tests.test_chat_folder_tracker

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Check close_conversation, the skipped tracker reset while shutting down or
with the setting off, the render crash and loadStarted in separate tests,
so a failure names the behaviour that broke.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Describe dialog mode creating the folder before DownloadDialog opens and
Ask every time creating it before the picker only without a remembered
Save As folder. Document the tracker re-reading the header on floating
layers, move its paragraph after the New chat paragraph it was splitting,
list the new tests and split the CHANGELOG sentence.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Files downloaded from the right drawer (contact or group info and its
media tab) belong to the open chat, so the tracker now reports the chat
title there instead of falling back to the download directory. The left
drawer, chat list and all-chats media gallery still report no chat.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The right drawer links to the all-chats media gallery, a floating dialog
outside the main screen. Clicks there kept the open chat title, so files
from any chat were saved into that chat's folder. Presses inside the
gallery now report no chat.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The chat folder switch description still said files from contact info go
to the download directory. Update it for the right drawer and the
all-chats media gallery, and refresh the tr, pt_BR and zh_CN
translations.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…pport

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@atahan150
atahan150 force-pushed the feat/downloads-chat-folders branch from 111b0a9 to e319df4 Compare November 16, 2026 06:37

This branch has not been deployed

No deployments
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.

1 participant