2022-07-10 16:28:43 +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-09-06 23:15:09 +02:00
|
|
|
use ruma::RoomId;
|
2022-09-07 13:25:51 +02:00
|
|
|
|
2024-05-09 15:59:08 -07:00
|
|
|
pub struct Service {
|
2024-06-28 22:51:39 +00:00
|
|
|
db: Data,
|
2022-07-10 16:28:43 +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-10-05 12:45:54 +02:00
|
|
|
#[tracing::instrument(skip(self))]
|
2024-05-09 15:59:08 -07:00
|
|
|
pub fn index_pdu(&self, shortroomid: u64, pdu_id: &[u8], message_body: &str) -> Result<()> {
|
2022-10-05 12:45:54 +02:00
|
|
|
self.db.index_pdu(shortroomid, pdu_id, message_body)
|
|
|
|
|
}
|
|
|
|
|
|
2024-06-12 00:33:12 -04:00
|
|
|
#[tracing::instrument(skip(self))]
|
|
|
|
|
pub fn deindex_pdu(&self, shortroomid: u64, pdu_id: &[u8], message_body: &str) -> Result<()> {
|
|
|
|
|
self.db.deindex_pdu(shortroomid, pdu_id, message_body)
|
|
|
|
|
}
|
|
|
|
|
|
2021-08-19 11:01:18 +02:00
|
|
|
#[tracing::instrument(skip(self))]
|
2024-05-09 15:59:08 -07:00
|
|
|
pub fn search_pdus<'a>(
|
2020-08-18 12:15:27 +02:00
|
|
|
&'a self, room_id: &RoomId, search_string: &str,
|
2022-02-04 17:15:21 +01:00
|
|
|
) -> Result<Option<(impl Iterator<Item = Vec<u8>> + 'a, Vec<String>)>> {
|
2022-07-10 16:28:43 +02:00
|
|
|
self.db.search_pdus(room_id, search_string)
|
2020-08-21 21:22:59 +02:00
|
|
|
}
|
2022-07-10 16:28:43 +02:00
|
|
|
}
|