Skip to main content

tuwunel_service/account_data/
direct.rs

1use ruma::{
2	RoomId, UserId,
3	events::{GlobalAccountDataEventType, direct::DirectEventContent},
4};
5use tuwunel_core::{at, implement, is_equal_to};
6
7#[implement(super::Service)]
8pub async fn is_direct(&self, user_id: &UserId, room_id: &RoomId) -> bool {
9	self.services
10		.account_data
11		.get_global(user_id, GlobalAccountDataEventType::Direct)
12		.await
13		.map(|content: DirectEventContent| content)
14		.into_iter()
15		.flat_map(DirectEventContent::into_iter)
16		.map(at!(1))
17		.flat_map(Vec::into_iter)
18		.any(is_equal_to!(room_id))
19}