use std::sync::Arc; use conduit::{implement, Result}; use database::{Deserialized, Map}; use ruma::{CanonicalJsonObject, EventId}; use crate::PduEvent; pub struct Service { db: Data, } struct Data { eventid_outlierpdu: Arc, } impl crate::Service for Service { fn build(args: crate::Args<'_>) -> Result> { Ok(Arc::new(Self { db: Data { eventid_outlierpdu: args.db["eventid_outlierpdu"].clone(), }, })) } fn name(&self) -> &str { crate::service::make_name(std::module_path!()) } } /// Returns the pdu from the outlier tree. #[implement(Service)] pub async fn get_outlier_pdu_json(&self, event_id: &EventId) -> Result { self.db .eventid_outlierpdu .qry(event_id) .await .deserialized() } /// Returns the pdu from the outlier tree. #[implement(Service)] pub async fn get_pdu_outlier(&self, event_id: &EventId) -> Result { self.db .eventid_outlierpdu .qry(event_id) .await .deserialized() } /// Append the PDU as an outlier. #[implement(Service)] #[tracing::instrument(skip(self, pdu), level = "debug")] pub fn add_pdu_outlier(&self, event_id: &EventId, pdu: &CanonicalJsonObject) { self.db.eventid_outlierpdu.insert( event_id.as_bytes(), &serde_json::to_vec(&pdu).expect("CanonicalJsonObject is valid"), ); }