allow taking room aliases for auto_join_rooms
config option
Signed-off-by: strawberry <strawberry@puppygock.gay>
This commit is contained in:
parent
9466aeb088
commit
6f37a251fb
3 changed files with 31 additions and 13 deletions
|
@ -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() {
|
if !self.services.globals.config.auto_join_rooms.is_empty() {
|
||||||
for room in &self.services.globals.config.auto_join_rooms {
|
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
|
if !self
|
||||||
.services
|
.services
|
||||||
.rooms
|
.rooms
|
||||||
.state_cache
|
.state_cache
|
||||||
.server_in_room(self.services.globals.server_name(), room)
|
.server_in_room(self.services.globals.server_name(), &room_id)
|
||||||
.await
|
.await
|
||||||
{
|
{
|
||||||
warn!("Skipping room {room} to automatically join as we have never joined before.");
|
warn!("Skipping room {room} to automatically join as we have never joined before.");
|
||||||
continue;
|
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(
|
match join_room_by_id_helper(
|
||||||
self.services,
|
self.services,
|
||||||
&user_id,
|
&user_id,
|
||||||
room,
|
&room_id,
|
||||||
Some("Automatically joining this room upon registration".to_owned()),
|
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,
|
||||||
&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}");
|
info!("Automatically joined room {room} for user {user_id}");
|
||||||
},
|
},
|
||||||
Err(e) => {
|
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
|
// don't return this error so we don't fail registrations
|
||||||
error!("Failed to automatically join room {room} for user {user_id}: {e}");
|
error!("Failed to automatically join room {room} for user {user_id}: {e}");
|
||||||
},
|
},
|
||||||
|
|
|
@ -398,23 +398,28 @@ pub(crate) async fn register_route(
|
||||||
&& (services.globals.allow_guests_auto_join_rooms() || !is_guest)
|
&& (services.globals.allow_guests_auto_join_rooms() || !is_guest)
|
||||||
{
|
{
|
||||||
for room in &services.globals.config.auto_join_rooms {
|
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
|
if !services
|
||||||
.rooms
|
.rooms
|
||||||
.state_cache
|
.state_cache
|
||||||
.server_in_room(services.globals.server_name(), room)
|
.server_in_room(services.globals.server_name(), &room_id)
|
||||||
.await
|
.await
|
||||||
{
|
{
|
||||||
warn!("Skipping room {room} to automatically join as we have never joined before.");
|
warn!("Skipping room {room} to automatically join as we have never joined before.");
|
||||||
continue;
|
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(
|
if let Err(e) = join_room_by_id_helper(
|
||||||
&services,
|
&services,
|
||||||
&user_id,
|
&user_id,
|
||||||
room,
|
&room_id,
|
||||||
Some("Automatically joining this room upon registration".to_owned()),
|
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,
|
None,
|
||||||
&body.appservice_info,
|
&body.appservice_info,
|
||||||
)
|
)
|
||||||
|
|
|
@ -18,7 +18,8 @@ pub use figment::{value::Value as FigmentValue, Figment};
|
||||||
use itertools::Itertools;
|
use itertools::Itertools;
|
||||||
use regex::RegexSet;
|
use regex::RegexSet;
|
||||||
use ruma::{
|
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 serde::{de::IgnoredAny, Deserialize};
|
||||||
use url::Url;
|
use url::Url;
|
||||||
|
@ -653,13 +654,13 @@ pub struct Config {
|
||||||
#[serde(default = "default_turn_ttl")]
|
#[serde(default = "default_turn_ttl")]
|
||||||
pub turn_ttl: u64,
|
pub turn_ttl: u64,
|
||||||
|
|
||||||
/// List/vector of room **IDs** that conduwuit will make newly registered
|
/// List/vector of room IDs or room aliases that conduwuit will make newly
|
||||||
/// users join. The room IDs specified must be rooms that you have joined
|
/// registered users join. The rooms specified must be rooms that you
|
||||||
/// at least once on the server, and must be public.
|
/// have joined at least once on the server, and must be public.
|
||||||
///
|
///
|
||||||
/// No default.
|
/// No default.
|
||||||
#[serde(default = "Vec::new")]
|
#[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
|
/// Config option to automatically deactivate the account of any user who
|
||||||
/// attempts to join a:
|
/// attempts to join a:
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue