tuwunel_api/client/
utils.rs1use ruma::{EventId, RoomId, UserId};
2use tuwunel_core::{Err, Event, Result, warn};
3use tuwunel_service::Services;
4
5use crate::Ruma;
6
7pub(crate) async fn invite_check(
8 services: &Services,
9 sender_user: &UserId,
10 room_id: &RoomId,
11) -> Result {
12 if services.config.block_non_admin_invites && !services.admin.user_is_admin(sender_user).await
13 {
14 warn!("{sender_user} is not an admin and attempted to send an invite to {room_id}");
15 return Err!(Request(Forbidden("Invites are not allowed on this server.")));
16 }
17
18 Ok(())
19}
20
21pub(crate) async fn is_self_redaction(
22 services: &Services,
23 user_id: &UserId,
24 event_id: &EventId,
25) -> bool {
26 services
27 .timeline
28 .get_pdu(event_id)
29 .await
30 .is_ok_and(|target| target.sender() == user_id)
31}
32
33pub(crate) async fn may_set_displayname<T>(
39 services: &Services,
40 body: &Ruma<T>,
41 is_admin: impl AsyncFnOnce() -> bool,
42) -> bool
43where
44 T: Sync,
45{
46 services.config.enable_set_displayname || body.appservice_info.is_some() || is_admin().await
47}