1
0
Fork 0
mirror of https://gitlab.com/famedly/conduit.git synced 2025-06-27 16:35:59 +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

@ -114,12 +114,11 @@ exclude = ["*.clearnet.onion"]
### Default rooms ### Default rooms
Since the validation of room aliases and IDs does validate the presence of a colon separator, This list should contain either room identifiers or aliases.
this symbol including the server name can be ommitted for local rooms. Opaque identifiers will be interpreted as incomplete, local aliases.
#### Example #### Example
In this example, the two configuration options are equivalent: In this example, the opaque identifier and alias are the same:
```toml ```toml
default_rooms = ["#home", "!abc123", "#conduit:fachschaften.org"] default_rooms = ["home", "#home:conduit.rs"]
default_rooms = ["#home:conduit.rs", "!abc123:conduit.rs", "#conduit:fachschaften.org"]
``` ```

View file

@ -2,15 +2,18 @@ use std::{
collections::BTreeMap, collections::BTreeMap,
fmt, fmt,
net::{IpAddr, Ipv4Addr}, net::{IpAddr, Ipv4Addr},
str::FromStr,
}; };
use ruma::{OwnedRoomOrAliasId, OwnedServerName, RoomVersionId}; use ruma::{serde::Raw, OwnedRoomId, OwnedRoomOrAliasId, OwnedServerName, RoomVersionId};
use serde::{de::IgnoredAny, Deserialize}; use serde::{de::IgnoredAny, Deserialize};
use tracing::warn; use tracing::warn;
use url::Url; use url::Url;
mod proxy; mod proxy;
use crate::Error;
use self::proxy::ProxyConfig; use self::proxy::ProxyConfig;
#[derive(Clone, Debug, Deserialize)] #[derive(Clone, Debug, Deserialize)]
@ -105,7 +108,8 @@ pub struct WellKnownConfig {
#[derive(Clone, Debug, Deserialize, Default)] #[derive(Clone, Debug, Deserialize, Default)]
pub struct DefaultRoomsConfig { pub struct DefaultRoomsConfig {
pub rooms: Vec<OwnedRoomOrAliasId>, #[serde(default = "Vec::new")]
pub rooms: Vec<String>,
pub join_reason: Option<String>, pub join_reason: Option<String>,
} }

View file

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