mirror of
https://forgejo.ellis.link/continuwuation/continuwuity.git
synced 2026-11-12 19:56:48 +00:00
feat: Reorganise federation commands
This commit is contained in:
2 files changed
+21
-63
No files matched your search
@@ -1,20 +1,19 @@
|
||||
use std::fmt::Write;
|
||||
|
||||
use conduwuit::{Err, Result, utils::response::LimitReadExt};
|
||||
use futures::StreamExt;
|
||||
use ruma::{MilliSecondsSinceUnixEpoch, OwnedRoomId, OwnedServerName, OwnedUserId};
|
||||
|
||||
use crate::get_room_info;
|
||||
use ruma::{MilliSecondsSinceUnixEpoch, OwnedRoomOrAliasId, OwnedServerName};
|
||||
|
||||
impl crate::Context<'_> {
|
||||
pub(super) async fn disable_room(&self, room_id: OwnedRoomId) -> Result {
|
||||
pub(super) async fn disable_room(&self, room: OwnedRoomOrAliasId) -> Result {
|
||||
self.bail_restricted()?;
|
||||
let room_id = self.services.rooms.alias.resolve(&room).await?;
|
||||
self.services.rooms.metadata.disable_room(&room_id, true);
|
||||
self.write_str("Room disabled.").await
|
||||
}
|
||||
|
||||
pub(super) async fn enable_room(&self, room_id: OwnedRoomId) -> Result {
|
||||
pub(super) async fn enable_room(&self, room: OwnedRoomOrAliasId) -> Result {
|
||||
self.bail_restricted()?;
|
||||
let room_id = self.services.rooms.alias.resolve(&room).await?;
|
||||
self.services.rooms.metadata.disable_room(&room_id, false);
|
||||
self.write_str("Room enabled.").await
|
||||
}
|
||||
@@ -33,13 +32,13 @@ impl crate::Context<'_> {
|
||||
map.len(),
|
||||
self.services.transactions.txn_active_handle_count()
|
||||
);
|
||||
for (r, (e, i)) in map.iter() {
|
||||
let elapsed = i.elapsed();
|
||||
for (room_id, (event_id, started_at)) in map.iter() {
|
||||
let elapsed = started_at.elapsed();
|
||||
writeln!(
|
||||
msg,
|
||||
"{} {}: {}m{}s",
|
||||
r,
|
||||
e,
|
||||
room_id,
|
||||
event_id,
|
||||
elapsed.as_secs() / 60,
|
||||
elapsed.as_secs() % 60
|
||||
)?;
|
||||
@@ -50,7 +49,7 @@ impl crate::Context<'_> {
|
||||
self.write_str(&msg).await
|
||||
}
|
||||
|
||||
pub(super) async fn fetch_support_well_known(&self, server_name: OwnedServerName) -> Result {
|
||||
pub(super) async fn fetch_support(&self, server_name: OwnedServerName) -> Result {
|
||||
let response = self
|
||||
.services
|
||||
.client
|
||||
@@ -97,41 +96,6 @@ impl crate::Context<'_> {
|
||||
.await
|
||||
}
|
||||
|
||||
pub(super) async fn remote_user_in_rooms(&self, user_id: OwnedUserId) -> Result {
|
||||
if user_id.server_name() == self.services.server.name {
|
||||
return Err!(
|
||||
"User belongs to our server, please use `list-joined-rooms` user admin command \
|
||||
instead.",
|
||||
);
|
||||
}
|
||||
|
||||
let mut rooms: Vec<(OwnedRoomId, u64, String)> = self
|
||||
.services
|
||||
.rooms
|
||||
.state_cache
|
||||
.rooms_joined(&user_id)
|
||||
.then(async |room_id| get_room_info(self.services, &room_id).await)
|
||||
.collect()
|
||||
.await;
|
||||
|
||||
if rooms.is_empty() {
|
||||
return Err!("User is not in any rooms.");
|
||||
}
|
||||
|
||||
rooms.sort_by_key(|r| r.1);
|
||||
rooms.reverse();
|
||||
|
||||
let num = rooms.len();
|
||||
let body = rooms
|
||||
.iter()
|
||||
.map(|(id, members, name)| format!("{id} | Members: {members} | Name: {name}"))
|
||||
.collect::<Vec<_>>()
|
||||
.join("\n");
|
||||
|
||||
self.write_str(&format!("Rooms {user_id} shares with us ({num}):\n```\n{body}\n```"))
|
||||
.await
|
||||
}
|
||||
|
||||
pub(super) async fn get_signing_keys(&self, server_name: OwnedServerName) -> Result {
|
||||
let response = self
|
||||
.services
|
||||
|
||||
+11
-17
@@ -2,7 +2,7 @@ mod commands;
|
||||
|
||||
use clap::Subcommand;
|
||||
use conduwuit::Result;
|
||||
use ruma::{OwnedRoomId, OwnedServerName, OwnedUserId};
|
||||
use ruma::{OwnedRoomId, OwnedRoomOrAliasId, OwnedServerName, OwnedUserId};
|
||||
|
||||
use crate::admin_command_dispatch;
|
||||
|
||||
@@ -10,36 +10,30 @@ use crate::admin_command_dispatch;
|
||||
#[derive(Debug, Subcommand)]
|
||||
pub enum FederationCommand {
|
||||
/// List all rooms we are currently handling an incoming pdu from
|
||||
#[clap(name="incoming", alias="inbound")]
|
||||
IncomingFederation,
|
||||
|
||||
/// Disables incoming federation handling for a room.
|
||||
///
|
||||
/// The room can still be used locally, but events from other servers will stop being received.
|
||||
DisableRoom {
|
||||
room_id: OwnedRoomId,
|
||||
room: OwnedRoomOrAliasId,
|
||||
},
|
||||
|
||||
/// Enables incoming federation handling for a room again.
|
||||
///
|
||||
/// This does not unban the room if it was banned, it only re-enables incoming events.
|
||||
EnableRoom {
|
||||
room_id: OwnedRoomId,
|
||||
room: OwnedRoomOrAliasId,
|
||||
},
|
||||
|
||||
/// Fetch `/.well-known/matrix/support` from the specified server
|
||||
/// Fetch support details from the given server.
|
||||
///
|
||||
/// Despite the name, this is not a federation endpoint and does not go
|
||||
/// through the federation / server resolution process as per-spec this is
|
||||
/// supposed to be served at the server_name.
|
||||
///
|
||||
/// Respecting homeservers put this file here for listing administration,
|
||||
/// moderation, and security inquiries. This command provides a way to
|
||||
/// easily fetch that information.
|
||||
FetchSupportWellKnown {
|
||||
/// This makes a request to `https://<server_name>/.well-known/matrix/support`. Many servers do not advertise support information, but those that do usually provide a way to contact homeserver administrators.
|
||||
FetchSupport {
|
||||
server_name: OwnedServerName,
|
||||
},
|
||||
|
||||
/// Lists all the rooms we share/track with the specified *remote* user
|
||||
RemoteUserInRooms {
|
||||
user_id: OwnedUserId,
|
||||
},
|
||||
|
||||
/// Queries the remote server for their current signing keys.
|
||||
GetSigningKeys {
|
||||
server_name: OwnedServerName,
|
||||
|
||||
Reference in new issue
Block a user