chore: comprehensive refactor — async DB, dependency bumps, chat sync events, and code quality #10

Merged
alisson merged 23 commits from refactor/updates into master 2026-07-05 00:26:35 -03:00
Owner

Summary

This PR contains a broad set of maintenance and feature improvements across the codebase, primarily focused on async safety, dependency updates, internationalization completeness, and preparing for live chat property updates from the WhatsApp sync stream.

Changes

Async & Threading

  • Offloaded all database operations to relm4::spawn to prevent blocking the GTK main thread (application.rs, store/database.rs).
  • Moved QR code generation into relm4::spawn_blocking (utils.rs).
  • Added spawn_blocking wrapper for libsql database connection setup.

Dependencies

  • Bumped libadwaita to 0.9 and relm4 to 0.11.
  • Switched whatsapp-rust from a git dependency to the crates.io registry.
  • Updated Cargo.lock accordingly.

WhatsApp Session & Sync

  • Added handling for SelfPushNameUpdated during initial sync (session/client.rs, application.rs).
  • Added infrastructure to handle chat property updates and sync events (session/client.rs, application.rs, components/chat_list.rs).

Code Quality & Refactors

  • Reordered struct fields across ChatRow, ChatRowWidgets, Login, Message, and Application to follow the "length-then-alphabetical" convention.
  • Boxed large enum variants in session/client.rs and components/chat_view.rs to reduce stack size.
  • Added i18n! translations to previously hardcoded error strings and the about dialog.
  • Fixed i18n_f! macro to use replacen for correct placeholder substitution.
  • Cleaned up import ordering and removed redundant fully-qualified names.

Documentation

  • Added AGENTS.md with comprehensive AI agent guidelines for project development.

Chores

  • Added a FIXME note for the currently unused PKGDATADIR constant in config.rs.in.
### Summary This PR contains a broad set of maintenance and feature improvements across the codebase, primarily focused on async safety, dependency updates, internationalization completeness, and preparing for live chat property updates from the WhatsApp sync stream. ### Changes **Async & Threading** - Offloaded all database operations to `relm4::spawn` to prevent blocking the GTK main thread (`application.rs`, `store/database.rs`). - Moved QR code generation into `relm4::spawn_blocking` (`utils.rs`). - Added `spawn_blocking` wrapper for libsql database connection setup. **Dependencies** - Bumped `libadwaita` to `0.9` and `relm4` to `0.11`. - Switched `whatsapp-rust` from a git dependency to the crates.io registry. - Updated `Cargo.lock` accordingly. **WhatsApp Session & Sync** - Added handling for `SelfPushNameUpdated` during initial sync (`session/client.rs`, `application.rs`). - Added infrastructure to handle chat property updates and sync events (`session/client.rs`, `application.rs`, `components/chat_list.rs`). **Code Quality & Refactors** - Reordered struct fields across `ChatRow`, `ChatRowWidgets`, `Login`, `Message`, and `Application` to follow the "length-then-alphabetical" convention. - Boxed large enum variants in `session/client.rs` and `components/chat_view.rs` to reduce stack size. - Added `i18n!` translations to previously hardcoded error strings and the about dialog. - Fixed `i18n_f!` macro to use `replacen` for correct placeholder substitution. - Cleaned up import ordering and removed redundant fully-qualified names. **Documentation** - Added `AGENTS.md` with comprehensive AI agent guidelines for project development. **Chores** - Added a `FIXME` note for the currently unused `PKGDATADIR` constant in `config.rs.in`.
- Add ChatPropertyUpdate messages for pin, mute, and archive events
- Process HistorySync events to extract conversations and messages
- Handle OfflineSyncCompleted to transition app state from syncing to ready
- Add HistorySyncCompleted and OfflineSyncCompleted signals
- Add RemoveChat input to ChatList for archived chats
- Fallback to extended_text_message text when conversation is empty
- Add ProcessHistorySync command for blocking protobuf parsing
alisson force-pushed refactor/updates from 2bb65731a7 to 59acd71526 2026-04-23 23:01:24 -03:00 Compare
- Switch libadwaita feature from v1_9 to v1_8 in Cargo.toml
- Switch relm4 feature from gnome_50 to gnome_49 in Cargo.toml
- Update AGENTS.md to reflect Relm4 0.11 and GNOME 49
andrielfr approved these changes 2026-04-23 23:43:49 -03:00
alisson force-pushed refactor/updates from ed55d3f71f to 6100766821 2026-07-04 19:34:24 -03:00 Compare
alisson force-pushed refactor/updates from 6100766821 to 965ace3e89 2026-07-04 19:54:05 -03:00 Compare
On Event::LoggedOut, the app was restarting the client with the same
stale credentials in whatsapp.db, causing an immediate LoggedOut event
and an infinite loop. Now:

- ClientCommand::LoggedOut disconnects and deletes whatsapp.db files
- ClientCommand::Restart also clears credentials before fresh start
- AppMsg::LoggedOut sends ClientInput::Start instead of ResetSession
- ClientCommand::Disconnected guards against stale events overwriting
  active connection states
@ -256,0 +281,4 @@
for path in [
db_path.as_path(),
std::path::Path::new(&wal_path),
Member

import Path and use it

import `Path` and use it
alisson marked this conversation as resolved
@ -256,0 +285,4 @@
std::path::Path::new(&shm_path),
] {
if path.exists()
&& let Err(e) = std::fs::remove_file(path)
Member

maybe it's ok to import std::fs too

maybe it's ok to import `std::fs` too
alisson marked this conversation as resolved
Messages synced from history sync arrived before their chats were
saved to the database, causing FOREIGN KEY constraint failures.
Duplicate server_id insertions also failed because save_message only
handled ON CONFLICT(local_id), but synced messages use random UUIDs
for local_id.

- Add Database::ensure_chat_exists (INSERT OR IGNORE INTO chats)
- Add Database::save_synced_message (INSERT OR IGNORE on both PKs)
- Add ChatMessage::save_or_ignore delegating to save_synced_message
- Remove early return in MessagesSynced handler that dropped messages
  for chats not yet in memory (they may arrive before ChatSynced)
- Use save_or_ignore in ProcessMessagesSync instead of save
- Skip adding chats to the list when they have no messages (chat_list.rs)
- Use NULLIF for empty server_id in save_synced_message to avoid UNIQUE
  constraint collisions across messages with no server ID
- Add detailed sync logging with duplicate/skip counts for diagnostics
alisson force-pushed refactor/updates from 1b7118e912 to 6d693f046c 2026-07-04 23:09:56 -03:00 Compare
alisson force-pushed refactor/updates from ca86033eec to 70ce8cc7eb 2026-07-04 23:53:28 -03:00 Compare
alisson force-pushed refactor/updates from 70ce8cc7eb to b4a8287351 2026-07-05 00:14:42 -03:00 Compare
alisson merged commit a6f875a9fc into master 2026-07-05 00:26:35 -03:00
alisson deleted branch refactor/updates 2026-07-05 00:26:35 -03:00
alisson referenced this pull request from a commit 2026-07-05 00:26:36 -03:00
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
AmanoTeam/Papo!10
No description provided.