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

View file

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

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 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)?,
let fallback = || {
format!("#{s}:{server_name}")
.parse()
.map_err(|_| Error::bad_config("Invalid opaque identifier."))
};
default_rooms.insert(room_id);
}
Ok(default_rooms)
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),
};
self.config
.default_rooms
.rooms
.iter()
.map(String::as_str)
.map(|s| f)
.collect::<Result<_>>()
}
pub fn shutdown(&self) {