mirror of
https://gitlab.computer.surgery/matrix/grapevine.git
synced 2025-12-17 15:51:23 +01:00
create admin bot room alias id once and reuse it
This commit is contained in:
parent
95a24c761d
commit
339a869872
2 changed files with 18 additions and 22 deletions
|
|
@ -1,10 +1,4 @@
|
|||
use std::{
|
||||
collections::BTreeMap,
|
||||
convert::{TryFrom, TryInto},
|
||||
fmt::Write,
|
||||
sync::Arc,
|
||||
time::Instant,
|
||||
};
|
||||
use std::{collections::BTreeMap, fmt::Write, sync::Arc, time::Instant};
|
||||
|
||||
use clap::Parser;
|
||||
use regex::Regex;
|
||||
|
|
@ -29,8 +23,8 @@ use ruma::{
|
|||
TimelineEventType,
|
||||
},
|
||||
signatures::verify_json,
|
||||
EventId, MilliSecondsSinceUnixEpoch, OwnedRoomAliasId, OwnedRoomId,
|
||||
RoomAliasId, RoomId, RoomVersionId, ServerName, UserId,
|
||||
EventId, MilliSecondsSinceUnixEpoch, OwnedRoomId, RoomId, RoomVersionId,
|
||||
ServerName, UserId,
|
||||
};
|
||||
use serde_json::value::to_raw_value;
|
||||
use tokio::sync::{mpsc, Mutex, RwLock};
|
||||
|
|
@ -1410,10 +1404,7 @@ impl Service {
|
|||
.await?;
|
||||
|
||||
// 6. Room alias
|
||||
let alias: OwnedRoomAliasId =
|
||||
format!("#admins:{}", services().globals.server_name())
|
||||
.try_into()
|
||||
.expect("#admins:server_name is a valid alias name");
|
||||
let alias = &services().globals.admin_bot_room_alias_id;
|
||||
|
||||
services()
|
||||
.rooms
|
||||
|
|
@ -1436,7 +1427,7 @@ impl Service {
|
|||
)
|
||||
.await?;
|
||||
|
||||
services().rooms.alias.set_alias(&alias, &room_id)?;
|
||||
services().rooms.alias.set_alias(alias, &room_id)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
|
@ -1448,12 +1439,10 @@ impl Service {
|
|||
// Allowed because this function uses `services()`
|
||||
#[allow(clippy::unused_self)]
|
||||
pub(crate) fn get_admin_room(&self) -> Result<Option<OwnedRoomId>> {
|
||||
let admin_room_alias: Box<RoomAliasId> =
|
||||
format!("#admins:{}", services().globals.server_name())
|
||||
.try_into()
|
||||
.expect("#admins:server_name is a valid alias name");
|
||||
|
||||
services().rooms.alias.resolve_local_alias(&admin_room_alias)
|
||||
services()
|
||||
.rooms
|
||||
.alias
|
||||
.resolve_local_alias(&services().globals.admin_bot_room_alias_id)
|
||||
}
|
||||
|
||||
/// Invite the user to the grapevine admin room.
|
||||
|
|
|
|||
|
|
@ -24,8 +24,9 @@ use hyper_util::{
|
|||
use reqwest::dns::{Addrs, Name, Resolve, Resolving};
|
||||
use ruma::{
|
||||
api::federation::discovery::ServerSigningKeys, serde::Base64, DeviceId,
|
||||
MilliSecondsSinceUnixEpoch, OwnedEventId, OwnedRoomId, OwnedServerName,
|
||||
OwnedUserId, RoomVersionId, ServerName, UserId,
|
||||
MilliSecondsSinceUnixEpoch, OwnedEventId, OwnedRoomAliasId, OwnedRoomId,
|
||||
OwnedServerName, OwnedUserId, RoomAliasId, RoomVersionId, ServerName,
|
||||
UserId,
|
||||
};
|
||||
use tokio::sync::{broadcast, Mutex, RwLock, Semaphore};
|
||||
use tracing::{error, info, Instrument};
|
||||
|
|
@ -53,6 +54,7 @@ pub(crate) struct Service {
|
|||
pub(crate) stable_room_versions: Vec<RoomVersionId>,
|
||||
pub(crate) unstable_room_versions: Vec<RoomVersionId>,
|
||||
pub(crate) admin_bot_user_id: OwnedUserId,
|
||||
pub(crate) admin_bot_room_alias_id: OwnedRoomAliasId,
|
||||
pub(crate) bad_event_ratelimiter:
|
||||
Arc<RwLock<HashMap<OwnedEventId, RateLimitState>>>,
|
||||
pub(crate) bad_signature_ratelimiter:
|
||||
|
|
@ -218,6 +220,10 @@ impl Service {
|
|||
))
|
||||
.expect("admin bot user ID should be valid");
|
||||
|
||||
let admin_bot_room_alias_id =
|
||||
RoomAliasId::parse(format!("#admins:{}", config.server_name))
|
||||
.expect("admin bot room alias ID should be valid");
|
||||
|
||||
let mut s = Self {
|
||||
db,
|
||||
config,
|
||||
|
|
@ -244,6 +250,7 @@ impl Service {
|
|||
stable_room_versions,
|
||||
unstable_room_versions,
|
||||
admin_bot_user_id,
|
||||
admin_bot_room_alias_id,
|
||||
bad_event_ratelimiter: Arc::new(RwLock::new(HashMap::new())),
|
||||
bad_signature_ratelimiter: Arc::new(RwLock::new(HashMap::new())),
|
||||
bad_query_ratelimiter: Arc::new(RwLock::new(HashMap::new())),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue