2022-09-07 13:25:51 +02:00
|
|
|
use crate::Result;
|
2022-09-06 23:15:09 +02:00
|
|
|
use ruma::{EventId, RoomId};
|
2022-10-05 20:34:31 +02:00
|
|
|
use std::collections::HashSet;
|
|
|
|
|
use std::sync::Arc;
|
2022-10-05 15:33:57 +02:00
|
|
|
use tokio::sync::MutexGuard;
|
2022-09-06 23:15:09 +02:00
|
|
|
|
2022-10-05 15:33:57 +02:00
|
|
|
pub trait Data: Send + Sync {
|
2022-06-25 16:12:23 +02:00
|
|
|
/// Returns the last state hash key added to the db for the given room.
|
2022-09-07 13:25:51 +02:00
|
|
|
fn get_room_shortstatehash(&self, room_id: &RoomId) -> Result<Option<u64>>;
|
2020-08-06 08:29:59 -04:00
|
|
|
|
2022-10-09 13:15:26 +02:00
|
|
|
/// Set the state hash to a new version, but does not update state_cache.
|
2022-10-05 20:34:31 +02:00
|
|
|
fn set_room_state(
|
|
|
|
|
&self,
|
|
|
|
|
room_id: &RoomId,
|
|
|
|
|
new_shortstatehash: u64,
|
2022-09-07 13:25:51 +02:00
|
|
|
_mutex_lock: &MutexGuard<'_, ()>, // Take mutex guard to make sure users get the room state mutex
|
|
|
|
|
) -> Result<()>;
|
2022-06-25 16:12:23 +02:00
|
|
|
|
|
|
|
|
/// Associates a state with an event.
|
2022-09-07 13:25:51 +02:00
|
|
|
fn set_event_state(&self, shorteventid: u64, shortstatehash: u64) -> Result<()>;
|
2022-06-25 16:12:23 +02:00
|
|
|
|
|
|
|
|
/// Returns all events we would send as the prev_events of the next event.
|
2022-09-07 13:25:51 +02:00
|
|
|
fn get_forward_extremities(&self, room_id: &RoomId) -> Result<HashSet<Arc<EventId>>>;
|
2022-06-25 16:12:23 +02:00
|
|
|
|
|
|
|
|
/// Replace the forward extremities of the room.
|
2022-10-05 20:34:31 +02:00
|
|
|
fn set_forward_extremities<'a>(
|
|
|
|
|
&self,
|
2022-06-25 16:12:23 +02:00
|
|
|
room_id: &RoomId,
|
2022-10-05 20:33:55 +02:00
|
|
|
event_ids: Vec<Box<EventId>>,
|
2022-09-07 13:25:51 +02:00
|
|
|
_mutex_lock: &MutexGuard<'_, ()>, // Take mutex guard to make sure users get the room state mutex
|
2022-09-06 23:15:09 +02:00
|
|
|
) -> Result<()>;
|
2022-06-25 16:12:23 +02:00
|
|
|
}
|