feat: automatically join rooms on registration
Signed-off-by: strawberry <strawberry@puppygock.gay>
This commit is contained in:
parent
2ca357e44c
commit
7066b7b428
5 changed files with 48 additions and 4 deletions
|
@ -263,6 +263,11 @@ url_preview_check_root_domain = false
|
||||||
# Defaults to true as this is the fastest option for federation.
|
# Defaults to true as this is the fastest option for federation.
|
||||||
#query_trusted_key_servers_first = true
|
#query_trusted_key_servers_first = true
|
||||||
|
|
||||||
|
# List/vector of room **IDs** that conduwuit will make newly registered users join.
|
||||||
|
#
|
||||||
|
# No default.
|
||||||
|
#auto_join_rooms = []
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
### Generic database options
|
### Generic database options
|
||||||
|
|
|
@ -12,10 +12,13 @@ use ruma::{
|
||||||
events::{room::message::RoomMessageEventContent, GlobalAccountDataEventType},
|
events::{room::message::RoomMessageEventContent, GlobalAccountDataEventType},
|
||||||
push, UserId,
|
push, UserId,
|
||||||
};
|
};
|
||||||
use tracing::{info, warn};
|
use tracing::{error, info, warn};
|
||||||
|
|
||||||
use super::{DEVICE_ID_LENGTH, SESSION_ID_LENGTH, TOKEN_LENGTH};
|
use super::{DEVICE_ID_LENGTH, SESSION_ID_LENGTH, TOKEN_LENGTH};
|
||||||
use crate::{api::client_server, services, utils, Error, Result, Ruma};
|
use crate::{
|
||||||
|
api::client_server::{self, join_room_by_id_helper},
|
||||||
|
services, utils, Error, Result, Ruma,
|
||||||
|
};
|
||||||
|
|
||||||
const RANDOM_USER_ID_LENGTH: usize = 10;
|
const RANDOM_USER_ID_LENGTH: usize = 10;
|
||||||
|
|
||||||
|
@ -285,6 +288,30 @@ pub async fn register_route(body: Ruma<register::v3::Request>) -> Result<registe
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if !services().globals.config.auto_join_rooms.is_empty() {
|
||||||
|
for room in &services().globals.config.auto_join_rooms {
|
||||||
|
if let Some(room_id_server_name) = room.server_name() {
|
||||||
|
match join_room_by_id_helper(
|
||||||
|
Some(&user_id),
|
||||||
|
room,
|
||||||
|
Some("Automatically joining this room".to_owned()),
|
||||||
|
&[room_id_server_name.to_owned()],
|
||||||
|
None,
|
||||||
|
)
|
||||||
|
.await
|
||||||
|
{
|
||||||
|
Ok(_) => {
|
||||||
|
info!("Automatically joined room {room} for user {user_id}");
|
||||||
|
},
|
||||||
|
Err(e) => {
|
||||||
|
// don't return this error so we don't fail registrations
|
||||||
|
error!("Failed to automatically join room {room} for user {user_id}: {e}");
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Ok(register::v3::Response {
|
Ok(register::v3::Response {
|
||||||
access_token: Some(token),
|
access_token: Some(token),
|
||||||
user_id,
|
user_id,
|
||||||
|
|
|
@ -474,7 +474,7 @@ pub async fn joined_members_route(body: Ruma<joined_members::v3::Request>) -> Re
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn join_room_by_id_helper(
|
pub(crate) async fn join_room_by_id_helper(
|
||||||
sender_user: Option<&UserId>, room_id: &RoomId, reason: Option<String>, servers: &[OwnedServerName],
|
sender_user: Option<&UserId>, room_id: &RoomId, reason: Option<String>, servers: &[OwnedServerName],
|
||||||
_third_party_signed: Option<&ThirdPartySigned>,
|
_third_party_signed: Option<&ThirdPartySigned>,
|
||||||
) -> Result<join_room_by_id::v3::Response> {
|
) -> Result<join_room_by_id::v3::Response> {
|
||||||
|
|
|
@ -10,7 +10,7 @@ use either::Either;
|
||||||
use figment::Figment;
|
use figment::Figment;
|
||||||
use itertools::Itertools;
|
use itertools::Itertools;
|
||||||
use regex::RegexSet;
|
use regex::RegexSet;
|
||||||
use ruma::{OwnedServerName, RoomVersionId};
|
use ruma::{OwnedRoomId, OwnedServerName, RoomVersionId};
|
||||||
use serde::{de::IgnoredAny, Deserialize};
|
use serde::{de::IgnoredAny, Deserialize};
|
||||||
use tracing::{debug, error, warn};
|
use tracing::{debug, error, warn};
|
||||||
|
|
||||||
|
@ -110,6 +110,9 @@ pub struct Config {
|
||||||
#[serde(default = "default_turn_ttl")]
|
#[serde(default = "default_turn_ttl")]
|
||||||
pub turn_ttl: u64,
|
pub turn_ttl: u64,
|
||||||
|
|
||||||
|
#[serde(default = "Vec::new")]
|
||||||
|
pub auto_join_rooms: Vec<OwnedRoomId>,
|
||||||
|
|
||||||
#[serde(default = "default_rocksdb_log_level")]
|
#[serde(default = "default_rocksdb_log_level")]
|
||||||
pub rocksdb_log_level: String,
|
pub rocksdb_log_level: String,
|
||||||
#[serde(default = "default_rocksdb_max_log_file_size")]
|
#[serde(default = "default_rocksdb_max_log_file_size")]
|
||||||
|
@ -364,6 +367,13 @@ impl fmt::Display for Config {
|
||||||
}
|
}
|
||||||
&lst.join(", ")
|
&lst.join(", ")
|
||||||
}),
|
}),
|
||||||
|
("Auto Join Rooms", {
|
||||||
|
let mut lst = vec![];
|
||||||
|
for room in &self.auto_join_rooms {
|
||||||
|
lst.push(room);
|
||||||
|
}
|
||||||
|
&lst.into_iter().join(", ")
|
||||||
|
}),
|
||||||
#[cfg(feature = "compression-zstd")]
|
#[cfg(feature = "compression-zstd")]
|
||||||
("zstd Response Body Compression", &self.zstd_compression.to_string()),
|
("zstd Response Body Compression", &self.zstd_compression.to_string()),
|
||||||
#[cfg(feature = "rocksdb")]
|
#[cfg(feature = "rocksdb")]
|
||||||
|
|
|
@ -327,6 +327,8 @@ impl Service<'_> {
|
||||||
|
|
||||||
pub fn turn_secret(&self) -> &String { &self.config.turn_secret }
|
pub fn turn_secret(&self) -> &String { &self.config.turn_secret }
|
||||||
|
|
||||||
|
pub fn auto_join_rooms(&self) -> &[OwnedRoomId] { &self.config.auto_join_rooms }
|
||||||
|
|
||||||
pub fn notification_push_path(&self) -> &String { &self.config.notification_push_path }
|
pub fn notification_push_path(&self) -> &String { &self.config.notification_push_path }
|
||||||
|
|
||||||
pub fn emergency_password(&self) -> &Option<String> { &self.config.emergency_password }
|
pub fn emergency_password(&self) -> &Option<String> { &self.config.emergency_password }
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue