mirror of
https://gitlab.com/famedly/conduit.git
synced 2025-07-27 17:28:36 +00:00
reviewed changes
This commit is contained in:
parent
1761de5d03
commit
a51a4fdef9
6 changed files with 39 additions and 95 deletions
|
@ -3,11 +3,10 @@ pub use data::{Data, SigningKeys};
|
|||
|
||||
use ruma::{
|
||||
serde::Base64, MilliSecondsSinceUnixEpoch, OwnedDeviceId, OwnedEventId, OwnedRoomAliasId,
|
||||
OwnedRoomId, OwnedServerName, OwnedUserId, RoomAliasId,
|
||||
OwnedRoomId, OwnedRoomOrAliasId, OwnedServerName, OwnedUserId, RoomAliasId,
|
||||
};
|
||||
use tokio::sync::OnceCell;
|
||||
|
||||
use crate::api::server_server::DestinationResponse;
|
||||
use crate::api::{client_server::get_alias_helper, server_server::DestinationResponse};
|
||||
|
||||
use crate::{services, Config, Error, Result};
|
||||
use futures_util::FutureExt;
|
||||
|
@ -70,7 +69,6 @@ pub struct Service {
|
|||
pub roomid_mutex_state: RwLock<HashMap<OwnedRoomId, Arc<Mutex<()>>>>,
|
||||
pub roomid_mutex_federation: RwLock<HashMap<OwnedRoomId, Arc<Mutex<()>>>>, // this lock will be held longer
|
||||
pub roomid_federationhandletime: RwLock<HashMap<OwnedRoomId, (OwnedEventId, Instant)>>,
|
||||
default_rooms: OnceCell<BTreeSet<OwnedRoomId>>,
|
||||
server_user: OwnedUserId,
|
||||
admin_alias: OwnedRoomAliasId,
|
||||
pub stateres_mutex: Arc<Mutex<()>>,
|
||||
|
@ -224,7 +222,6 @@ impl Service {
|
|||
roomid_mutex_insert: RwLock::new(HashMap::new()),
|
||||
roomid_mutex_federation: RwLock::new(HashMap::new()),
|
||||
roomid_federationhandletime: RwLock::new(HashMap::new()),
|
||||
default_rooms: OnceCell::new(),
|
||||
stateres_mutex: Arc::new(Mutex::new(())),
|
||||
sync_receivers: RwLock::new(HashMap::new()),
|
||||
rotate: RotationHandler::new(),
|
||||
|
@ -509,66 +506,32 @@ impl Service {
|
|||
self.config.well_known_client()
|
||||
}
|
||||
|
||||
pub async fn default_rooms(&self) -> Result<&BTreeSet<OwnedRoomId>> {
|
||||
if let Some(default_rooms) = self.default_rooms.get() {
|
||||
return Ok(default_rooms);
|
||||
}
|
||||
|
||||
pub async fn default_rooms(&self) -> Result<BTreeSet<OwnedRoomId>> {
|
||||
let mut default_rooms = BTreeSet::new();
|
||||
|
||||
for mut alias_or_id in self.config.default_rooms.iter().cloned() {
|
||||
// anything that does not start '!' should be considered an alias
|
||||
// empty strings are ignored
|
||||
let room_id = if alias_or_id.starts_with('!') {
|
||||
if alias_or_id.split_once(':').is_none() {
|
||||
alias_or_id = format!("{}:{}", alias_or_id, self.config.server_name);
|
||||
}
|
||||
for id_or_alias in &self.config.default_rooms {
|
||||
// OwnedRoomOrAliasId always starts with a '#' or '!', presence of a ':' is not validated
|
||||
let localpart = id_or_alias
|
||||
.as_str()
|
||||
.split_once(':')
|
||||
.map(|(localpart, _)| localpart)
|
||||
.unwrap_or(id_or_alias.as_str());
|
||||
let server_name = id_or_alias
|
||||
.server_name()
|
||||
.map(ToOwned::to_owned)
|
||||
.unwrap_or(self.config.server_name.clone());
|
||||
|
||||
OwnedRoomId::from_str(&alias_or_id).map_err(|e| {
|
||||
warn!(
|
||||
"Invalid room ID ({}) for join-by-default rooms: {}",
|
||||
alias_or_id, e
|
||||
);
|
||||
|
||||
Error::bad_config("Invalid room ID for join-by-default rooms.")
|
||||
})?
|
||||
} else {
|
||||
if alias_or_id.split_once(':').is_none() {
|
||||
alias_or_id = format!("#{}:{}", alias_or_id, self.config.server_name);
|
||||
}
|
||||
|
||||
let room_alias = OwnedRoomAliasId::from_str(&alias_or_id).map_err(|e| {
|
||||
warn!(
|
||||
"Invalid room alias ({}) for join-by-default rooms: {}",
|
||||
alias_or_id, e
|
||||
);
|
||||
|
||||
Error::bad_config("Invalid room alias for join-by-default rooms.")
|
||||
})?;
|
||||
|
||||
if room_alias.server_name() == self.config.server_name {
|
||||
services()
|
||||
.rooms
|
||||
.alias
|
||||
.resolve_local_alias(&room_alias)?
|
||||
.ok_or_else(|| {
|
||||
Error::bad_config("Unknown alias for join-by-default rooms.")
|
||||
})?
|
||||
} else {
|
||||
get_alias_helper(room_alias.clone())
|
||||
.await
|
||||
.map(|res| res.room_id)?
|
||||
}
|
||||
let room_id = match OwnedRoomOrAliasId::from_str(&format!("{localpart}:{server_name}"))
|
||||
.expect("this should always be valid")
|
||||
.try_into()
|
||||
{
|
||||
Ok(room_id) => room_id,
|
||||
Err(room_alias) => get_alias_helper(room_alias).await.map(|res| res.room_id)?,
|
||||
};
|
||||
|
||||
default_rooms.insert(room_id);
|
||||
}
|
||||
|
||||
self.default_rooms
|
||||
.set(default_rooms)
|
||||
.expect("default_rooms should not be set already");
|
||||
|
||||
Ok(self.default_rooms.get().unwrap())
|
||||
Ok(default_rooms)
|
||||
}
|
||||
|
||||
pub fn shutdown(&self) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue