implement per-event state filtering for joined rooms in /sync

This commit is contained in:
Benjamin Lee 2024-05-10 19:02:46 -07:00
parent f4f3be8c30
commit 98d93da3a8
No known key found for this signature in database
GPG key ID: FB9624E2885D55A4

View file

@ -605,7 +605,10 @@ async fn load_joined_room(
error!("Pdu in state not found: {}", id);
continue;
};
state_events.push(pdu);
if filter.room.state.pdu_event_allowed(&pdu) {
state_events.push(pdu);
}
i += 1;
if i % 100 == 0 {
@ -624,12 +627,15 @@ async fn load_joined_room(
continue;
};
// This check is in case a bad user ID made it into the
// database
if let Ok(uid) = UserId::parse(&state_key) {
lazy_loaded.insert(uid);
if filter.room.state.pdu_event_allowed(&pdu) {
// This check is in case a bad user ID made it into
// the database
if let Ok(uid) = UserId::parse(&state_key) {
lazy_loaded.insert(uid);
}
state_events.push(pdu);
}
state_events.push(pdu);
i += 1;
if i % 100 == 0 {
@ -809,6 +815,9 @@ async fn load_joined_room(
let mut state_events = delta_state_events;
let mut lazy_loaded = HashSet::new();
state_events
.retain(|pdu| filter.room.state.pdu_event_allowed(pdu));
// Mark all member events we're returning as lazy-loaded
for pdu in &state_events {
if pdu.kind == TimelineEventType::RoomMember {
@ -857,8 +866,14 @@ async fn load_joined_room(
event.sender.as_str(),
)?
{
lazy_loaded.insert(event.sender.clone());
state_events.push(member_event);
if filter
.room
.state
.pdu_event_allowed(&member_event)
{
lazy_loaded.insert(event.sender.clone());
state_events.push(member_event);
}
}
}
}