feat: add desktop notifications for incoming DMs and room messages - #6
Merged
Merged
Conversation
Introduce OS-level desktop notifications via the `notify-rust` crate so users are alerted to new messages when they are not actively viewing the relevant conversation or room. DM notifications fire when a message arrives from another user in a conversation that is not currently selected. Room message notifications follow the same logic — only triggering for messages from others in rooms the user is not viewing. Both notification types display the sender's display name and a truncated preview of the message content. Notifications are sent asynchronously via `tokio::spawn_blocking` to avoid blocking the TUI event loop, and failures (e.g. no notification daemon running) are logged as warnings rather than crashing the app. A `notifications_enabled` flag has been added to `CliConfig` (defaults to `true`) allowing users to disable notifications by setting `"notifications_enabled": false` in their config file. The field uses `serde(default)` for backward compatibility with existing configs.
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.
Summary
Introduce OS-level desktop notifications via the notify-rust crate so users are alerted to new messages when they are not actively viewing the relevant conversation or room.
DM notifications fire when a message arrives from another user in a conversation that is not currently selected. Room message notifications follow the same logic — only triggering for messages from others in rooms the user is not viewing. Both notification types display the sender's display name and a truncated preview of the message content.
Notifications are sent asynchronously via tokio::spawn_blocking to avoid blocking the TUI event loop, and failures (e.g. no notification daemon running) are logged as warnings rather than crashing the app.
A notifications_enabled flag has been added to CliConfig (defaults to true) allowing users to disable notifications by setting "notifications_enabled": false in their config file. The field uses serde(default) for backward compatibility with existing configs.
Changes
Added notify-rust = "4" dependency to crates/cli/Cargo.toml for cross-platform desktop notifications (D-Bus/zbus on Linux, native APIs on macOS/Windows)
Added notifications_enabled: bool field to CliConfig in crates/cli/src/config.rs with #[serde(default = "default_true")] for backward compatibility with existing config files
Added send_notification() helper method on App in crates/cli/src/tui/app.rs that fires notifications via tokio::spawn_blocking with graceful error handling
Wired DM notifications into the WsServerMessage::DmMessage handler — triggers for messages from others in inactive conversations
Wired room message notifications into the WsServerMessage::RoomMessage handler — triggers for messages from others in rooms the user is not currently viewing
Content previews are safely truncated to 100 characters using .chars().take(100) to avoid splitting multi-byte UTF-8
How to test
Build and run the CLI with cargo build -p lag-cli --release && ./target/release/lag
Log in and open a DM conversation with a friend
Have that friend (or a second account) send you a DM while you are viewing a different conversation — a desktop notification should appear showing the sender name and message preview
Switch to that conversation — subsequent messages from the same person should not trigger a notification
Navigate to a server room, then have someone send a message in a different room — a notification should appear with the sender and room name
Set "notifications_enabled": false in ~/.config/lag/config.json, restart the CLI, and repeat — no notifications should fire
Verify the app does not crash if no notification daemon is running (e.g. on a bare TTY) — a warning is logged instead