fix: Disambiguate appservices in lazy loading context

In the previous commit, app services would all appear to be the same
device when accessing the same user. This sets the device ID to be the
appservice ID when available to avoid possible clobbering.
This commit is contained in:
Jade Ellis 2025-04-16 13:47:35 +01:00
parent 68d68a0645
commit 3a95585f0e
No known key found for this signature in database
GPG key ID: 8705A2A3EBF77BD2

View file

@ -26,7 +26,10 @@ use ruma::{
Direction, Direction,
client::{filter::RoomEventFilter, message::get_message_events}, client::{filter::RoomEventFilter, message::get_message_events},
}, },
events::{AnyStateEvent, StateEventType, TimelineEventType, TimelineEventType::*}, events::{
AnyStateEvent, StateEventType,
TimelineEventType::{self, *},
},
serde::Raw, serde::Raw,
}; };
@ -129,10 +132,20 @@ pub(crate) async fn get_message_events_route(
.take(limit) .take(limit)
.collect() .collect()
.await; .await;
// let appservice_id = body.appservice_info.map(|appservice|
// appservice.registration.id);
let lazy_loading_context = lazy_loading::Context { let lazy_loading_context = lazy_loading::Context {
user_id: sender_user, user_id: sender_user,
device_id: sender_device.map_or_else(|| <&DeviceId>::from(""), AsRef::as_ref), device_id: match sender_device {
| Some(device_id) => device_id,
| None =>
if let Some(registration) = body.appservice_info.as_ref() {
<&DeviceId>::from(registration.registration.id.as_str())
} else {
<&DeviceId>::from("")
},
},
room_id, room_id,
token: Some(from.into_unsigned()), token: Some(from.into_unsigned()),
options: Some(&filter.lazy_load_options), options: Some(&filter.lazy_load_options),