From 5db574b44fb59468e07fd71d00b3911cf78a361c Mon Sep 17 00:00:00 2001 From: iequidoo Date: Sun, 24 Nov 2024 21:42:35 -0300 Subject: [PATCH] refactor: create_status_update_record: Get rid of `notify` var It's used in the only place. Also this way `get_webxdc_self_addr()` which makes a db query is only called when necessary. --- src/webxdc.rs | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/src/webxdc.rs b/src/webxdc.rs index 518fbcbfd..4945408fa 100644 --- a/src/webxdc.rs +++ b/src/webxdc.rs @@ -326,12 +326,6 @@ impl Context { return Ok(None); }; - let notify = if let Some(notify_list) = status_update_item.notify { - let self_addr = instance.get_webxdc_self_addr(self).await?; - notify_list.contains(&self_addr) - } else { - false - }; let mut notify_msg_id = instance.id; let mut notify_text = "".to_string(); let mut param_changed = false; @@ -412,12 +406,17 @@ impl Context { }); } - if notify && !notify_text.is_empty() && from_id != ContactId::SELF { - self.emit_event(EventType::IncomingWebxdcNotify { - contact_id: from_id, - msg_id: notify_msg_id, - text: notify_text, - }); + if !notify_text.is_empty() && from_id != ContactId::SELF { + if let Some(notify_list) = status_update_item.notify { + let self_addr = instance.get_webxdc_self_addr(self).await?; + if notify_list.contains(&self_addr) { + self.emit_event(EventType::IncomingWebxdcNotify { + contact_id: from_id, + msg_id: notify_msg_id, + text: notify_text, + }); + } + } } Ok(Some(status_update_serial))