Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 24 additions & 12 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 10 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ authors = [
]
categories = ["network-programming"]
description = "High Performance Matrix Homeserver in Rust!"
# also update edition in rustfmt.toml
edition = "2024"
homepage = "https://tuwunel.chat"
keywords = [
Expand Down Expand Up @@ -231,7 +232,13 @@ rev = "93795449913f65ab533b7fa482333eef63fc3ae0"
[workspace.dependencies.jsonwebtoken]
version = "10.3"
default-features = false
features = ["use_pem"]
features = [
"aws_lc_rs",
"ed25519-dalek",
"hmac",
"sha2",
"use_pem",
]

[workspace.dependencies.ldap3]
git = "https://github.com/matrix-construct/ldap3"
Expand Down Expand Up @@ -267,7 +274,7 @@ version = "0.6"
features = ["std"]

[workspace.dependencies.nix]
version = "0.30"
version = "0"
default-features = false
features = [
"resource",
Expand Down Expand Up @@ -320,7 +327,7 @@ default-features = false

[workspace.dependencies.ruma]
git = "https://github.com/matrix-construct/ruma"
rev = "3cb939f5c8a67197433cbb3dc7e256f0ddaee978"
rev = "30d063c4503c3b630cdd55eda71a0bc3504518a2"
features = [
"__compat",
"appservice-api-c",
Expand Down
4 changes: 3 additions & 1 deletion rustfmt.toml
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
edition = "2024"
style_edition = "2024"

array_width = 80
attr_fn_like_width = 60
chain_width = 50
comment_width = 80
condense_wildcard_suffixes = true
style_edition = "2024"
fn_call_width = 80
fn_single_line = true
format_code_in_doc_comments = true
Expand Down
2 changes: 1 addition & 1 deletion src/admin/federation/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,6 @@ pub(super) async fn remote_user_in_rooms(&self, user_id: OwnedUserId) -> Result
.collect::<Vec<_>>()
.join("\n");

self.write_str(&format!("Rooms {user_id} shares with us ({num}):\n```\n{body}\n```",))
self.write_str(&format!("Rooms {user_id} shares with us ({num}):\n```\n{body}\n```"))
.await
}
6 changes: 3 additions & 3 deletions src/admin/media/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ pub(super) async fn delete_past_remote_media(
)
.await?;

self.write_str(&format!("Deleted {deleted_count} total files.",))
self.write_str(&format!("Deleted {deleted_count} total files."))
.await
}

Expand All @@ -204,7 +204,7 @@ pub(super) async fn delete_all_from_user(&self, username: String) -> Result {
.delete_from_user(&user_id)
.await?;

self.write_str(&format!("Deleted {deleted_count} total files.",))
self.write_str(&format!("Deleted {deleted_count} total files."))
.await
}

Expand Down Expand Up @@ -257,7 +257,7 @@ pub(super) async fn delete_all_from_server(
}
}

self.write_str(&format!("Deleted {deleted_count} total files.",))
self.write_str(&format!("Deleted {deleted_count} total files."))
.await
}

Expand Down
51 changes: 50 additions & 1 deletion src/admin/room/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ pub(super) async fn room_list(
.collect::<Vec<_>>()
.join("\n");

self.write_str(&format!("Rooms ({}):\n```\n{body}\n```", rooms.len(),))
self.write_str(&format!("Rooms ({}):\n```\n{body}\n```", rooms.len()))
.await
}

Expand Down Expand Up @@ -132,3 +132,52 @@ pub(super) async fn room_prune_empty(&self, force: bool) -> Result {

Ok(())
}

