1
0
Fork 0
mirror of https://forgejo.ellis.link/continuwuation/continuwuity.git synced 2025-07-28 10:48:30 +00:00
continuwuity/src/service/account_data/mod.rs

54 lines
1.4 KiB
Rust
Raw Normal View History

2022-09-07 13:25:51 +02:00
mod data;
use std::{collections::HashMap, sync::Arc};
2022-09-07 13:25:51 +02:00
use conduit::Result;
use data::Data;
2020-06-05 18:19:26 +02:00
use ruma::{
events::{AnyEphemeralRoomEvent, RoomAccountDataEventType},
serde::Raw,
RoomId, UserId,
2020-06-05 18:19:26 +02:00
};
2022-10-05 20:41:05 +02:00
pub struct Service {
db: Data,
2022-09-07 13:25:51 +02:00
}
2021-06-08 18:10:00 +02:00
impl crate::Service for Service {
fn build(args: crate::Args<'_>) -> Result<Arc<Self>> {
Ok(Arc::new(Self {
db: Data::new(args.db),
}))
}
fn name(&self) -> &str { crate::service::make_name(std::module_path!()) }
}
impl Service {
/// Places one event in the account data of the user and removes the
/// previous entry.
#[allow(clippy::needless_pass_by_value)]
pub fn update(
&self, room_id: Option<&RoomId>, user_id: &UserId, event_type: RoomAccountDataEventType,
data: &serde_json::Value,
) -> Result<()> {
self.db.update(room_id, user_id, &event_type, data)
}
/// Searches the account data for a specific kind.
#[allow(clippy::needless_pass_by_value)]
pub fn get(
&self, room_id: Option<&RoomId>, user_id: &UserId, event_type: RoomAccountDataEventType,
) -> Result<Option<Box<serde_json::value::RawValue>>> {
self.db.get(room_id, user_id, &event_type)
}
/// Returns all changes to the account data that happened after `since`.
#[tracing::instrument(skip_all, name = "since")]
pub fn changes_since(
&self, room_id: Option<&RoomId>, user_id: &UserId, since: u64,
) -> Result<HashMap<RoomAccountDataEventType, Raw<AnyEphemeralRoomEvent>>> {
self.db.changes_since(room_id, user_id, since)
}
}