implement room.account_data.(not_)rooms filter on /sync

This commit is contained in:
Benjamin Lee 2024-05-21 14:18:51 -07:00
parent 84f356e67b
commit 745eaa9b48
No known key found for this signature in database
GPG key ID: FB9624E2885D55A4
2 changed files with 23 additions and 14 deletions

View file

@ -951,6 +951,26 @@ async fn load_joined_room(
vec![]
};
let account_data_events = if filter.room.account_data.room_allowed(room_id)
{
services()
.account_data
.changes_since(Some(room_id), sender_user, since)?
.into_iter()
.filter_map(|(_, v)| {
serde_json::from_str(v.json().get())
.map_err(|_| {
Error::bad_database(
"Invalid account event in database.",
)
})
.ok()
})
.collect()
} else {
vec![]
};
// Save the state after this sync so we can send the correct state diff next
// sync
services().rooms.user.associate_token_shortstatehash(
@ -961,20 +981,7 @@ async fn load_joined_room(
Ok(JoinedRoom {
account_data: RoomAccountData {
events: services()
.account_data
.changes_since(Some(room_id), sender_user, since)?
.into_iter()
.filter_map(|(_, v)| {
serde_json::from_str(v.json().get())
.map_err(|_| {
Error::bad_database(
"Invalid account event in database.",
)
})
.ok()
})
.collect(),
events: account_data_events,
},
summary: RoomSummary {
heroes,

View file

@ -158,6 +158,7 @@ pub(crate) struct CompiledFilterDefinition<'a> {
pub(crate) struct CompiledRoomFilter<'a> {
rooms: AllowDenyList<'a, RoomId>,
pub(crate) account_data: CompiledRoomEventFilter<'a>,
pub(crate) timeline: CompiledRoomEventFilter<'a>,
pub(crate) ephemeral: CompiledRoomEventFilter<'a>,
pub(crate) state: CompiledRoomEventFilter<'a>,
@ -198,6 +199,7 @@ impl<'a> TryFrom<&'a RoomFilter> for CompiledRoomFilter<'a> {
source.rooms.as_deref(),
&source.not_rooms,
),
account_data: (&source.account_data).try_into()?,
timeline: (&source.timeline).try_into()?,
ephemeral: (&source.ephemeral).try_into()?,
state: (&source.state).try_into()?,