Skip to main content

tuwunel_service/rooms/pdu_metadata/
mod.rs

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