test(notification-client): show room names wrong in sliding sync notifications

Signed-off-by: Michael Goldenberg <m@mgoldenberg.net>
This commit is contained in:
Michael Goldenberg
2026-02-06 10:29:24 -05:00
committed by Damir Jelić
parent f69e154e30
commit b35bea6c2b
@@ -1,7 +1,7 @@
// TODO: Remove this once all tests are re-enabled.
#![allow(unused)]
use std::sync::Arc;
use std::{collections::BTreeSet, sync::Arc};
use anyhow::{Result, ensure};
use assert_matches::assert_matches;
@@ -14,9 +14,12 @@ use matrix_sdk::{
api::client::room::create_room::v3::Request as CreateRoomRequest,
assign,
events::{
AnyStrippedStateEvent, SyncMessageLikeEvent, TimelineEventType,
AnyInitialStateEvent, AnyStrippedStateEvent, InitialStateEvent, StaticEventContent,
SyncMessageLikeEvent, TimelineEventType,
member_hints::{InitialMemberHintsEvent, MemberHintsEventContent},
room::{member::MembershipState, message::RoomMessageEventContent},
},
serde::Raw,
},
};
use matrix_sdk_ui::{
@@ -225,3 +228,88 @@ async fn test_notification() -> Result<()> {
Ok(())
}
#[tokio::test(flavor = "multi_thread", worker_threads = 4)]
async fn test_notification_room_display_name_excludes_service_members() -> Result<()> {
let alice = TestClientBuilder::new("alice").use_sqlite().build().await?;
let alice_user_id = alice.user_id().unwrap().to_owned();
let bob = TestClientBuilder::new("bob").use_sqlite().build().await?;
let bob_user_id = bob.user_id().unwrap().to_owned();
let charlie = TestClientBuilder::new("charlie").use_sqlite().build().await?;
let charlie_user_id = charlie.user_id().unwrap().to_owned();
// Initial setup: Alice creates a room, invites Bob and Charlie, sets Charlie as
// a service member.
let invite = vec![bob_user_id, charlie_user_id.clone()];
let member_hints_content = MemberHintsEventContent::new(BTreeSet::from([charlie_user_id]));
let initial_state =
vec![InitialStateEvent::with_empty_state_key(member_hints_content).to_raw_any()];
let request = assign!(CreateRoomRequest::new(), {
invite,
initial_state,
is_direct: true,
});
let room_id = alice.create_room(request).await?.room_id().to_owned();
// Bob and Charlie join room
bob.sync_once(Default::default()).await?;
bob.join_room_by_id(&room_id).await?;
charlie.sync_once(Default::default()).await?;
charlie.join_room_by_id(&room_id).await?;
// Bob sends a message
bob.get_room(&room_id)
.unwrap()
.send(RoomMessageEventContent::text_plain("Hello world!"))
.await?;
// In this sync, Alice receives message from Bob
let response = alice.sync_once(SyncSettings::default()).await?;
let event_id = response
.rooms
.joined
.get(&room_id)
.unwrap()
.timeline
.events
.iter()
.find_map(|event| {
let event = event.raw().deserialize().ok()?;
(event.event_type() == TimelineEventType::RoomMessage)
.then(|| event.event_id().to_owned())
})
.expect("message from bob in alice's client");
// The room name should simply be Bob's display name
let expected_display_name = bob.account().get_display_name().await?.unwrap();
let process_setup = NotificationProcessSetup::SingleProcess {
sync_service: Arc::new(SyncService::builder(alice.clone()).build().await?),
};
// Check that the notification we get with `/context` shows the correct room
// name
let notification_client =
NotificationClient::new(alice.clone(), process_setup.clone()).await.unwrap();
assert_let!(
NotificationStatus::Event(notification) =
notification_client.get_notification_with_context(&room_id, &event_id).await?
);
assert_eq!(notification.room_computed_display_name, expected_display_name);
// Check that the notification we get with sliding sync shows the correct room
// name
let notification_client =
NotificationClient::new(alice.clone(), process_setup.clone()).await.unwrap();
assert_let!(
NotificationStatus::Event(notification) =
notification_client.get_notification_with_sliding_sync(&room_id, &event_id).await?
);
assert_eq!(notification.room_computed_display_name, expected_display_name);
Ok(())
}