mirror of
https://forgejo.ellis.link/continuwuation/continuwuity.git
synced 2025-06-28 02:14:51 +02:00
57 lines
1.3 KiB
Rust
57 lines
1.3 KiB
Rust
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<Map>,
|
|
}
|
|
|
|
impl crate::Service for Service {
|
|
fn build(args: crate::Args<'_>) -> Result<Arc<Self>> {
|
|
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<CanonicalJsonObject> {
|
|
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<PduEvent> {
|
|
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"),
|
|
);
|
|
}
|