diff --git a/src/test_utils.rs b/src/test_utils.rs index 666140802..fbdd4f2a2 100644 --- a/src/test_utils.rs +++ b/src/test_utils.rs @@ -1434,13 +1434,14 @@ impl EventTracker { event_matcher: F, ) -> Option { ctx.emit_event(EventType::Test); + let mut found_event = None; loop { let event = self.recv().await.unwrap(); - if event_matcher(&event.typ) { - return Some(event.typ); - } if let EventType::Test = event.typ { - return None; + return found_event; + } + if event_matcher(&event.typ) { + found_event = Some(event.typ); } } } diff --git a/src/webxdc.rs b/src/webxdc.rs index fb962294e..ac15583bd 100644 --- a/src/webxdc.rs +++ b/src/webxdc.rs @@ -411,8 +411,16 @@ impl Context { && let Some(notify_list) = status_update_item.notify { let self_addr = instance.get_webxdc_self_addr(self).await?; - if let Some(notify_text) = notify_list.get(&self_addr).or_else(|| notify_list.get("*")) + let notify_text = if let Some(notify_text) = notify_list.get(&self_addr) { + Some(notify_text) + } else if let Some(notify_text) = notify_list.get("*") + && !Chat::load_from_db(self, instance.chat_id).await?.is_muted() { + Some(notify_text) + } else { + None + }; + if let Some(notify_text) = notify_text { self.emit_event(EventType::IncomingWebxdcNotify { chat_id: instance.chat_id, contact_id: from_id, diff --git a/src/webxdc/webxdc_tests.rs b/src/webxdc/webxdc_tests.rs index 3a03d606f..c0d4f87ee 100644 --- a/src/webxdc/webxdc_tests.rs +++ b/src/webxdc/webxdc_tests.rs @@ -5,8 +5,8 @@ use serde_json::json; use super::*; use crate::chat::{ - ChatId, add_contact_to_chat, create_broadcast, create_group, forward_msgs, - remove_contact_from_chat, resend_msgs, send_msg, send_text_msg, + ChatId, MuteDuration, add_contact_to_chat, create_broadcast, create_group, forward_msgs, + remove_contact_from_chat, resend_msgs, send_msg, send_text_msg, set_muted, }; use crate::chatlist::Chatlist; use crate::config::Config; @@ -2073,6 +2073,74 @@ async fn test_webxdc_notify_all() -> Result<()> { Ok(()) } +#[tokio::test(flavor = "multi_thread", worker_threads = 2)] +async fn test_webxdc_notify_muted() -> Result<()> { + let mut tcm = TestContextManager::new(); + let alice = tcm.alice().await; + let bob = tcm.bob().await; + let fiona = tcm.fiona().await; + + let grp_id = alice + .create_group_with_members("grp", &[&bob, &fiona]) + .await; + let alice_instance = send_webxdc_instance(&alice, grp_id).await?; + let sent1 = alice.pop_sent_msg().await; + let bob_instance = bob.recv_msg(&sent1).await; + let fiona_instance = fiona.recv_msg(&sent1).await; + + set_muted(&bob, bob_instance.chat_id, MuteDuration::Forever).await?; + + alice + .send_webxdc_status_update( + alice_instance.id, + "{\"payload\":7,\"info\": \"all\", \"notify\":{\"*\":\"notify all\"} }", + ) + .await?; + alice.flush_status_updates().await?; + let sent2 = alice.pop_sent_msg().await; + let info_msg = alice.get_last_msg().await; + assert_eq!(info_msg.text, "all"); + assert!(!has_incoming_webxdc_event(&alice, info_msg, "notify all").await); + + bob.recv_msg_trash(&sent2).await; + let info_msg = bob.get_last_msg().await; + assert_eq!(info_msg.text, "all"); + assert!(!has_incoming_webxdc_event(&bob, info_msg, "notify all").await); + + fiona.recv_msg_trash(&sent2).await; + let info_msg = fiona.get_last_msg().await; + assert_eq!(info_msg.text, "all"); + assert!(has_incoming_webxdc_event(&fiona, info_msg, "notify all").await); + + alice + .send_webxdc_status_update( + alice_instance.id, + &format!( + "{{\"payload\":8,\"info\": \"reply\", \"notify\":{{\"{}\":\"reply, Bob\",\"{}\":\"reply, Fiona\"}} }}", + bob_instance.get_webxdc_self_addr(&bob).await?, + fiona_instance.get_webxdc_self_addr(&fiona).await? + ), + ) + .await?; + alice.flush_status_updates().await?; + let sent3 = alice.pop_sent_msg().await; + let info_msg = alice.get_last_msg().await; + assert_eq!(info_msg.text, "reply"); + assert!(!has_incoming_webxdc_event(&alice, info_msg, "").await); + + bob.recv_msg_trash(&sent3).await; + let info_msg = bob.get_last_msg().await; + assert_eq!(info_msg.text, "reply"); + assert!(has_incoming_webxdc_event(&bob, info_msg, "reply, Bob").await); + + fiona.recv_msg_trash(&sent3).await; + let info_msg = fiona.get_last_msg().await; + assert_eq!(info_msg.text, "reply"); + assert!(has_incoming_webxdc_event(&fiona, info_msg, "reply, Fiona").await); + + Ok(()) +} + #[tokio::test(flavor = "multi_thread", worker_threads = 2)] async fn test_webxdc_notify_bob_and_all() -> Result<()> { let mut tcm = TestContextManager::new();