2022-09-07 13:25:51 +02:00
|
|
|
use crate::Result;
|
2023-07-10 16:41:00 +02:00
|
|
|
use ruma::{
|
|
|
|
|
events::presence::PresenceEvent, presence::PresenceState, OwnedUserId, RoomId, UInt, UserId,
|
|
|
|
|
};
|
2022-09-06 23:15:09 +02:00
|
|
|
|
2022-10-05 15:33:57 +02:00
|
|
|
pub trait Data: Send + Sync {
|
2023-07-10 16:41:00 +02:00
|
|
|
/// Returns the latest presence event for the given user in the given room.
|
|
|
|
|
fn get_presence(&self, room_id: &RoomId, user_id: &UserId) -> Result<Option<PresenceEvent>>;
|
2022-06-25 16:12:23 +02:00
|
|
|
|
2023-07-10 16:41:00 +02:00
|
|
|
/// Pings the presence of the given user in the given room, setting the specified state.
|
|
|
|
|
fn ping_presence(&self, user_id: &UserId, new_state: PresenceState) -> Result<()>;
|
2022-06-25 16:12:23 +02:00
|
|
|
|
2023-07-10 16:41:00 +02:00
|
|
|
/// Adds a presence event which will be saved until a new event replaces it.
|
|
|
|
|
fn set_presence(
|
2022-07-10 14:37:34 +02:00
|
|
|
&self,
|
|
|
|
|
room_id: &RoomId,
|
|
|
|
|
user_id: &UserId,
|
2023-07-10 16:41:00 +02:00
|
|
|
presence_state: PresenceState,
|
|
|
|
|
currently_active: Option<bool>,
|
|
|
|
|
last_active_ago: Option<UInt>,
|
|
|
|
|
status_msg: Option<String>,
|
|
|
|
|
) -> Result<()>;
|
|
|
|
|
|
|
|
|
|
/// Removes the presence record for the given user from the database.
|
|
|
|
|
fn remove_presence(&self, user_id: &UserId) -> Result<()>;
|
2022-06-25 16:12:23 +02:00
|
|
|
|
|
|
|
|
/// Returns the most recent presence updates that happened after the event with id `since`.
|
2023-07-10 16:41:00 +02:00
|
|
|
fn presence_since<'a>(
|
|
|
|
|
&'a self,
|
2022-06-25 16:12:23 +02:00
|
|
|
room_id: &RoomId,
|
|
|
|
|
since: u64,
|
2023-12-20 12:04:47 +01:00
|
|
|
) -> Box<dyn Iterator<Item = (OwnedUserId, u64, PresenceEvent)> + 'a>;
|
2022-06-25 16:12:23 +02:00
|
|
|
}
|