2022-06-25 16:12:23 +02:00
|
|
|
mod data;
|
2022-09-06 23:15:09 +02:00
|
|
|
use std::sync::Arc;
|
|
|
|
|
|
2022-06-25 16:12:23 +02:00
|
|
|
pub use data::Data;
|
2022-10-05 20:34:31 +02:00
|
|
|
use ruma::{EventId, RoomId};
|
2020-05-03 17:25:31 +02:00
|
|
|
|
2023-06-25 19:31:40 +02:00
|
|
|
use crate::{services, Result};
|
2022-06-25 16:12:23 +02:00
|
|
|
|
2022-10-05 12:45:54 +02:00
|
|
|
pub struct Service {
|
2022-10-08 13:02:52 +02:00
|
|
|
pub db: &'static dyn Data,
|
2022-06-25 16:12:23 +02:00
|
|
|
}
|
|
|
|
|
|
2022-10-05 12:45:54 +02:00
|
|
|
impl Service {
|
2023-06-25 19:31:40 +02:00
|
|
|
#[tracing::instrument(skip(self, from, to))]
|
|
|
|
|
pub fn add_relation(&self, from: &EventId, to: &EventId) -> Result<()> {
|
|
|
|
|
let from = services().rooms.short.get_or_create_shorteventid(from)?;
|
|
|
|
|
let to = services().rooms.short.get_or_create_shorteventid(to)?;
|
|
|
|
|
self.db.add_relation(from, to)
|
|
|
|
|
}
|
|
|
|
|
|
2021-08-24 19:10:31 +02:00
|
|
|
#[tracing::instrument(skip(self, room_id, event_ids))]
|
2021-11-27 17:44:52 +01:00
|
|
|
pub fn mark_as_referenced(&self, room_id: &RoomId, event_ids: &[Arc<EventId>]) -> Result<()> {
|
2022-06-25 16:12:23 +02:00
|
|
|
self.db.mark_as_referenced(room_id, event_ids)
|
2021-08-24 19:10:31 +02:00
|
|
|
}
|
|
|
|
|
|
2021-07-29 08:36:01 +02:00
|
|
|
#[tracing::instrument(skip(self))]
|
2021-07-20 12:41:35 +02:00
|
|
|
pub fn is_event_referenced(&self, room_id: &RoomId, event_id: &EventId) -> Result<bool> {
|
2022-06-25 16:12:23 +02:00
|
|
|
self.db.is_event_referenced(room_id, event_id)
|
2021-02-03 20:00:01 -05:00
|
|
|
}
|
|
|
|
|
|
2021-08-28 11:39:33 +02:00
|
|
|
#[tracing::instrument(skip(self))]
|
|
|
|
|
pub fn mark_event_soft_failed(&self, event_id: &EventId) -> Result<()> {
|
2022-06-25 16:12:23 +02:00
|
|
|
self.db.mark_event_soft_failed(event_id)
|
2021-08-28 11:39:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[tracing::instrument(skip(self))]
|
|
|
|
|
pub fn is_event_soft_failed(&self, event_id: &EventId) -> Result<bool> {
|
2022-06-25 16:12:23 +02:00
|
|
|
self.db.is_event_soft_failed(event_id)
|
2021-01-14 21:32:22 -05:00
|
|
|
}
|
2022-06-25 16:12:23 +02:00
|
|
|
}
|