Minor rewrites
This commit is contained in:
@@ -13,7 +13,8 @@ pub(super) async fn check_all_users(&self) -> Result {
|
||||
let users = self
|
||||
.services
|
||||
.users
|
||||
.iter()
|
||||
.stream()
|
||||
.map(ToOwned::to_owned)
|
||||
.collect::<Vec<_>>()
|
||||
.await;
|
||||
let query_time = timer.elapsed();
|
||||
|
||||
@@ -17,19 +17,15 @@ use ruma::{
|
||||
federation,
|
||||
},
|
||||
directory::{Filter, PublicRoomsChunk, RoomNetwork, RoomTypeFilter},
|
||||
events::{
|
||||
StateEventType,
|
||||
room::join_rules::{JoinRule, RoomJoinRulesEventContent},
|
||||
},
|
||||
events::StateEventType,
|
||||
uint,
|
||||
};
|
||||
use tuwunel_core::{
|
||||
Err, Result, err, info, is_true,
|
||||
Err, Result, err, info,
|
||||
matrix::Event,
|
||||
utils::{
|
||||
TryFutureExtExt,
|
||||
math::Expected,
|
||||
result::FlatOk,
|
||||
stream::{IterStream, ReadyExt, WidebandExt},
|
||||
},
|
||||
};
|
||||
@@ -429,17 +425,19 @@ async fn public_rooms_chunk(services: &Services, room_id: OwnedRoomId) -> Public
|
||||
|
||||
let join_rule = services
|
||||
.state_accessor
|
||||
.room_state_get_content(&room_id, &StateEventType::RoomJoinRules, "")
|
||||
.map_ok(|c: RoomJoinRulesEventContent| match c.join_rule {
|
||||
| JoinRule::Public => "public".into(),
|
||||
| JoinRule::Knock => "knock".into(),
|
||||
| JoinRule::KnockRestricted(_) => "knock_restricted".into(),
|
||||
| _ => "invite".into(),
|
||||
});
|
||||
.get_join_rules(&room_id)
|
||||
.map(|join_rule| join_rule.kind());
|
||||
|
||||
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 (
|
||||
(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(),
|
||||
canonical_alias,
|
||||
guest_can_join,
|
||||
join_rule: join_rule.unwrap_or_default(),
|
||||
join_rule,
|
||||
name,
|
||||
num_joined_members: num_joined_members
|
||||
.map(TryInto::try_into)
|
||||
.map(Result::ok)
|
||||
.flat_ok()
|
||||
.unwrap_or_else(|| uint!(0)),
|
||||
num_joined_members,
|
||||
room_id,
|
||||
room_type,
|
||||
topic,
|
||||
@@ -474,18 +468,17 @@ fn check_server_banned(services: &Services, server: Option<&ServerName>) -> Resu
|
||||
return Ok(());
|
||||
};
|
||||
|
||||
let conditions = [
|
||||
services
|
||||
.config
|
||||
.forbidden_remote_room_directory_server_names
|
||||
.is_match(server.host()),
|
||||
services
|
||||
let host = server.host();
|
||||
|
||||
if services
|
||||
.config
|
||||
.forbidden_remote_room_directory_server_names
|
||||
.is_match(host)
|
||||
|| services
|
||||
.config
|
||||
.forbidden_remote_server_names
|
||||
.is_match(server.host()),
|
||||
];
|
||||
|
||||
if conditions.iter().any(is_true!()) {
|
||||
.is_match(host)
|
||||
{
|
||||
return Err!(Request(Forbidden("Server is banned on this homeserver.")));
|
||||
}
|
||||
|
||||
|
||||
@@ -257,26 +257,23 @@ where
|
||||
return true;
|
||||
}
|
||||
|
||||
let ignored_type = IGNORED_MESSAGE_TYPES
|
||||
if IGNORED_MESSAGE_TYPES
|
||||
.binary_search(event.kind())
|
||||
.is_ok();
|
||||
.is_err()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
let ignored_server = services
|
||||
.config
|
||||
.forbidden_remote_server_names
|
||||
.is_match(event.sender().server_name().host());
|
||||
|
||||
if ignored_type
|
||||
&& (ignored_server
|
||||
|| services
|
||||
.users
|
||||
.user_is_ignored(event.sender(), user_id)
|
||||
.await)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
false
|
||||
ignored_server
|
||||
|| services
|
||||
.users
|
||||
.user_is_ignored(event.sender(), user_id)
|
||||
.await
|
||||
}
|
||||
|
||||
#[inline]
|
||||
|
||||
@@ -32,7 +32,7 @@ pub(crate) async fn search_users_route(
|
||||
) -> Result<search_users::v3::Response> {
|
||||
let sender_user = body.sender_user();
|
||||
let limit = usize::try_from(body.limit)
|
||||
.map_or(LIMIT_DEFAULT, usize::from)
|
||||
.unwrap_or(LIMIT_DEFAULT)
|
||||
.min(LIMIT_MAX);
|
||||
|
||||
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(
|
||||
"emergency_password",
|
||||
"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(
|
||||
"emergency_password",
|
||||
"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 `""`
|
||||
if config.registration_token == Some(String::new()) {
|
||||
if config
|
||||
.registration_token
|
||||
.as_ref()
|
||||
.is_some_and(String::is_empty)
|
||||
{
|
||||
return Err!(Config(
|
||||
"registration_token",
|
||||
"Registration token was specified but is empty (\"\")"
|
||||
|
||||
@@ -183,16 +183,6 @@ impl Service {
|
||||
#[inline]
|
||||
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.
|
||||
pub fn stream(&self) -> impl Stream<Item = &UserId> + Send {
|
||||
self.db.userid_password.keys().ignore_err()
|
||||
|
||||
Reference in New Issue
Block a user