Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions benches/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::path::Path;

use criterion::{BatchSize, Criterion, criterion_group, criterion_main};
use gurk::app::App;
use gurk::config::{Config, User};
use gurk::config::{Config, NotificationConfig, User};
use gurk::signal::test::SignalManagerMock;
use gurk::storage::{ForgetfulStorage, MemCache};
use presage::libsignal_service::content::Content;
Expand All @@ -11,7 +11,10 @@ use tracing::info;
fn test_app() -> App {
let (app, _) = App::try_new(
Config {
notifications: false,
notifications: NotificationConfig {
enabled: false,
..Default::default()
},
..Config::with_user(User {
display_name: "Tyler Durden".to_string(),
})
Expand Down
24 changes: 18 additions & 6 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -719,8 +719,8 @@ impl App {
emoji,
HandleReactionOptions::new()
.remove(remove.unwrap_or(false))
.notify(true)
.bell(true),
.notify(self.config.notifications.show_reactions)
.bell(!self.config.notifications.mute_reactions_bell),
)
.await;
read.into_iter().for_each(|r| {
Expand Down Expand Up @@ -769,8 +769,8 @@ impl App {
emoji,
HandleReactionOptions::new()
.remove(remove.unwrap_or(false))
.notify(true)
.bell(true),
.notify(self.config.notifications.show_reactions)
.bell(!self.config.notifications.mute_reactions_bell),
)
.await;
return Ok(());
Expand Down Expand Up @@ -1424,8 +1424,20 @@ impl App {
}

fn notify(&self, summary: &str, text: &str) {
if self.config.notifications {
if let Err(e) = Notification::new().summary(summary).body(text).show() {
if self.config.notifications.enabled {
if let Err(e) = Notification::new()
.summary(if self.config.notifications.show_message_chat {
summary
} else {
"gurk"
})
.body(if self.config.notifications.show_message_text {
text
} else {
"New message!"
})
.show()
{
error!("failed to send notification: {}", e);
}
}
Expand Down
49 changes: 45 additions & 4 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ pub struct Config {
/// Whether to show receipts (sent, delivered, read) information next to your user name in UI
#[serde(default = "default_true")]
pub show_receipts: bool,
/// Whether to show system notifications on incoming messages
#[serde(default = "default_true")]
pub notifications: bool,
/// Notification settings
#[serde(default)]
pub notifications: NotificationConfig,
#[serde(default = "default_true")]
pub bell: bool,
/// User configuration
Expand Down Expand Up @@ -72,6 +72,37 @@ pub struct User {
pub display_name: String,
}

#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct NotificationConfig {
/// Whether to show system notifications on incoming messages
#[serde(default = "default_true")]
pub enabled: bool,
/// Whether to show message preview in notifications
#[serde(default = "default_true")]
pub show_message_text: bool,
/// Whether to show message origin in notifications
#[serde(default = "default_true")]
pub show_message_chat: bool,
/// Whether to show reactions in notifications
#[serde(default = "default_true")]
pub show_reactions: bool,
/// Whether to mute reactions bell
#[serde(default)]
pub mute_reactions_bell: bool,
}

impl Default for NotificationConfig {
fn default() -> Self {
Self {
enabled: true,
show_message_text: true,
show_message_chat: true,
show_reactions: true,
mute_reactions_bell: false,
}
}
}

#[cfg(feature = "dev")]
#[derive(Debug, Default, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct DeveloperConfig {
Expand Down Expand Up @@ -127,7 +158,7 @@ impl Config {
deprecated_signal_db_path: default_signal_db_path(),
first_name_only: false,
show_receipts: true,
notifications: true,
notifications: NotificationConfig::default(),
bell: true,
#[cfg(feature = "dev")]
developer: Default::default(),
Expand Down Expand Up @@ -220,6 +251,16 @@ impl Config {
message: "will be removed in a future version; use `<data_dir>/gurk.sqlite` instead",
});
}
if config_value
.get("notifications")
.and_then(|v| v.as_bool())
.is_some()
{
keys.push(DeprecatedConfigKey {
key: "notifications",
message: "boolean format is deprecated; use [notifications] section with enabled, show_message_text, show_message_chat, show_reactions and mute_reactions_bell fields",
});
}

let deprecated_keys = DeprecatedKeys {
file_path: path.to_path_buf(),
Expand Down
Loading