Minor rewrites
This commit is contained in:
@@ -13,7 +13,8 @@ pub(super) async fn check_all_users(&self) -> Result {
|
|||||||
let users = self
|
let users = self
|
||||||
.services
|
.services
|
||||||
.users
|
.users
|
||||||
.iter()
|
.stream()
|
||||||
|
.map(ToOwned::to_owned)
|
||||||
.collect::<Vec<_>>()
|
.collect::<Vec<_>>()
|
||||||
.await;
|
.await;
|
||||||
let query_time = timer.elapsed();
|
let query_time = timer.elapsed();
|
||||||
|
|||||||
@@ -17,19 +17,15 @@ use ruma::{
|
|||||||
federation,
|
federation,
|
||||||
},
|
},
|
||||||
directory::{Filter, PublicRoomsChunk, RoomNetwork, RoomTypeFilter},
|
directory::{Filter, PublicRoomsChunk, RoomNetwork, RoomTypeFilter},
|
||||||
events::{
|
events::StateEventType,
|
||||||
StateEventType,
|
|
||||||
room::join_rules::{JoinRule, RoomJoinRulesEventContent},
|
|
||||||
},
|
|
||||||
uint,
|
uint,
|
||||||
};
|
};
|
||||||
use tuwunel_core::{
|
use tuwunel_core::{
|
||||||
Err, Result, err, info, is_true,
|
Err, Result, err, info,
|
||||||
matrix::Event,
|
matrix::Event,
|
||||||
utils::{
|
utils::{
|
||||||
TryFutureExtExt,
|
TryFutureExtExt,
|
||||||
math::Expected,
|
math::Expected,
|
||||||
result::FlatOk,
|
|
||||||
stream::{IterStream, ReadyExt, WidebandExt},
|
stream::{IterStream, ReadyExt, WidebandExt},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
@@ -429,17 +425,19 @@ async fn public_rooms_chunk(services: &Services, room_id: OwnedRoomId) -> Public
|
|||||||
|
|
||||||
let join_rule = services
|
let join_rule = services
|
||||||
.state_accessor
|
.state_accessor
|
||||||
.room_state_get_content(&room_id, &StateEventType::RoomJoinRules, "")
|
.get_join_rules(&room_id)
|
||||||
.map_ok(|c: RoomJoinRulesEventContent| match c.join_rule {
|
.map(|join_rule| join_rule.kind());
|
||||||
| JoinRule::Public => "public".into(),
|
|
||||||
| JoinRule::Knock => "knock".into(),
|
|
||||||
| JoinRule::KnockRestricted(_) => "knock_restricted".into(),
|
|
||||||
| _ => "invite".into(),
|
|
||||||
});
|
|
||||||
|
|
||||||
let guest_can_join = services.state_accessor.guest_can_join(&room_id);
|
let guest_can_join = services.state_accessor.guest_can_join(&room_id);
|
||||||
|
|
||||||
let num_joined_members = services.state_cache.room_joined_count(&room_id);
|
let num_joined_members = services
|
||||||
|
.state_cache
|
||||||
|
.room_joined_count(&room_id)
|
||||||
|
.map(|x| {
|
||||||
|
x.ok()
|
||||||
|
.and_then(|x| x.try_into().ok())
|
||||||
|
.unwrap_or_else(|| uint!(0))
|
||||||
|
});
|
||||||
|
|
||||||
let (
|
let (
|
||||||
(avatar_url, canonical_alias, guest_can_join, join_rule, name),
|
(avatar_url, canonical_alias, guest_can_join, join_rule, name),
|
||||||
@@ -455,13 +453,9 @@ async fn public_rooms_chunk(services: &Services, room_id: OwnedRoomId) -> Public
|
|||||||
avatar_url: avatar_url.flatten(),
|
avatar_url: avatar_url.flatten(),
|
||||||
canonical_alias,
|
canonical_alias,
|
||||||
guest_can_join,
|
guest_can_join,
|
||||||
join_rule: join_rule.unwrap_or_default(),
|
join_rule,
|
||||||
name,
|
name,
|
||||||
num_joined_members: num_joined_members
|
num_joined_members,
|
||||||
.map(TryInto::try_into)
|
|
||||||
.map(Result::ok)
|
|
||||||
.flat_ok()
|
|
||||||
.unwrap_or_else(|| uint!(0)),
|
|
||||||
room_id,
|
room_id,
|
||||||
room_type,
|
room_type,
|
||||||
topic,
|
topic,
|
||||||
@@ -474,18 +468,17 @@ fn check_server_banned(services: &Services, server: Option<&ServerName>) -> Resu
|
|||||||
return Ok(());
|
return Ok(());
|
||||||
};
|
};
|
||||||
|
|
||||||
let conditions = [
|
let host = server.host();
|
||||||
services
|
|
||||||
.config
|
if services
|
||||||
.forbidden_remote_room_directory_server_names
|
.config
|
||||||
.is_match(server.host()),
|
.forbidden_remote_room_directory_server_names
|
||||||
services
|
.is_match(host)
|
||||||
|
|| services
|
||||||
.config
|
.config
|
||||||
.forbidden_remote_server_names
|
.forbidden_remote_server_names
|
||||||
.is_match(server.host()),
|
.is_match(host)
|
||||||
];
|
{
|
||||||
|
|
||||||
if conditions.iter().any(is_true!()) {
|
|
||||||
return Err!(Request(Forbidden("Server is banned on this homeserver.")));
|
return Err!(Request(Forbidden("Server is banned on this homeserver.")));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -257,26 +257,23 @@ where
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
let ignored_type = IGNORED_MESSAGE_TYPES
|
if IGNORED_MESSAGE_TYPES
|
||||||
.binary_search(event.kind())
|
.binary_search(event.kind())
|
||||||
.is_ok();
|
.is_err()
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
let ignored_server = services
|
let ignored_server = services
|
||||||
.config
|
.config
|
||||||
.forbidden_remote_server_names
|
.forbidden_remote_server_names
|
||||||
.is_match(event.sender().server_name().host());
|
.is_match(event.sender().server_name().host());
|
||||||
|
|
||||||
if ignored_type
|
ignored_server
|
||||||
&& (ignored_server
|
|| services
|
||||||
|| services
|
.users
|
||||||
.users
|
.user_is_ignored(event.sender(), user_id)
|
||||||
.user_is_ignored(event.sender(), user_id)
|
.await
|
||||||
.await)
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
false
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ pub(crate) async fn search_users_route(
|
|||||||
) -> Result<search_users::v3::Response> {
|
) -> Result<search_users::v3::Response> {
|
||||||
let sender_user = body.sender_user();
|
let sender_user = body.sender_user();
|
||||||
let limit = usize::try_from(body.limit)
|
let limit = usize::try_from(body.limit)
|
||||||
.map_or(LIMIT_DEFAULT, usize::from)
|
.unwrap_or(LIMIT_DEFAULT)
|
||||||
.min(LIMIT_MAX);
|
.min(LIMIT_MAX);
|
||||||
|
|
||||||
let search_term = body.search_term.to_lowercase();
|
let search_term = body.search_term.to_lowercase();
|
||||||
|
|||||||
@@ -128,7 +128,11 @@ pub fn check(config: &Config) -> Result {
|
|||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
if config.emergency_password == Some(String::from("F670$2CP@Hw8mG7RY1$%!#Ic7YA")) {
|
if config
|
||||||
|
.emergency_password
|
||||||
|
.as_ref()
|
||||||
|
.is_some_and(|emergency_password| emergency_password == "F670$2CP@Hw8mG7RY1$%!#Ic7YA")
|
||||||
|
{
|
||||||
return Err!(Config(
|
return Err!(Config(
|
||||||
"emergency_password",
|
"emergency_password",
|
||||||
"The public example emergency password is being used, this is insecure. Please \
|
"The public example emergency password is being used, this is insecure. Please \
|
||||||
@@ -136,7 +140,11 @@ pub fn check(config: &Config) -> Result {
|
|||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
if config.emergency_password == Some(String::new()) {
|
if config
|
||||||
|
.emergency_password
|
||||||
|
.as_ref()
|
||||||
|
.is_some_and(String::is_empty)
|
||||||
|
{
|
||||||
return Err!(Config(
|
return Err!(Config(
|
||||||
"emergency_password",
|
"emergency_password",
|
||||||
"Emergency password was set to an empty string, this is not valid. Unset \
|
"Emergency password was set to an empty string, this is not valid. Unset \
|
||||||
@@ -145,7 +153,11 @@ pub fn check(config: &Config) -> Result {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// check if the user specified a registration token as `""`
|
// check if the user specified a registration token as `""`
|
||||||
if config.registration_token == Some(String::new()) {
|
if config
|
||||||
|
.registration_token
|
||||||
|
.as_ref()
|
||||||
|
.is_some_and(String::is_empty)
|
||||||
|
{
|
||||||
return Err!(Config(
|
return Err!(Config(
|
||||||
"registration_token",
|
"registration_token",
|
||||||
"Registration token was specified but is empty (\"\")"
|
"Registration token was specified but is empty (\"\")"
|
||||||
|
|||||||
@@ -183,16 +183,6 @@ impl Service {
|
|||||||
#[inline]
|
#[inline]
|
||||||
pub async fn count(&self) -> usize { self.db.userid_password.count().await }
|
pub async fn count(&self) -> usize { self.db.userid_password.count().await }
|
||||||
|
|
||||||
/// Returns an iterator over all users on this homeserver (offered for
|
|
||||||
/// compatibility)
|
|
||||||
#[allow(
|
|
||||||
clippy::iter_without_into_iter,
|
|
||||||
clippy::iter_not_returning_iterator
|
|
||||||
)]
|
|
||||||
pub fn iter(&self) -> impl Stream<Item = OwnedUserId> + Send + '_ {
|
|
||||||
self.stream().map(ToOwned::to_owned)
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Returns an iterator over all users on this homeserver.
|
/// Returns an iterator over all users on this homeserver.
|
||||||
pub fn stream(&self) -> impl Stream<Item = &UserId> + Send {
|
pub fn stream(&self) -> impl Stream<Item = &UserId> + Send {
|
||||||
self.db.userid_password.keys().ignore_err()
|
self.db.userid_password.keys().ignore_err()
|
||||||
|
|||||||
Reference in New Issue
Block a user