style(presence): make type alias for presence_since iter

This commit is contained in:
Jakub Kubík 2022-12-07 18:36:47 +01:00
parent 70652fe00c
commit b4356917eb
No known key found for this signature in database
GPG key ID: D3A0D5D60F3A173F
3 changed files with 9 additions and 16 deletions

View file

@ -13,7 +13,8 @@ use tokio::{sync::mpsc, time::sleep};
use crate::{
database::KeyValueDatabase,
service, services, utils,
service::{self, rooms::edus::presence::PresenceIter},
services, utils,
utils::{millis_since_unix_epoch, u64_from_bytes},
Error, Result,
};
@ -148,11 +149,7 @@ impl service::rooms::edus::presence::Data for KeyValueDatabase {
.transpose()
}
fn presence_since<'a>(
&'a self,
room_id: &RoomId,
since: u64,
) -> Result<Box<dyn Iterator<Item = (OwnedUserId, PresenceEvent)> + 'a>> {
fn presence_since<'a>(&'a self, room_id: &RoomId, since: u64) -> Result<PresenceIter<'a>> {
let user_timestamp: HashMap<OwnedUserId, u64> = self
.userid_presenceupdate
.iter()

View file

@ -2,6 +2,8 @@ use crate::Result;
use ruma::{events::presence::PresenceEvent, OwnedUserId, RoomId, UserId};
use tokio::sync::mpsc;
use super::PresenceIter;
pub trait Data: Send + Sync {
/// 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>>;
/// Returns the most recent presence updates that happened after the event with id `since`.
fn presence_since<'a>(
&'a self,
room_id: &RoomId,
since: u64,
) -> Result<Box<dyn Iterator<Item = (OwnedUserId, PresenceEvent)> + 'a>>;
fn presence_since<'a>(&'a self, room_id: &RoomId, since: u64) -> Result<PresenceIter<'a>>;
fn presence_maintain(&self, timer_receiver: mpsc::UnboundedReceiver<OwnedUserId>)
-> Result<()>;

View file

@ -6,6 +6,8 @@ use tokio::sync::mpsc;
use crate::{services, Error, Result};
pub(crate) type PresenceIter<'a> = Box<dyn Iterator<Item = (OwnedUserId, PresenceEvent)> + 'a>;
pub struct Service {
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`.
#[tracing::instrument(skip(self, since, room_id))]
pub fn presence_since(
&self,
room_id: &RoomId,
since: u64,
) -> Result<Box<dyn Iterator<Item = (OwnedUserId, PresenceEvent)>>> {
pub fn presence_since<'a>(&'a self, room_id: &RoomId, since: u64) -> Result<PresenceIter<'a>> {
if !services().globals.allow_presence() {
return Ok(Box::new(std::iter::empty()));
}