mirror of
https://gitlab.com/famedly/conduit.git
synced 2025-06-27 16:35:59 +00:00
style(presence): make type alias for presence_since iter
This commit is contained in:
parent
70652fe00c
commit
b4356917eb
3 changed files with 9 additions and 16 deletions
|
@ -13,7 +13,8 @@ use tokio::{sync::mpsc, time::sleep};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
database::KeyValueDatabase,
|
database::KeyValueDatabase,
|
||||||
service, services, utils,
|
service::{self, rooms::edus::presence::PresenceIter},
|
||||||
|
services, utils,
|
||||||
utils::{millis_since_unix_epoch, u64_from_bytes},
|
utils::{millis_since_unix_epoch, u64_from_bytes},
|
||||||
Error, Result,
|
Error, Result,
|
||||||
};
|
};
|
||||||
|
@ -148,11 +149,7 @@ impl service::rooms::edus::presence::Data for KeyValueDatabase {
|
||||||
.transpose()
|
.transpose()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn presence_since<'a>(
|
fn presence_since<'a>(&'a self, room_id: &RoomId, since: u64) -> Result<PresenceIter<'a>> {
|
||||||
&'a self,
|
|
||||||
room_id: &RoomId,
|
|
||||||
since: u64,
|
|
||||||
) -> Result<Box<dyn Iterator<Item = (OwnedUserId, PresenceEvent)> + 'a>> {
|
|
||||||
let user_timestamp: HashMap<OwnedUserId, u64> = self
|
let user_timestamp: HashMap<OwnedUserId, u64> = self
|
||||||
.userid_presenceupdate
|
.userid_presenceupdate
|
||||||
.iter()
|
.iter()
|
||||||
|
|
|
@ -2,6 +2,8 @@ use crate::Result;
|
||||||
use ruma::{events::presence::PresenceEvent, OwnedUserId, RoomId, UserId};
|
use ruma::{events::presence::PresenceEvent, OwnedUserId, RoomId, UserId};
|
||||||
use tokio::sync::mpsc;
|
use tokio::sync::mpsc;
|
||||||
|
|
||||||
|
use super::PresenceIter;
|
||||||
|
|
||||||
pub trait Data: Send + Sync {
|
pub trait Data: Send + Sync {
|
||||||
/// Adds a presence event which will be saved until a new event replaces it.
|
/// Adds a presence event which will be saved until a new event replaces it.
|
||||||
///
|
///
|
||||||
|
@ -34,11 +36,7 @@ pub trait Data: Send + Sync {
|
||||||
) -> Result<Option<PresenceEvent>>;
|
) -> Result<Option<PresenceEvent>>;
|
||||||
|
|
||||||
/// Returns the most recent presence updates that happened after the event with id `since`.
|
/// Returns the most recent presence updates that happened after the event with id `since`.
|
||||||
fn presence_since<'a>(
|
fn presence_since<'a>(&'a self, room_id: &RoomId, since: u64) -> Result<PresenceIter<'a>>;
|
||||||
&'a self,
|
|
||||||
room_id: &RoomId,
|
|
||||||
since: u64,
|
|
||||||
) -> Result<Box<dyn Iterator<Item = (OwnedUserId, PresenceEvent)> + 'a>>;
|
|
||||||
|
|
||||||
fn presence_maintain(&self, timer_receiver: mpsc::UnboundedReceiver<OwnedUserId>)
|
fn presence_maintain(&self, timer_receiver: mpsc::UnboundedReceiver<OwnedUserId>)
|
||||||
-> Result<()>;
|
-> Result<()>;
|
||||||
|
|
|
@ -6,6 +6,8 @@ use tokio::sync::mpsc;
|
||||||
|
|
||||||
use crate::{services, Error, Result};
|
use crate::{services, Error, Result};
|
||||||
|
|
||||||
|
pub(crate) type PresenceIter<'a> = Box<dyn Iterator<Item = (OwnedUserId, PresenceEvent)> + 'a>;
|
||||||
|
|
||||||
pub struct Service {
|
pub struct Service {
|
||||||
pub db: &'static dyn Data,
|
pub db: &'static dyn Data,
|
||||||
|
|
||||||
|
@ -99,11 +101,7 @@ impl Service {
|
||||||
|
|
||||||
/// Returns the most recent presence updates that happened after the event with id `since`.
|
/// Returns the most recent presence updates that happened after the event with id `since`.
|
||||||
#[tracing::instrument(skip(self, since, room_id))]
|
#[tracing::instrument(skip(self, since, room_id))]
|
||||||
pub fn presence_since(
|
pub fn presence_since<'a>(&'a self, room_id: &RoomId, since: u64) -> Result<PresenceIter<'a>> {
|
||||||
&self,
|
|
||||||
room_id: &RoomId,
|
|
||||||
since: u64,
|
|
||||||
) -> Result<Box<dyn Iterator<Item = (OwnedUserId, PresenceEvent)>>> {
|
|
||||||
if !services().globals.allow_presence() {
|
if !services().globals.allow_presence() {
|
||||||
return Ok(Box::new(std::iter::empty()));
|
return Ok(Box::new(std::iter::empty()));
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue