Browse Source

add option to autoupdate nicks from notify

master
η (eta) 2 years ago
parent
commit
2f9bb6f535
  1. 10
      config.example.toml
  2. 4
      src/config.rs
  3. 20
      src/whatsapp.rs

10
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

4
src/config.rs

@ -56,7 +56,9 @@ pub struct WhatsappConfig {
#[serde(default)]
pub backlog_start: Option<chrono::NaiveDateTime>,
#[serde(default)]
pub mark_read: bool
pub mark_read: bool,
#[serde(default)]
pub autoupdate_nicks: bool
}
#[derive(Deserialize, Debug, Clone)]
pub struct IrcClientConfig {

20
src/whatsapp.rs

@ -78,12 +78,13 @@ pub struct WhatsappManager {
ack_resend: Option<u64>,
backlog_start: Option<chrono::NaiveDateTime>,
connected: bool,
mark_read: bool,
store: Store,
qr_path: String,
media_path: String,
dl_path: String,
autocreate: Option<String>,
autoupdate_nicks: bool,
mark_read: bool,
our_jid: Option<Jid>
}
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(())

Loading…
Cancel
Save