diff --git a/config.example.toml b/config.example.toml index a24eda9..17ca35d 100644 --- a/config.example.toml +++ b/config.example.toml @@ -147,3 +147,13 @@ command_timeout_ms = 30000 # autocreate_prefix = "#wa" +## By default, messages are never marked as read, which may result in duplicate +## notifications if you still use WhatsApp on your phone. +## If you want messages to be marked as read, set `mark_read` to `true` below. +## +## /!\ Note that *every* message will be marked as read the instance the bridge +## receives it; this might cause your friends to get angry at not having +## read your messages...! + +mark_read = false + diff --git a/src/config.rs b/src/config.rs index be58f74..413423b 100644 --- a/src/config.rs +++ b/src/config.rs @@ -56,7 +56,9 @@ pub struct WhatsappConfig { #[serde(default)] pub backlog_start: Option, #[serde(default)] - pub mark_read: bool + pub mark_read: bool, + #[serde(default)] + pub autoupdate_nicks: bool } #[derive(Deserialize, Debug, Clone)] pub struct IrcClientConfig { diff --git a/src/whatsapp.rs b/src/whatsapp.rs index c5fab52..9ae8143 100644 --- a/src/whatsapp.rs +++ b/src/whatsapp.rs @@ -78,12 +78,13 @@ pub struct WhatsappManager { ack_resend: Option, backlog_start: Option, connected: bool, - mark_read: bool, store: Store, qr_path: String, media_path: String, dl_path: String, autocreate: Option, + autoupdate_nicks: bool, + mark_read: bool, our_jid: Option } impl Future for WhatsappManager { @@ -116,6 +117,7 @@ impl WhatsappManager { let ack_resend_ms = p.cfg.whatsapp.ack_resend_ms.clone(); let backlog_start = p.cfg.whatsapp.backlog_start.clone(); let mark_read = p.cfg.whatsapp.mark_read; + let autoupdate_nicks = p.cfg.whatsapp.autoupdate_nicks; wa_tx.unbounded_send(WhatsappCommand::LogonIfSaved) .unwrap(); let wa_tx = Arc::new(wa_tx); @@ -142,7 +144,8 @@ impl WhatsappManager { ack_expiry: ack_expiry_ms, ack_resend: ack_resend_ms, wa_tx, backlog_start, - rx, cf_tx, cb_tx, qr_path, store, media_path, dl_path, autocreate, mark_read + rx, cf_tx, cb_tx, qr_path, store, media_path, dl_path, autocreate, + mark_read, autoupdate_nicks } } fn handle_int_rx(&mut self, c: WhatsappCommand) -> Result<()> { @@ -858,6 +861,19 @@ impl WhatsappManager { if old_notify != notify { debug!("Notify changed for recipient {}: it's now {:?}", recip.nick, notify); self.store.update_recipient_notify(&addr, notify.as_ref().map(|x| x as &str))?; + if self.autoupdate_nicks && old_notify.is_none() { + if let Some(n) = notify { + let nick = util::string_to_irc_nick(&n); + info!("Automatically updating nick for {} to {}", addr, nick); + self.store.update_recipient_nick(&addr, &nick)?; + let cmd = ContactFactoryCommand::ForwardCommand( + addr, + crate::comm::ContactManagerCommand::ChangeNick(nick) + ); + self.cf_tx.unbounded_send(cmd) + .unwrap(); + } + } } } Ok(())