Add is_direct() query for account_data.
Signed-off-by: Jason Volk <jason@zemos.net>
This commit is contained in:
19
src/service/account_data/direct.rs
Normal file
19
src/service/account_data/direct.rs
Normal file
@@ -0,0 +1,19 @@
|
||||
use ruma::{
|
||||
RoomId, UserId,
|
||||
events::{GlobalAccountDataEventType, direct::DirectEventContent},
|
||||
};
|
||||
use tuwunel_core::{at, implement, is_equal_to};
|
||||
|
||||
#[implement(super::Service)]
|
||||
pub async fn is_direct(&self, user_id: &UserId, room_id: &RoomId) -> bool {
|
||||
self.services
|
||||
.account_data
|
||||
.get_global(user_id, GlobalAccountDataEventType::Direct)
|
||||
.await
|
||||
.map(|content: DirectEventContent| content)
|
||||
.into_iter()
|
||||
.flat_map(DirectEventContent::into_iter)
|
||||
.map(at!(1))
|
||||
.flat_map(Vec::into_iter)
|
||||
.any(is_equal_to!(room_id))
|
||||
}
|
||||
@@ -1,3 +1,4 @@
|
||||
mod direct;
|
||||
mod room_tags;
|
||||
|
||||
use std::sync::Arc;
|
||||
|
||||
Reference in New Issue
Block a user