conduwuit/src/service/rooms/state/data.rs

29 lines
1.1 KiB
Rust
Raw Normal View History

use std::sync::Arc;
2022-10-05 15:33:57 +02:00
use std::collections::HashSet;
2022-09-07 13:25:51 +02:00
use crate::Result;
use ruma::{EventId, RoomId};
2022-10-05 15:33:57 +02:00
use tokio::sync::MutexGuard;
2022-10-05 15:33:57 +02:00
pub trait Data: Send + Sync {
/// 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>>;
/// Update the current state of the room.
2022-09-07 13:25:51 +02:00
fn set_room_state(&self, room_id: &RoomId, new_shortstatehash: u64,
_mutex_lock: &MutexGuard<'_, ()>, // Take mutex guard to make sure users get the room state mutex
) -> Result<()>;
/// Associates a state with an event.
2022-09-07 13:25:51 +02:00
fn set_event_state(&self, shorteventid: u64, shortstatehash: u64) -> Result<()>;
/// 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>>>;
/// Replace the forward extremities of the room.
2022-09-07 13:25:51 +02:00
fn set_forward_extremities<'a>(&self,
room_id: &RoomId,
2022-10-05 15:33:57 +02:00
event_ids: &mut dyn Iterator<Item = &'a EventId>,
2022-09-07 13:25:51 +02:00
_mutex_lock: &MutexGuard<'_, ()>, // Take mutex guard to make sure users get the room state mutex
) -> Result<()>;
}