Support optional device_id's in lazy-loading context.

Co-authored-by: Jade Ellis <jade@ellis.link>
Signed-off-by: Jason Volk <jason@zemos.net>
This commit is contained in:
Jason Volk 2025-04-28 01:32:13 +00:00 committed by Jade Ellis
parent 49f7a2487f
commit 2051c22a28
No known key found for this signature in database
GPG key ID: 8705A2A3EBF77BD2
4 changed files with 17 additions and 19 deletions

View file

@ -111,7 +111,7 @@ pub(crate) async fn get_context_route(
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, device_id: Some(sender_device),
room_id, room_id,
token: Some(base_count.into_unsigned()), token: Some(base_count.into_unsigned()),
options: Some(&filter.lazy_load_options), options: Some(&filter.lazy_load_options),

View file

@ -1,5 +1,3 @@
use core::panic;
use axum::extract::State; use axum::extract::State;
use conduwuit::{ use conduwuit::{
Err, Result, at, Err, Result, at,
@ -34,6 +32,7 @@ use ruma::{
}, },
serde::Raw, serde::Raw,
}; };
use tracing::warn;
use crate::Ruma; use crate::Ruma;
@ -73,7 +72,7 @@ pub(crate) async fn get_message_events_route(
) -> Result<get_message_events::v3::Response> { ) -> Result<get_message_events::v3::Response> {
debug_assert!(IGNORED_MESSAGE_TYPES.is_sorted(), "IGNORED_MESSAGE_TYPES is not sorted"); debug_assert!(IGNORED_MESSAGE_TYPES.is_sorted(), "IGNORED_MESSAGE_TYPES is not sorted");
let sender_user = body.sender_user(); let sender_user = body.sender_user();
let sender_device = body.sender_device.as_ref(); let sender_device = body.sender_device.as_deref();
let room_id = &body.room_id; let room_id = &body.room_id;
let filter = &body.filter; let filter = &body.filter;
@ -137,18 +136,17 @@ pub(crate) async fn get_message_events_route(
let lazy_loading_context = lazy_loading::Context { let lazy_loading_context = lazy_loading::Context {
user_id: sender_user, user_id: sender_user,
device_id: match sender_device { device_id: sender_device.or_else(|| {
| Some(device_id) => device_id,
| None =>
if let Some(registration) = body.appservice_info.as_ref() { if let Some(registration) = body.appservice_info.as_ref() {
<&DeviceId>::from(registration.registration.id.as_str()) Some(<&DeviceId>::from(registration.registration.id.as_str()))
} else { } else {
panic!( warn!(
"No device_id provided and no appservice registration found, this \ "No device_id provided and no appservice registration found, this should be \
should be unreachable" unreachable"
); );
}, None
}, }
}),
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),

View file

@ -645,7 +645,7 @@ async fn load_joined_room(
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, device_id: Some(sender_device),
room_id, room_id,
token: Some(since), token: Some(since),
options: Some(&filter.room.state.lazy_load_options), options: Some(&filter.room.state.lazy_load_options),

View file

@ -27,7 +27,7 @@ pub trait Options: Send + Sync {
#[derive(Clone, Debug)] #[derive(Clone, Debug)]
pub struct Context<'a> { pub struct Context<'a> {
pub user_id: &'a UserId, pub user_id: &'a UserId,
pub device_id: &'a DeviceId, pub device_id: Option<&'a DeviceId>,
pub room_id: &'a RoomId, pub room_id: &'a RoomId,
pub token: Option<u64>, pub token: Option<u64>,
pub options: Option<&'a LazyLoadOptions>, pub options: Option<&'a LazyLoadOptions>,
@ -40,7 +40,7 @@ pub enum Status {
} }
pub type Witness = HashSet<OwnedUserId>; pub type Witness = HashSet<OwnedUserId>;
type Key<'a> = (&'a UserId, &'a DeviceId, &'a RoomId, &'a UserId); type Key<'a> = (&'a UserId, Option<&'a DeviceId>, &'a RoomId, &'a UserId);
impl crate::Service for Service { impl crate::Service for Service {
fn build(args: crate::Args<'_>) -> Result<Arc<Self>> { fn build(args: crate::Args<'_>) -> Result<Arc<Self>> {