mirror of
https://forgejo.ellis.link/continuwuation/continuwuity.git
synced 2025-07-12 09:16:23 +02:00
implement room.state.(not_)rooms filter on /sync
This commit is contained in:
parent
8b43336487
commit
4b6e2fae52
2 changed files with 111 additions and 109 deletions
|
@ -351,7 +351,11 @@ async fn sync_helper(
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
if !services().rooms.metadata.exists(&room_id)? {
|
let state = if !compiled_filter.room.state.room_allowed(&room_id) {
|
||||||
|
State {
|
||||||
|
events: vec![],
|
||||||
|
}
|
||||||
|
} else if !services().rooms.metadata.exists(&room_id)? {
|
||||||
// This is just a rejected invite, not a room we know
|
// This is just a rejected invite, not a room we know
|
||||||
// Insert a leave event anyways
|
// Insert a leave event anyways
|
||||||
let event = PduEvent {
|
let event = PduEvent {
|
||||||
|
@ -377,21 +381,10 @@ async fn sync_helper(
|
||||||
signatures: None,
|
signatures: None,
|
||||||
};
|
};
|
||||||
|
|
||||||
left_rooms.insert(
|
State {
|
||||||
room_id.into_owned(),
|
|
||||||
LeftRoom {
|
|
||||||
account_data: RoomAccountData {
|
|
||||||
events: Vec::new(),
|
|
||||||
},
|
|
||||||
timeline,
|
|
||||||
state: State {
|
|
||||||
events: vec![event.to_sync_state_event()],
|
events: vec![event.to_sync_state_event()],
|
||||||
},
|
|
||||||
},
|
|
||||||
);
|
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
let mut left_state_events = Vec::new();
|
let mut left_state_events = Vec::new();
|
||||||
|
|
||||||
let since_shortstatehash = services()
|
let since_shortstatehash = services()
|
||||||
|
@ -462,6 +455,11 @@ async fn sync_helper(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
State {
|
||||||
|
events: left_state_events,
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
left_rooms.insert(
|
left_rooms.insert(
|
||||||
room_id.into_owned(),
|
room_id.into_owned(),
|
||||||
LeftRoom {
|
LeftRoom {
|
||||||
|
@ -469,9 +467,7 @@ async fn sync_helper(
|
||||||
events: Vec::new(),
|
events: Vec::new(),
|
||||||
},
|
},
|
||||||
timeline,
|
timeline,
|
||||||
state: State {
|
state,
|
||||||
events: left_state_events,
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -727,6 +723,8 @@ async fn load_joined_room(
|
||||||
.user
|
.user
|
||||||
.get_token_shortstatehash(room_id, since)?;
|
.get_token_shortstatehash(room_id, since)?;
|
||||||
|
|
||||||
|
let skip_state_events = !filter.room.state.room_allowed(room_id);
|
||||||
|
|
||||||
let (heroes, joined_member_count, invited_member_count, joined_since_last_sync, state_events) =
|
let (heroes, joined_member_count, invited_member_count, joined_since_last_sync, state_events) =
|
||||||
if timeline_pdus.is_empty() && since_shortstatehash == Some(current_shortstatehash) {
|
if timeline_pdus.is_empty() && since_shortstatehash == Some(current_shortstatehash) {
|
||||||
// No state changes
|
// No state changes
|
||||||
|
@ -827,6 +825,7 @@ async fn load_joined_room(
|
||||||
let mut state_events = Vec::new();
|
let mut state_events = Vec::new();
|
||||||
let mut lazy_loaded = HashSet::new();
|
let mut lazy_loaded = HashSet::new();
|
||||||
|
|
||||||
|
if !skip_state_events {
|
||||||
let mut i = 0;
|
let mut i = 0;
|
||||||
for (shortstatekey, id) in current_state_ids {
|
for (shortstatekey, id) in current_state_ids {
|
||||||
let (event_type, state_key) = services()
|
let (event_type, state_key) = services()
|
||||||
|
@ -868,6 +867,7 @@ async fn load_joined_room(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Reset lazy loading because this is an initial sync
|
// Reset lazy loading because this is an initial sync
|
||||||
services()
|
services()
|
||||||
|
@ -891,7 +891,7 @@ async fn load_joined_room(
|
||||||
let mut state_events = Vec::new();
|
let mut state_events = Vec::new();
|
||||||
let mut lazy_loaded = HashSet::new();
|
let mut lazy_loaded = HashSet::new();
|
||||||
|
|
||||||
if since_shortstatehash != current_shortstatehash {
|
if !skip_state_events && since_shortstatehash != current_shortstatehash {
|
||||||
let current_state_ids = services()
|
let current_state_ids = services()
|
||||||
.rooms
|
.rooms
|
||||||
.state_accessor
|
.state_accessor
|
||||||
|
|
|
@ -137,6 +137,7 @@ pub(crate) struct CompiledFilterDefinition<'a> {
|
||||||
pub(crate) struct CompiledRoomFilter<'a> {
|
pub(crate) struct CompiledRoomFilter<'a> {
|
||||||
rooms: AllowDenyList<'a, RoomId>,
|
rooms: AllowDenyList<'a, RoomId>,
|
||||||
pub(crate) timeline: CompiledRoomEventFilter<'a>,
|
pub(crate) timeline: CompiledRoomEventFilter<'a>,
|
||||||
|
pub(crate) state: CompiledRoomEventFilter<'a>,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) struct CompiledRoomEventFilter<'a> {
|
pub(crate) struct CompiledRoomEventFilter<'a> {
|
||||||
|
@ -167,6 +168,7 @@ impl<'a> TryFrom<&'a RoomFilter> for CompiledRoomFilter<'a> {
|
||||||
// all of the sub-filters
|
// all of the sub-filters
|
||||||
rooms: AllowDenyList::from_slices(source.rooms.as_deref(), &source.not_rooms),
|
rooms: AllowDenyList::from_slices(source.rooms.as_deref(), &source.not_rooms),
|
||||||
timeline: (&source.timeline).try_into()?,
|
timeline: (&source.timeline).try_into()?,
|
||||||
|
state: (&source.state).try_into()?,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue