fix: Don't send webxdc notification for notify: "*" when chat is muted (#7658)

- webxdc notify specifically to Bob: notifies Bob even when chat is
muted
- webxdc notify to everyone ("*"): notifies Bob if he does not have the
chat muted

This aligns with how we handle notifications with quote replies.

---------

Co-authored-by: link2xt <link2xt@testrun.org>
This commit is contained in:
Casper Zandbergen
2025-12-30 23:14:35 +01:00
committed by GitHub
parent 25750de4e1
commit 516f0a1a98
3 changed files with 84 additions and 7 deletions

View File

@@ -1434,13 +1434,14 @@ impl EventTracker {
event_matcher: F,
) -> Option<EventType> {
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);
}
}
}

View File

@@ -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,

View File

@@ -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();