Toward abstracting Pdu into trait Event.
Signed-off-by: Jason Volk <jason@zemos.net>
This commit is contained in:
@@ -5,9 +5,7 @@ use futures::{
|
||||
};
|
||||
use ruma::{OwnedEventId, UserId, api::client::context::get_context, events::StateEventType};
|
||||
use tuwunel_core::{
|
||||
Err, Result, at, debug_warn, err,
|
||||
matrix::pdu::PduEvent,
|
||||
ref_at,
|
||||
Err, Event, Result, at, debug_warn, err, ref_at,
|
||||
utils::{
|
||||
IterStream,
|
||||
future::TryExtExt,
|
||||
@@ -190,14 +188,12 @@ pub(crate) async fn get_context_route(
|
||||
.get_pdu(event_id.as_ref())
|
||||
.ok()
|
||||
})
|
||||
.map(PduEvent::into_state_event)
|
||||
.map(Event::into_format)
|
||||
.collect()
|
||||
.await;
|
||||
|
||||
Ok(get_context::v3::Response {
|
||||
event: base_event
|
||||
.map(at!(1))
|
||||
.map(PduEvent::into_room_event),
|
||||
event: base_event.map(at!(1)).map(Event::into_format),
|
||||
|
||||
start: events_before
|
||||
.last()
|
||||
@@ -216,13 +212,13 @@ pub(crate) async fn get_context_route(
|
||||
events_before: events_before
|
||||
.into_iter()
|
||||
.map(at!(1))
|
||||
.map(PduEvent::into_room_event)
|
||||
.map(Event::into_format)
|
||||
.collect(),
|
||||
|
||||
events_after: events_after
|
||||
.into_iter()
|
||||
.map(at!(1))
|
||||
.map(PduEvent::into_room_event)
|
||||
.map(Event::into_format)
|
||||
.collect(),
|
||||
|
||||
state,
|
||||
|
||||
@@ -36,7 +36,8 @@ use ruma::{
|
||||
},
|
||||
};
|
||||
use tuwunel_core::{
|
||||
Err, Result, at, debug, debug_error, debug_info, debug_warn, err, error, info, is_matching,
|
||||
Err, Event, Result, at, debug, debug_error, debug_info, debug_warn, err, error, info,
|
||||
is_matching,
|
||||
matrix::{
|
||||
StateKey,
|
||||
pdu::{PduBuilder, PduEvent, gen_event_id, gen_event_id_canonical_json},
|
||||
@@ -907,7 +908,7 @@ pub(crate) async fn get_member_events_route(
|
||||
.ready_filter(|((ty, _), _)| *ty == StateEventType::RoomMember)
|
||||
.map(at!(1))
|
||||
.ready_filter_map(|pdu| membership_filter(pdu, membership, not_membership))
|
||||
.map(PduEvent::into_member_event)
|
||||
.map(Event::into_format)
|
||||
.collect()
|
||||
.await,
|
||||
})
|
||||
|
||||
@@ -161,7 +161,7 @@ pub(crate) async fn get_message_events_route(
|
||||
let chunk = events
|
||||
.into_iter()
|
||||
.map(at!(1))
|
||||
.map(PduEvent::into_room_event)
|
||||
.map(Event::into_format)
|
||||
.collect();
|
||||
|
||||
Ok(get_message_events::v3::Response {
|
||||
@@ -227,7 +227,7 @@ async fn get_member_event(
|
||||
.rooms
|
||||
.state_accessor
|
||||
.room_state_get(room_id, &StateEventType::RoomMember, user_id.as_str())
|
||||
.map_ok(PduEvent::into_state_event)
|
||||
.map_ok(Event::into_format)
|
||||
.await
|
||||
.ok()
|
||||
}
|
||||
|
||||
@@ -13,7 +13,7 @@ use ruma::{
|
||||
};
|
||||
use tuwunel_core::{
|
||||
Result, at,
|
||||
matrix::pdu::PduCount,
|
||||
matrix::{Event, pdu::PduCount},
|
||||
utils::{IterStream, ReadyExt, result::FlatOk, stream::WidebandExt},
|
||||
};
|
||||
use tuwunel_service::{Services, rooms::timeline::PdusIterItem};
|
||||
@@ -167,7 +167,7 @@ async fn paginate_relations_with_filter(
|
||||
chunk: events
|
||||
.into_iter()
|
||||
.map(at!(1))
|
||||
.map(|pdu| pdu.to_message_like_event())
|
||||
.map(Event::into_format)
|
||||
.collect(),
|
||||
})
|
||||
}
|
||||
|
||||
@@ -40,5 +40,5 @@ pub(crate) async fn get_room_event_route(
|
||||
|
||||
event.add_age().ok();
|
||||
|
||||
Ok(get_room_event::v3::Response { event: event.into_room_event() })
|
||||
Ok(get_room_event::v3::Response { event: event.into_format() })
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@ use axum::extract::State;
|
||||
use futures::TryStreamExt;
|
||||
use ruma::api::client::room::initial_sync::v3::{PaginationChunk, Request, Response};
|
||||
use tuwunel_core::{
|
||||
Err, PduEvent, Result, at,
|
||||
Err, Event, Result, at,
|
||||
utils::{BoolExt, stream::TryTools},
|
||||
};
|
||||
|
||||
@@ -38,7 +38,7 @@ pub(crate) async fn room_initial_sync_route(
|
||||
.rooms
|
||||
.state_accessor
|
||||
.room_state_full_pdus(room_id)
|
||||
.map_ok(PduEvent::into_state_event)
|
||||
.map_ok(Event::into_format)
|
||||
.try_collect()
|
||||
.await?;
|
||||
|
||||
@@ -59,7 +59,7 @@ pub(crate) async fn room_initial_sync_route(
|
||||
chunk: events
|
||||
.into_iter()
|
||||
.map(at!(1))
|
||||
.map(PduEvent::into_room_event)
|
||||
.map(Event::into_format)
|
||||
.collect(),
|
||||
};
|
||||
|
||||
|
||||
@@ -14,7 +14,7 @@ use ruma::{
|
||||
use search_events::v3::{Request, Response};
|
||||
use tuwunel_core::{
|
||||
Err, Result, at, is_true,
|
||||
matrix::pdu::PduEvent,
|
||||
matrix::Event,
|
||||
result::FlatOk,
|
||||
utils::{IterStream, stream::ReadyExt},
|
||||
};
|
||||
@@ -149,7 +149,7 @@ async fn category_room_events(
|
||||
.map(at!(2))
|
||||
.flatten()
|
||||
.stream()
|
||||
.map(PduEvent::into_room_event)
|
||||
.map(Event::into_format)
|
||||
.map(|result| SearchResult {
|
||||
rank: None,
|
||||
result: Some(result),
|
||||
@@ -190,7 +190,7 @@ async fn procure_room_state(services: &Services, room_id: &RoomId) -> Result<Roo
|
||||
.rooms
|
||||
.state_accessor
|
||||
.room_state_full_pdus(room_id)
|
||||
.map_ok(PduEvent::into_state_event)
|
||||
.map_ok(Event::into_format)
|
||||
.try_collect()
|
||||
.await?;
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
use axum::extract::State;
|
||||
use futures::TryStreamExt;
|
||||
use futures::{FutureExt, TryStreamExt};
|
||||
use ruma::{
|
||||
OwnedEventId, RoomId, UserId,
|
||||
api::client::state::{get_state_events, get_state_events_for_key, send_state_event},
|
||||
@@ -15,9 +15,10 @@ use ruma::{
|
||||
},
|
||||
serde::Raw,
|
||||
};
|
||||
use serde_json::json;
|
||||
use tuwunel_core::{
|
||||
Err, Result, err,
|
||||
matrix::pdu::{PduBuilder, PduEvent},
|
||||
matrix::{Event, pdu::PduBuilder},
|
||||
utils::BoolExt,
|
||||
};
|
||||
use tuwunel_service::Services;
|
||||
@@ -90,7 +91,7 @@ pub(crate) async fn get_state_events_route(
|
||||
.rooms
|
||||
.state_accessor
|
||||
.room_state_full_pdus(&body.room_id)
|
||||
.map_ok(PduEvent::into_state_event)
|
||||
.map_ok(Event::into_format)
|
||||
.try_collect()
|
||||
.await?,
|
||||
})
|
||||
@@ -141,7 +142,18 @@ pub(crate) async fn get_state_events_for_key_route(
|
||||
|
||||
Ok(get_state_events_for_key::v3::Response {
|
||||
content: event_format.or(|| event.get_content_as_value()),
|
||||
event: event_format.then(|| event.into_state_event_value()),
|
||||
event: event_format.then(|| {
|
||||
json!({
|
||||
"content": event.content(),
|
||||
"event_id": event.event_id(),
|
||||
"origin_server_ts": event.origin_server_ts(),
|
||||
"room_id": event.room_id(),
|
||||
"sender": event.sender(),
|
||||
"state_key": event.state_key(),
|
||||
"type": event.kind(),
|
||||
"unsigned": event.unsigned(),
|
||||
})
|
||||
}),
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -472,9 +472,7 @@ async fn handle_left_room(
|
||||
prev_batch: Some(next_batch.to_string()),
|
||||
events: Vec::new(),
|
||||
},
|
||||
state: RoomState {
|
||||
events: vec![event.into_sync_state_event()],
|
||||
},
|
||||
state: RoomState { events: vec![event.into_format()] },
|
||||
}));
|
||||
}
|
||||
|
||||
@@ -561,7 +559,7 @@ async fn handle_left_room(
|
||||
continue;
|
||||
}
|
||||
|
||||
left_state_events.push(pdu.into_sync_state_event());
|
||||
left_state_events.push(pdu.into_format());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -766,7 +764,7 @@ async fn load_joined_room(
|
||||
.wide_filter_map(|item| ignored_filter(services, item, sender_user))
|
||||
.map(at!(1))
|
||||
.chain(joined_sender_member.into_iter().stream())
|
||||
.map(|pdu| pdu.to_sync_room_event())
|
||||
.map(Event::into_format)
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
let account_data_events = services
|
||||
@@ -890,7 +888,7 @@ async fn load_joined_room(
|
||||
state: RoomState {
|
||||
events: state_events
|
||||
.into_iter()
|
||||
.map(PduEvent::into_sync_state_event)
|
||||
.map(Event::into_format)
|
||||
.collect(),
|
||||
},
|
||||
ephemeral: Ephemeral { events: edus },
|
||||
|
||||
@@ -23,11 +23,8 @@ use ruma::{
|
||||
uint,
|
||||
};
|
||||
use tuwunel_core::{
|
||||
Err, Error, Result, error, extract_variant, is_equal_to,
|
||||
matrix::{
|
||||
TypeStateKey,
|
||||
pdu::{PduCount, PduEvent},
|
||||
},
|
||||
Err, Error, Result, at, error, extract_variant, is_equal_to,
|
||||
matrix::{Event, TypeStateKey, pdu::PduCount},
|
||||
trace,
|
||||
utils::{
|
||||
BoolExt, FutureBoolExt, IterStream, ReadyExt, TryFutureExtExt,
|
||||
@@ -533,7 +530,8 @@ where
|
||||
.iter()
|
||||
.stream()
|
||||
.filter_map(|item| ignored_filter(services, item.clone(), sender_user))
|
||||
.map(|(_, pdu)| pdu.to_sync_room_event())
|
||||
.map(at!(1))
|
||||
.map(Event::into_format)
|
||||
.collect()
|
||||
.await;
|
||||
|
||||
@@ -556,7 +554,7 @@ where
|
||||
.state_accessor
|
||||
.room_state_get(room_id, &state.0, &state.1)
|
||||
.await
|
||||
.map(PduEvent::into_sync_state_event)
|
||||
.map(Event::into_format)
|
||||
.ok()
|
||||
})
|
||||
.collect()
|
||||
|
||||
@@ -3,7 +3,10 @@ use futures::StreamExt;
|
||||
use ruma::{api::client::threads::get_threads, uint};
|
||||
use tuwunel_core::{
|
||||
Result, at,
|
||||
matrix::pdu::{PduCount, PduEvent},
|
||||
matrix::{
|
||||
Event,
|
||||
pdu::{PduCount, PduEvent},
|
||||
},
|
||||
};
|
||||
|
||||
use crate::Ruma;
|
||||
@@ -56,7 +59,7 @@ pub(crate) async fn get_threads_route(
|
||||
chunk: threads
|
||||
.into_iter()
|
||||
.map(at!(1))
|
||||
.map(PduEvent::into_room_event)
|
||||
.map(Event::into_format)
|
||||
.collect(),
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user