mirror of
https://gitlab.com/famedly/conduit.git
synced 2025-07-22 17:18:35 +00:00
wip
This commit is contained in:
parent
624d1fcc9a
commit
de806e5d1b
2 changed files with 132 additions and 44 deletions
|
@ -194,10 +194,10 @@ pub async fn get_context_route(
|
|||
.map(|(count, _)| count.stringify())
|
||||
.unwrap_or_else(|| base_token.stringify());
|
||||
|
||||
let events_after: Vec<_> = events_after
|
||||
let events_after = events_after
|
||||
.into_iter()
|
||||
.map(|(_, pdu)| pdu.to_room_event())
|
||||
.collect();
|
||||
.map(|(_, pdu)| pdu.to_room_event());
|
||||
// .collect();
|
||||
|
||||
let mut state = Vec::new();
|
||||
|
||||
|
|
|
@ -1,48 +1,136 @@
|
|||
use ruma::{api::client::filter::RoomEventFilter, events::AnyTimelineEvent, serde::Raw};
|
||||
use std::collections::HashSet;
|
||||
|
||||
pub fn filter_room_events<I: Iterator<Item = &Raw<AnyTimelineEvent>>>(
|
||||
use ruma::{
|
||||
api::client::filter::{LazyLoadOptions, RoomEventFilter},
|
||||
events::AnyTimelineEvent,
|
||||
serde::Raw,
|
||||
DeviceId, OwnedEventId, OwnedRoomId, OwnedUserId, RoomId, UserId,
|
||||
};
|
||||
|
||||
use crate::services;
|
||||
|
||||
pub fn filter_room_events<'i, I: Iterator<Item = &'i Raw<AnyTimelineEvent>>>(
|
||||
events: I,
|
||||
sender_user: &UserId,
|
||||
sender_device: &DeviceId,
|
||||
room_id: Option<&RoomId>,
|
||||
filter: RoomEventFilter,
|
||||
) {
|
||||
events
|
||||
.filter(|event| match &filter.types {
|
||||
None => true,
|
||||
Some(types) => types.iter().any(|t| {
|
||||
t.as_str()
|
||||
== event
|
||||
.get_field::<String>("type")
|
||||
.expect("room events should deserialize")
|
||||
.expect("room events should have a type")
|
||||
) -> crate::Result<Box<dyn Iterator<Item = &'i Raw<AnyTimelineEvent>>>> {
|
||||
let (lazy_load_enabled, lazy_load_send_redundant) = match &filter.lazy_load_options {
|
||||
LazyLoadOptions::Enabled {
|
||||
include_redundant_members,
|
||||
} => (true, *include_redundant_members),
|
||||
_ => (false, false),
|
||||
};
|
||||
|
||||
let it = Box::new(
|
||||
events
|
||||
.filter(|event| match &filter.rooms {
|
||||
None => true,
|
||||
Some(rooms) => rooms.iter().any(|r| {
|
||||
r.as_str()
|
||||
== event
|
||||
.get_field::<String>("room_id")
|
||||
.expect("room events should deserialize")
|
||||
.expect("room events should have a room_id")
|
||||
}),
|
||||
})
|
||||
.filter(|event| match &filter.not_rooms[..] {
|
||||
[] => true,
|
||||
not_rooms => not_rooms.iter().all(|r| {
|
||||
r.as_str()
|
||||
!= event
|
||||
.get_field::<String>("room_id")
|
||||
.expect("room events should deserialize")
|
||||
.expect("room events should have a room_id")
|
||||
}),
|
||||
})
|
||||
.filter(|event| match &filter.senders {
|
||||
None => true,
|
||||
Some(rooms) => rooms.iter().any(|r| {
|
||||
r.as_str()
|
||||
== event
|
||||
.get_field::<String>("sender")
|
||||
.expect("room events should deserialize")
|
||||
.expect("room events should have a sender")
|
||||
}),
|
||||
})
|
||||
.filter(|event| match &filter.not_senders[..] {
|
||||
[] => true,
|
||||
not_senders => not_senders.iter().all(|r| {
|
||||
r.as_str()
|
||||
!= event
|
||||
.get_field::<String>("sender")
|
||||
.expect("room events should deserialize")
|
||||
.expect("room events should have a sender")
|
||||
}),
|
||||
})
|
||||
.filter(|event| match &filter.types {
|
||||
None => true,
|
||||
Some(types) => types.iter().any(|t| {
|
||||
t.as_str()
|
||||
== event
|
||||
.get_field::<String>("type")
|
||||
.expect("room events should deserialize")
|
||||
.expect("room events should have a type")
|
||||
}),
|
||||
})
|
||||
.filter(|event| match &filter.not_types[..] {
|
||||
[] => true,
|
||||
not_types => not_types.iter().all(|t| {
|
||||
t.as_str()
|
||||
!= event
|
||||
.get_field::<String>("type")
|
||||
.expect("room events should deserialize")
|
||||
.expect("room events should have a type")
|
||||
}),
|
||||
})
|
||||
.filter(|event| {
|
||||
let room_id = event
|
||||
.get_field::<OwnedRoomId>("room_id")
|
||||
.expect("room events should deserialize")
|
||||
.expect("room events should have a room_id");
|
||||
let event_id = event
|
||||
.get_field::<OwnedEventId>("event_id")
|
||||
.expect("room events should deserialize")
|
||||
.expect("room events should have an event_id");
|
||||
|
||||
services()
|
||||
.rooms
|
||||
.state_accessor
|
||||
.user_can_see_event(sender_user, &room_id, &event_id)
|
||||
.unwrap_or(false)
|
||||
}),
|
||||
);
|
||||
|
||||
let memberships = it
|
||||
.map(|event| {
|
||||
let room_id = event
|
||||
.get_field::<OwnedRoomId>("room_id")
|
||||
.expect("room events should deserialize")
|
||||
.expect("room events should have a room_id");
|
||||
let sender = event
|
||||
.get_field::<OwnedUserId>("sender")
|
||||
.expect("room events should deserialize")
|
||||
.expect("room events should have a sender");
|
||||
|
||||
(room_id, sender)
|
||||
})
|
||||
.filter(|event| match &filter.not_types[..] {
|
||||
[] => true,
|
||||
not_types => not_types.iter().all(|t| {
|
||||
t.as_str()
|
||||
!= event
|
||||
.get_field::<String>("type")
|
||||
.expect("room events should deserialize")
|
||||
.expect("room events should have a type")
|
||||
}),
|
||||
.flat_map(|(room_id, sender)| {
|
||||
services()
|
||||
.rooms
|
||||
.lazy_loading
|
||||
.lazy_load_was_sent_before(sender_user, sender_device, &room_id, &sender)
|
||||
.map(|b| {
|
||||
if !b || lazy_load_send_redundant {
|
||||
Some(sender)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
})
|
||||
.transpose()
|
||||
})
|
||||
.filter(|event| match &filter.rooms {
|
||||
None => true,
|
||||
Some(rooms) => rooms.iter().any(|r| {
|
||||
r.as_str()
|
||||
== event
|
||||
.get_field::<String>("room_id")
|
||||
.expect("room events should deserialize")
|
||||
.expect("room events should have a type")
|
||||
}),
|
||||
})
|
||||
.filter(|event| match &filter.rooms {
|
||||
None => true,
|
||||
Some(rooms) => rooms.iter().all(|r| {
|
||||
r.as_str()
|
||||
!= event
|
||||
.get_field::<String>("room_id")
|
||||
.expect("room events should deserialize")
|
||||
.expect("room events should have a type")
|
||||
}),
|
||||
});
|
||||
.collect::<crate::Result<HashSet<_>>>()?;
|
||||
|
||||
Ok(it)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue