2022-06-25 16:12:23 +02:00
|
|
|
mod data;
|
2022-10-08 13:04:55 +02:00
|
|
|
|
2024-05-09 15:59:08 -07:00
|
|
|
use std::sync::Arc;
|
|
|
|
|
|
2024-06-28 22:51:39 +00:00
|
|
|
use conduit::{Result, Server};
|
2024-05-26 21:29:19 +00:00
|
|
|
use data::Data;
|
2024-06-28 22:51:39 +00:00
|
|
|
use database::Database;
|
2022-10-09 17:25:06 +02:00
|
|
|
use ruma::{CanonicalJsonObject, EventId};
|
2022-06-25 16:12:23 +02:00
|
|
|
|
2024-06-28 22:51:39 +00:00
|
|
|
use crate::PduEvent;
|
2022-06-25 16:12:23 +02:00
|
|
|
|
2024-05-09 15:59:08 -07:00
|
|
|
pub struct Service {
|
2024-06-28 22:51:39 +00:00
|
|
|
db: Data,
|
2022-06-25 16:12:23 +02:00
|
|
|
}
|
|
|
|
|
|
2022-10-05 12:45:54 +02:00
|
|
|
impl Service {
|
2024-06-28 22:51:39 +00:00
|
|
|
pub fn build(_server: &Arc<Server>, db: &Arc<Database>) -> Result<Self> {
|
2024-05-27 03:17:20 +00:00
|
|
|
Ok(Self {
|
|
|
|
|
db: Data::new(db),
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-20 11:31:27 +02:00
|
|
|
/// Returns the pdu from the outlier tree.
|
2024-05-09 15:59:08 -07:00
|
|
|
pub fn get_outlier_pdu_json(&self, event_id: &EventId) -> Result<Option<CanonicalJsonObject>> {
|
2022-06-25 16:12:23 +02:00
|
|
|
self.db.get_outlier_pdu_json(event_id)
|
2022-06-20 11:31:27 +02:00
|
|
|
}
|
|
|
|
|
|
2021-01-14 21:32:22 -05:00
|
|
|
/// Returns the pdu from the outlier tree.
|
2024-04-22 23:54:56 -04:00
|
|
|
///
|
|
|
|
|
/// TODO: use this?
|
|
|
|
|
#[allow(dead_code)]
|
2024-05-09 15:59:08 -07:00
|
|
|
pub fn get_pdu_outlier(&self, event_id: &EventId) -> Result<Option<PduEvent>> { self.db.get_outlier_pdu(event_id) }
|
2021-01-14 21:32:22 -05:00
|
|
|
|
2021-02-03 20:00:01 -05:00
|
|
|
/// Append the PDU as an outlier.
|
2021-07-29 08:36:01 +02:00
|
|
|
#[tracing::instrument(skip(self, pdu))]
|
2024-05-09 15:59:08 -07:00
|
|
|
pub fn add_pdu_outlier(&self, event_id: &EventId, pdu: &CanonicalJsonObject) -> Result<()> {
|
2022-06-25 16:12:23 +02:00
|
|
|
self.db.add_pdu_outlier(event_id, pdu)
|
2021-08-28 11:39:33 +02:00
|
|
|
}
|
2022-06-25 16:12:23 +02:00
|
|
|
}
|