#[admin_command]
pub(super) async fn room_delete_rooms(
&self,
page: Option<usize>,
room_index: Vec<usize>,
force: bool,
exclude_disabled: bool,
exclude_banned: bool,
) -> Result {
let page = page.unwrap_or(1);
let mut rooms = self
.services
.metadata
.iter_ids()
.filter_map(async |room_id| {
(!exclude_disabled || !self.services.metadata.is_disabled(room_id).await)
.then_some(room_id)
})
.filter_map(async |room_id| {
(!exclude_banned || !self.services.metadata.is_banned(room_id).await)
.then_some(room_id)
})
.then(|room_id| get_room_info(self.services, room_id))
.collect::<Vec<_>>()
.await;

rooms.sort_by_key(|r| r.1);
rooms.reverse();
let rooms = rooms
.into_iter()
.skip(page.saturating_sub(1).saturating_mul(PAGE_SIZE))
.take(PAGE_SIZE)
.collect::<Vec<_>>();
// get room_id from room_index
let rooms = room_index
.iter()
.filter_map(|i| {
i.checked_sub(1)
.and_then(|idx| rooms.get(idx).cloned())
})
.collect::<Vec<_>>();
// call the delete_room function for each room
for room in rooms {
self.room_delete(room.0, force).await?;
}

Ok(())
}
2 changes: 1 addition & 1 deletion src/admin/room/directory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ pub(super) async fn process(command: RoomDirectoryCommand, context: &Context<'_>
.join("\n");

context
.write_str(&format!("Rooms (page {page}):\n```\n{body}\n```",))
.write_str(&format!("Rooms (page {page}):\n```\n{body}\n```"))
.await
},
}
Expand Down
2 changes: 1 addition & 1 deletion src/admin/room/info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ async fn list_joined_members(&self, room_id: OwnedRoomId, local_only: bool) -> R
.collect::<Vec<_>>()
.join("\n");

self.write_str(&format!("{num} Members in Room \"{room_name}\":\n```\n{body}\n```",))
self.write_str(&format!("{num} Members in Room \"{room_name}\":\n```\n{body}\n```"))
.await
}

Expand Down
17 changes: 17 additions & 0 deletions src/admin/room/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,21 @@ pub(super) enum RoomCommand {
#[arg(short, long)]
force: bool,
},

/// - Delete rooms
DeleteRooms {
#[arg(long)]
page: Option<usize>,

room_index: Vec<usize>,

#[arg(short, long)]
force: bool,

#[arg(long)]
exclude_disabled: bool,

#[arg(long)]
exclude_banned: bool,
},
}
2 changes: 1 addition & 1 deletion src/admin/room/moderation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,6 @@ async fn list_banned_rooms(&self, no_details: bool) -> Result {
.collect::<Vec<_>>()
.join("\n");

self.write_str(&format!("Rooms Banned ({num}):\n```\n{body}\n```",))
self.write_str(&format!("Rooms Banned ({num}):\n```\n{body}\n```"))
.await
}
2 changes: 1 addition & 1 deletion src/admin/token/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ pub(super) async fn issue(
.issue_token(expires)
.await?;

self.write_str(&format!("New registration token issued: `{token}` - {info}",))
self.write_str(&format!("New registration token issued: `{token}` - {info}"))
.await
}

Expand Down
8 changes: 4 additions & 4 deletions src/admin/user/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ pub(super) async fn list_joined_rooms(&self, user_id: String) -> Result {
.collect::<Vec<_>>()
.join("\n");

self.write_str(&format!("Rooms {user_id} Joined ({}):\n```\n{body}\n```", rooms.len(),))
self.write_str(&format!("Rooms {user_id} Joined ({}):\n```\n{body}\n```", rooms.len()))
.await
}

Expand Down Expand Up @@ -520,7 +520,7 @@ pub(super) async fn force_join_room(&self, user_id: String, room: OwnedRoomOrAli

drop(state_lock);

self.write_str(&format!("{user_id} has been joined to {room_id}.",))
self.write_str(&format!("{user_id} has been joined to {room_id}."))
.await
}

Expand Down Expand Up @@ -561,7 +561,7 @@ pub(super) async fn force_leave_room(

drop(state_lock);

self.write_str(&format!("{user_id} has left {room_id}.",))
self.write_str(&format!("{user_id} has left {room_id}."))
.await
}

Expand Down Expand Up @@ -728,7 +728,7 @@ pub(super) async fn make_user_admin(&self, user_id: String) -> Result {
.boxed()
.await?;

self.write_str(&format!("{user_id} has been granted admin privileges.",))
self.write_str(&format!("{user_id} has been granted admin privileges."))
.await
}

Expand Down
Loading