allow taking room aliases for `auto_join_rooms` config option

Signed-off-by: strawberry <strawberry@puppygock.gay>
This commit is contained in:
strawberry 2024-11-02 20:55:40 -04:00
parent 9466aeb088
commit 6f37a251fb
No known key found for this signature in database
3 changed files with 31 additions and 13 deletions

View File

@ -108,24 +108,29 @@ pub(super) async fn create_user(&self, username: String, password: Option<String
if !self.services.globals.config.auto_join_rooms.is_empty() {
for room in &self.services.globals.config.auto_join_rooms {
let Ok(room_id) = self.services.rooms.alias.resolve(room).await else {
error!(%user_id, "Failed to resolve room alias to room ID when attempting to auto join {room}, skipping");
continue;
};
if !self
.services
.rooms
.state_cache
.server_in_room(self.services.globals.server_name(), room)
.server_in_room(self.services.globals.server_name(), &room_id)
.await
{
warn!("Skipping room {room} to automatically join as we have never joined before.");
continue;
}
if let Some(room_id_server_name) = room.server_name() {
if let Some(room_server_name) = room.server_name() {
match join_room_by_id_helper(
self.services,
&user_id,
room,
&room_id,
Some("Automatically joining this room upon registration".to_owned()),
&[room_id_server_name.to_owned(), self.services.globals.server_name().to_owned()],
&[self.services.globals.server_name().to_owned(), room_server_name.to_owned()],
None,
&None,
)
@ -135,6 +140,13 @@ pub(super) async fn create_user(&self, username: String, password: Option<String
info!("Automatically joined room {room} for user {user_id}");
},
Err(e) => {
self.services
.admin
.send_message(RoomMessageEventContent::text_plain(format!(
"Failed to automatically join room {room} for user {user_id}: {e}"
)))
.await
.ok();
// don't return this error so we don't fail registrations
error!("Failed to automatically join room {room} for user {user_id}: {e}");
},

View File

@ -398,23 +398,28 @@ pub(crate) async fn register_route(
&& (services.globals.allow_guests_auto_join_rooms() || !is_guest)
{
for room in &services.globals.config.auto_join_rooms {
let Ok(room_id) = services.rooms.alias.resolve(room).await else {
error!("Failed to resolve room alias to room ID when attempting to auto join {room}, skipping");
continue;
};
if !services
.rooms
.state_cache
.server_in_room(services.globals.server_name(), room)
.server_in_room(services.globals.server_name(), &room_id)
.await
{
warn!("Skipping room {room} to automatically join as we have never joined before.");
continue;
}
if let Some(room_id_server_name) = room.server_name() {
if let Some(room_server_name) = room.server_name() {
if let Err(e) = join_room_by_id_helper(
&services,
&user_id,
room,
&room_id,
Some("Automatically joining this room upon registration".to_owned()),
&[room_id_server_name.to_owned(), services.globals.server_name().to_owned()],
&[services.globals.server_name().to_owned(), room_server_name.to_owned()],
None,
&body.appservice_info,
)

View File

@ -18,7 +18,8 @@ pub use figment::{value::Value as FigmentValue, Figment};
use itertools::Itertools;
use regex::RegexSet;
use ruma::{
api::client::discovery::discover_support::ContactRole, OwnedRoomId, OwnedServerName, OwnedUserId, RoomVersionId,
api::client::discovery::discover_support::ContactRole, OwnedRoomOrAliasId, OwnedServerName, OwnedUserId,
RoomVersionId,
};
use serde::{de::IgnoredAny, Deserialize};
use url::Url;
@ -653,13 +654,13 @@ pub struct Config {
#[serde(default = "default_turn_ttl")]
pub turn_ttl: u64,
/// List/vector of room **IDs** that conduwuit will make newly registered
/// users join. The room IDs specified must be rooms that you have joined
/// at least once on the server, and must be public.
/// List/vector of room IDs or room aliases that conduwuit will make newly
/// registered users join. The rooms specified must be rooms that you
/// have joined at least once on the server, and must be public.
///
/// No default.
#[serde(default = "Vec::new")]
pub auto_join_rooms: Vec<OwnedRoomId>,
pub auto_join_rooms: Vec<OwnedRoomOrAliasId>,
/// Config option to automatically deactivate the account of any user who
/// attempts to join a: