Skip to main content

tuwunel_service/rooms/pdu_metadata/
mod.rs

1use std::sync::Arc;
2
3use ruma::{
4	OwnedRoomId,
5	events::{AnySyncMessageLikeEvent, room::encrypted::Relation},
6	serde::Raw,
7};
8use serde::Deserialize;
9use tuwunel_core::Result;
10use tuwunel_database::Map;
11use tuwunel_matrix::Pdu;
12
13mod bundling;
14mod purge;
15mod references;
16mod relations;
17pub use relations::RelationQuery;
18pub(crate) mod typed_relations;
19
20#[cfg(test)]
21mod tests;
22
23pub struct Service {
24	services: Arc<crate::services::OnceServices>,
25	db: Data,
26}
27
28struct Data {
29	eventid_pduid: Arc<Map>,
30	tofrom_relation: Arc<Map>,
31	relatesto_typed: Arc<Map>,
32	referencedevents: Arc<Map>,
33	softfailedeventids: Arc<Map>,
34}
35
36#[derive(Deserialize)]
37struct ExtractRelatesTo {
38	#[serde(rename = "m.relates_to")]
39	relates_to: Relation,
40}
41
42#[derive(Deserialize)]
43struct ExtractRoomId {
44	room_id: OwnedRoomId,
45}
46
47/// Requester-specific MSC3856 adjustment for one thread root in `/threads`.
48///
49/// Root redaction, visible replies, latest event, and reply count depend on the
50/// requesting user and their ignore list, so the resulting view must not be
51/// reused across requesters.
52///
53/// `Unchanged` preserves the served root, while `WithoutSummary` removes only
54/// its thread bundle. Each `Adjusted` field is `None` when that facet needs no
55/// change. A supplied `root` provides redacted content while the caller retains
56/// the served `unsigned`.
57pub enum IgnoredThreadView {
58	Unchanged,
59	/// Retains the root without its thread summary.
60	WithoutSummary {
61		/// The redacted root to serve when its sender is ignored.
62		root: Option<Box<Pdu>>,
63	},
64	Adjusted {
65		root: Option<Box<Pdu>>,
66		count: Option<usize>,
67		latest: Option<Raw<AnySyncMessageLikeEvent>>,
68	},
69}
70
71impl crate::Service for Service {
72	fn build(args: &crate::Args<'_>) -> Result<Arc<Self>> {
73		Ok(Arc::new(Self {
74			services: args.services.clone(),
75			db: Data {
76				eventid_pduid: args.db["eventid_pduid"].clone(),
77				tofrom_relation: args.db["tofrom_relation"].clone(),
78				relatesto_typed: args.db["relatesto_typed"].clone(),
79				referencedevents: args.db["referencedevents"].clone(),
80				softfailedeventids: args.db["softfailedeventids"].clone(),
81			},
82		}))
83	}
84
85	fn name(&self) -> &str { crate::service::make_name(std::module_path!()) }
86}