Skip to content

feat: add desktop notifications for incoming DMs and room messages - #6

Merged
mooncitizen merged 2 commits into
mainfrom
feat/introducing-notifications
Mar 31, 2026
Merged

mooncitizen merged 2 commits into
mainfrom
feat/introducing-notifications

Conversation

@mooncitizen

@mooncitizen mooncitizen commented Mar 31, 2026 •

Copy link
Copy Markdown
Contributor

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

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.
@mooncitizen
mooncitizen merged commit 899c1f6 into main Mar 31, 2026
2 checks passed
@mooncitizen
mooncitizen deleted the feat/introducing-notifications branch March 31, 2026 11:44
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