mirror of
https://forgejo.ellis.link/continuwuation/continuwuity.git
synced 2026-11-15 13:16:56 +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 std::fmt::Write;
|
||||||
|
|
||||||
use conduwuit::{Err, Result, utils::response::LimitReadExt};
|
use conduwuit::{Err, Result, utils::response::LimitReadExt};
|
||||||
use futures::StreamExt;
|
use ruma::{MilliSecondsSinceUnixEpoch, OwnedRoomOrAliasId, OwnedServerName};
|
||||||
use ruma::{MilliSecondsSinceUnixEpoch, OwnedRoomId, OwnedServerName, OwnedUserId};
|
|
||||||
|
|
||||||
use crate::get_room_info;
|
|
||||||
|
|
||||||
impl crate::Context<'_> {
|
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()?;
|
self.bail_restricted()?;
|
||||||
|
let room_id = self.services.rooms.alias.resolve(&room).await?;
|
||||||
self.services.rooms.metadata.disable_room(&room_id, true);
|
self.services.rooms.metadata.disable_room(&room_id, true);
|
||||||
self.write_str("Room disabled.").await
|
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()?;
|
self.bail_restricted()?;
|
||||||
|
let room_id = self.services.rooms.alias.resolve(&room).await?;
|
||||||
self.services.rooms.metadata.disable_room(&room_id, false);
|
self.services.rooms.metadata.disable_room(&room_id, false);
|
||||||
self.write_str("Room enabled.").await
|
self.write_str("Room enabled.").await
|
||||||
}
|
}
|
||||||
@@ -33,13 +32,13 @@ impl crate::Context<'_> {
|
|||||||
map.len(),
|
map.len(),
|
||||||
self.services.transactions.txn_active_handle_count()
|
self.services.transactions.txn_active_handle_count()
|
||||||
);
|
);
|
||||||
for (r, (e, i)) in map.iter() {
|
for (room_id, (event_id, started_at)) in map.iter() {
|
||||||
let elapsed = i.elapsed();
|
let elapsed = started_at.elapsed();
|
||||||
writeln!(
|
writeln!(
|
||||||
msg,
|
msg,
|
||||||
"{} {}: {}m{}s",
|
"{} {}: {}m{}s",
|
||||||
r,
|
room_id,
|
||||||
e,
|
event_id,
|
||||||
elapsed.as_secs() / 60,
|
elapsed.as_secs() / 60,
|
||||||
elapsed.as_secs() % 60
|
elapsed.as_secs() % 60
|
||||||
)?;
|
)?;
|
||||||
@@ -50,7 +49,7 @@ impl crate::Context<'_> {
|
|||||||
self.write_str(&msg).await
|
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
|
let response = self
|
||||||
.services
|
.services
|
||||||
.client
|
.client
|
||||||
@@ -97,41 +96,6 @@ impl crate::Context<'_> {
|
|||||||
.await
|
.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 {
|
pub(super) async fn get_signing_keys(&self, server_name: OwnedServerName) -> Result {
|
||||||
let response = self
|
let response = self
|
||||||
.services
|
.services
|
||||||
|
|||||||
+11
-17
@@ -2,7 +2,7 @@ mod commands;
|
|||||||
|
|
||||||
use clap::Subcommand;
|
use clap::Subcommand;
|
||||||
use conduwuit::Result;
|
use conduwuit::Result;
|
||||||
use ruma::{OwnedRoomId, OwnedServerName, OwnedUserId};
|
use ruma::{OwnedRoomId, OwnedRoomOrAliasId, OwnedServerName, OwnedUserId};
|
||||||
|
|
||||||
use crate::admin_command_dispatch;
|
use crate::admin_command_dispatch;
|
||||||
|
|
||||||
@@ -10,36 +10,30 @@ use crate::admin_command_dispatch;
|
|||||||
#[derive(Debug, Subcommand)]
|
#[derive(Debug, Subcommand)]
|
||||||
pub enum FederationCommand {
|
pub enum FederationCommand {
|
||||||
/// List all rooms we are currently handling an incoming pdu from
|
/// List all rooms we are currently handling an incoming pdu from
|
||||||
|
#[clap(name="incoming", alias="inbound")]
|
||||||
IncomingFederation,
|
IncomingFederation,
|
||||||
|
|
||||||
/// Disables incoming federation handling for a room.
|
/// Disables incoming federation handling for a room.
|
||||||
|
///
|
||||||
|
/// The room can still be used locally, but events from other servers will stop being received.
|
||||||
DisableRoom {
|
DisableRoom {
|
||||||
room_id: OwnedRoomId,
|
room: OwnedRoomOrAliasId,
|
||||||
},
|
},
|
||||||
|
|
||||||
/// Enables incoming federation handling for a room again.
|
/// 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 {
|
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
|
/// 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.
|
||||||
/// through the federation / server resolution process as per-spec this is
|
FetchSupport {
|
||||||
/// 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 {
|
|
||||||
server_name: OwnedServerName,
|
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.
|
/// Queries the remote server for their current signing keys.
|
||||||
GetSigningKeys {
|
GetSigningKeys {
|
||||||
server_name: OwnedServerName,
|
server_name: OwnedServerName,
|
||||||
|
|||||||
Reference in new issue
Block a user