2022-09-07 13:25:51 +02:00
|
|
|
use std::collections::HashMap;
|
2021-06-08 18:10:00 +02:00
|
|
|
|
2022-09-07 13:25:51 +02:00
|
|
|
use crate::Result;
|
2022-10-05 20:34:31 +02:00
|
|
|
use ruma::{
|
|
|
|
events::{AnyEphemeralRoomEvent, RoomAccountDataEventType},
|
|
|
|
serde::Raw,
|
|
|
|
RoomId, UserId,
|
|
|
|
};
|
2022-09-07 13:25:51 +02:00
|
|
|
|
2022-10-05 15:33:57 +02:00
|
|
|
pub trait Data: Send + Sync {
|
2020-05-03 17:25:31 +02:00
|
|
|
/// Places one event in the account data of the user and removes the previous entry.
|
2022-10-05 15:33:57 +02:00
|
|
|
fn update(
|
2020-05-03 17:25:31 +02:00
|
|
|
&self,
|
|
|
|
room_id: Option<&RoomId>,
|
|
|
|
user_id: &UserId,
|
2022-04-06 21:31:29 +02:00
|
|
|
event_type: RoomAccountDataEventType,
|
2022-10-05 15:33:57 +02:00
|
|
|
data: &serde_json::Value,
|
2022-09-07 13:25:51 +02:00
|
|
|
) -> Result<()>;
|
2020-05-03 17:25:31 +02:00
|
|
|
|
|
|
|
/// Searches the account data for a specific kind.
|
2022-10-05 15:33:57 +02:00
|
|
|
fn get(
|
2020-05-03 17:25:31 +02:00
|
|
|
&self,
|
|
|
|
room_id: Option<&RoomId>,
|
|
|
|
user_id: &UserId,
|
2022-04-06 21:31:29 +02:00
|
|
|
kind: RoomAccountDataEventType,
|
2022-10-05 15:33:57 +02:00
|
|
|
) -> Result<Option<Box<serde_json::value::RawValue>>>;
|
2020-05-03 17:25:31 +02:00
|
|
|
|
|
|
|
/// Returns all changes to the account data that happened after `since`.
|
2022-09-07 13:25:51 +02:00
|
|
|
fn changes_since(
|
2020-05-03 17:25:31 +02:00
|
|
|
&self,
|
|
|
|
room_id: Option<&RoomId>,
|
|
|
|
user_id: &UserId,
|
|
|
|
since: u64,
|
2022-09-07 13:25:51 +02:00
|
|
|
) -> Result<HashMap<RoomAccountDataEventType, Raw<AnyEphemeralRoomEvent>>>;
|
2020-05-03 17:25:31 +02:00
|
|
|
}
|