tuwunel_admin/user/
force_join_all_local_users.rs1use futures::StreamExt;
2use ruma::{OwnedRoomOrAliasId, UserId};
3use tuwunel_core::{Err, Result, debug_warn};
4
5use super::BULK_JOIN_REASON;
6use crate::admin_command;
7
8#[admin_command]
9pub(super) async fn force_join_all_local_users(
10 &self,
11 room: OwnedRoomOrAliasId,
12 yes_i_want_to_do_this: bool,
13) -> Result {
14 if !yes_i_want_to_do_this {
15 return Err!(
16 "You must pass the --yes-i-want-to-do-this-flag to ensure you really want to force \
17 bulk join all local users.",
18 );
19 }
20
21 let (room_id, servers) = self
22 .services
23 .alias
24 .maybe_resolve_with_servers(&room, None)
25 .await?;
26
27 if !self
28 .services
29 .state_cache
30 .server_in_room(self.services.globals.server_name(), &room_id)
31 .await
32 {
33 return Err!("We are not joined in this room.");
34 }
35
36 let mut failed_joins: usize = 0;
37 let mut successful_joins: usize = 0;
38
39 for user_id in &self
40 .services
41 .users
42 .list_local_users()
43 .map(UserId::to_owned)
44 .collect::<Vec<_>>()
45 .await
46 {
47 if user_id == &self.services.globals.server_user {
48 continue;
49 }
50
51 match self
52 .services
53 .membership
54 .join(
55 user_id,
56 &room_id,
57 Some(&room),
58 Some(String::from(BULK_JOIN_REASON)),
59 &servers,
60 false,
61 None,
62 )
63 .await
64 {
65 | Ok(_res) => {
66 successful_joins = successful_joins.saturating_add(1);
67 },
68 | Err(e) => {
69 debug_warn!("Failed force joining {user_id} to {room_id} during bulk join: {e}");
70 failed_joins = failed_joins.saturating_add(1);
71 },
72 }
73 }
74
75 write!(
76 self,
77 "{successful_joins} local users have been joined to {room_id}. {failed_joins} joins \
78 failed.",
79 )
80 .await
81}