Add is_direct() query for account_data.
Signed-off-by: Jason Volk <jason@zemos.net>
This commit is contained in:
parent
4ca68deef8
commit
51fc2342a4
2 changed files with 20 additions and 0 deletions
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;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue