1
0
Fork 0
mirror of https://gitlab.com/famedly/conduit.git synced 2025-07-27 17:28:36 +00:00
This commit is contained in:
avdb13 2024-07-06 22:26:33 +02:00
parent 734e84c668
commit 5e28b9158f
3 changed files with 35 additions and 31 deletions

View file

@ -1,9 +1,10 @@
mod data;
pub use data::{Data, SigningKeys};
use hmac::digest::typenum::Pow;
use ruma::{
serde::Base64, MilliSecondsSinceUnixEpoch, OwnedDeviceId, OwnedEventId, OwnedRoomAliasId,
OwnedRoomId, OwnedRoomOrAliasId, OwnedServerName, OwnedUserId, RoomAliasId,
OwnedRoomId, OwnedRoomOrAliasId, OwnedServerName, OwnedUserId, RoomAliasId, RoomId,
};
use crate::api::{client_server::get_alias_helper, server_server::DestinationResponse};
@ -24,6 +25,7 @@ use std::{
future::{self, Future},
iter,
net::{IpAddr, SocketAddr},
ops::Deref,
path::PathBuf,
str::FromStr,
sync::{
@ -507,32 +509,31 @@ impl Service {
}
pub async fn default_rooms(&self) -> Result<BTreeSet<OwnedRoomId>> {
let mut default_rooms = BTreeSet::new();
let server_name = &self.config.server_name;
for id_or_alias in &self.config.default_rooms.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());
let fallback = || {
format!("#{s}:{server_name}")
.parse()
.map_err(|_| Error::bad_config("Invalid opaque identifier."))
};
let room_id = match id_or_alias.try_into()
// 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);
}
let f = |s| match OwnedRoomOrAliasId::from_str(s).map(OwnedRoomId::try_from) {
Ok(Ok(room_id)) => room_id
.server_name()
.ok_or_else(|| Error::bad_config("Invalid room ID due to missing server name."))
.map(|_| room_id),
result => get_alias_helper(result.map(Result::unwrap_err).or_else(fallback)?)
.await
.map(|response| response.room_id),
};
Ok(default_rooms)
self.config
.default_rooms
.rooms
.iter()
.map(String::as_str)
.map(|s| f)
.collect::<Result<_>>()
}
pub fn shutdown(&self) {