@@ -49,8 +49,19 @@ pub(crate) async fn get_event_authorization_route(
|
||||
.auth_chain
|
||||
.event_ids_iter(room_id, once(body.event_id.borrow()))
|
||||
.ready_filter_map(Result::ok)
|
||||
.filter_map(|id| async move { services.rooms.timeline.get_pdu_json(&id).await.ok() })
|
||||
.then(|pdu| services.sending.convert_to_outgoing_federation_event(pdu))
|
||||
.filter_map(|id| async move {
|
||||
services
|
||||
.rooms
|
||||
.timeline
|
||||
.get_pdu_json(&id)
|
||||
.await
|
||||
.ok()
|
||||
})
|
||||
.then(|pdu| {
|
||||
services
|
||||
.sending
|
||||
.convert_to_outgoing_federation_event(pdu)
|
||||
})
|
||||
.collect()
|
||||
.await;
|
||||
|
||||
|
||||
@@ -38,7 +38,12 @@ pub(crate) async fn get_missing_events_route(
|
||||
|
||||
let mut i: usize = 0;
|
||||
while i < queued_events.len() && events.len() < limit {
|
||||
let Ok(pdu) = services.rooms.timeline.get_pdu(&queued_events[i]).await else {
|
||||
let Ok(pdu) = services
|
||||
.rooms
|
||||
.timeline
|
||||
.get_pdu(&queued_events[i])
|
||||
.await
|
||||
else {
|
||||
debug!(
|
||||
?body.origin,
|
||||
"Event {} does not exist locally, skipping", &queued_events[i]
|
||||
|
||||
@@ -17,7 +17,12 @@ pub(crate) async fn get_hierarchy_route(
|
||||
State(services): State<crate::State>,
|
||||
body: Ruma<get_hierarchy::v1::Request>,
|
||||
) -> Result<get_hierarchy::v1::Response> {
|
||||
if !services.rooms.metadata.exists(&body.room_id).await {
|
||||
if !services
|
||||
.rooms
|
||||
.metadata
|
||||
.exists(&body.room_id)
|
||||
.await
|
||||
{
|
||||
return Err!(Request(NotFound("Room does not exist.")));
|
||||
}
|
||||
|
||||
@@ -60,8 +65,15 @@ pub(crate) async fn get_hierarchy_route(
|
||||
.unzip()
|
||||
.map(|(children, inaccessible_children): (Vec<_>, Vec<_>)| {
|
||||
(
|
||||
children.into_iter().flatten().map(Into::into).collect(),
|
||||
inaccessible_children.into_iter().flatten().collect(),
|
||||
children
|
||||
.into_iter()
|
||||
.flatten()
|
||||
.map(Into::into)
|
||||
.collect(),
|
||||
inaccessible_children
|
||||
.into_iter()
|
||||
.flatten()
|
||||
.collect(),
|
||||
)
|
||||
})
|
||||
.await;
|
||||
|
||||
@@ -29,7 +29,10 @@ pub(crate) async fn create_invite_route(
|
||||
.acl_check(body.origin(), &body.room_id)
|
||||
.await?;
|
||||
|
||||
if !services.server.supported_room_version(&body.room_version) {
|
||||
if !services
|
||||
.server
|
||||
.supported_room_version(&body.room_version)
|
||||
{
|
||||
return Err(Error::BadRequest(
|
||||
ErrorKind::IncompatibleRoomVersion { room_version: body.room_version.clone() },
|
||||
"Server does not support this room version.",
|
||||
@@ -69,7 +72,10 @@ pub(crate) async fn create_invite_route(
|
||||
.map(UserId::to_owned)
|
||||
.map_err(|e| err!(Request(InvalidParam("Invalid state_key property: {e}"))))?;
|
||||
|
||||
if !services.globals.server_is_ours(invited_user.server_name()) {
|
||||
if !services
|
||||
.globals
|
||||
.server_is_ours(invited_user.server_name())
|
||||
{
|
||||
return Err!(Request(InvalidParam("User does not belong to this homeserver.")));
|
||||
}
|
||||
|
||||
@@ -96,8 +102,11 @@ pub(crate) async fn create_invite_route(
|
||||
.try_into()
|
||||
.map_err(|e| err!(Request(InvalidParam("Invalid sender property: {e}"))))?;
|
||||
|
||||
if services.rooms.metadata.is_banned(&body.room_id).await
|
||||
&& !services.users.is_admin(&invited_user).await
|
||||
if services
|
||||
.rooms
|
||||
.metadata
|
||||
.is_banned(&body.room_id)
|
||||
.await && !services.users.is_admin(&invited_user).await
|
||||
{
|
||||
return Err!(Request(Forbidden("This room is banned on this homeserver.")));
|
||||
}
|
||||
|
||||
@@ -27,7 +27,10 @@ pub(crate) async fn get_server_keys_route(
|
||||
) -> Result<impl IntoResponse> {
|
||||
let server_name = services.globals.server_name();
|
||||
let active_key_id = services.server_keys.active_key_id();
|
||||
let mut all_keys = services.server_keys.verify_keys_for(server_name).await;
|
||||
let mut all_keys = services
|
||||
.server_keys
|
||||
.verify_keys_for(server_name)
|
||||
.await;
|
||||
|
||||
let verify_keys = all_keys
|
||||
.remove_entry(active_key_id)
|
||||
|
||||
@@ -26,7 +26,12 @@ pub(crate) async fn create_join_event_template_route(
|
||||
State(services): State<crate::State>,
|
||||
body: Ruma<prepare_join_event::v1::Request>,
|
||||
) -> Result<prepare_join_event::v1::Response> {
|
||||
if !services.rooms.metadata.exists(&body.room_id).await {
|
||||
if !services
|
||||
.rooms
|
||||
.metadata
|
||||
.exists(&body.room_id)
|
||||
.await
|
||||
{
|
||||
return Err!(Request(NotFound("Room is unknown to this server.")));
|
||||
}
|
||||
|
||||
@@ -68,7 +73,11 @@ pub(crate) async fn create_join_event_template_route(
|
||||
}
|
||||
}
|
||||
|
||||
let room_version_id = services.rooms.state.get_room_version(&body.room_id).await?;
|
||||
let room_version_id = services
|
||||
.rooms
|
||||
.state
|
||||
.get_room_version(&body.room_id)
|
||||
.await?;
|
||||
if !body.ver.contains(&room_version_id) {
|
||||
return Err(Error::BadRequest(
|
||||
ErrorKind::IncompatibleRoomVersion { room_version: room_version_id },
|
||||
@@ -76,7 +85,12 @@ pub(crate) async fn create_join_event_template_route(
|
||||
));
|
||||
}
|
||||
|
||||
let state_lock = services.rooms.state.mutex.lock(&body.room_id).await;
|
||||
let state_lock = services
|
||||
.rooms
|
||||
.state
|
||||
.mutex
|
||||
.lock(&body.room_id)
|
||||
.await;
|
||||
|
||||
let join_authorized_via_users_server: Option<OwnedUserId> = {
|
||||
use RoomVersionId::*;
|
||||
@@ -157,7 +171,12 @@ pub(crate) async fn user_can_perform_restricted_join(
|
||||
return Ok(false);
|
||||
}
|
||||
|
||||
if services.rooms.state_cache.is_joined(user_id, room_id).await {
|
||||
if services
|
||||
.rooms
|
||||
.state_cache
|
||||
.is_joined(user_id, room_id)
|
||||
.await
|
||||
{
|
||||
// joining user is already joined, there is nothing we need to do
|
||||
return Ok(false);
|
||||
}
|
||||
@@ -196,7 +215,12 @@ pub(crate) async fn user_can_perform_restricted_join(
|
||||
}
|
||||
})
|
||||
.stream()
|
||||
.any(|m| services.rooms.state_cache.is_joined(user_id, &m.room_id))
|
||||
.any(|m| {
|
||||
services
|
||||
.rooms
|
||||
.state_cache
|
||||
.is_joined(user_id, &m.room_id)
|
||||
})
|
||||
.await
|
||||
{
|
||||
Ok(true)
|
||||
|
||||
@@ -17,7 +17,12 @@ pub(crate) async fn create_knock_event_template_route(
|
||||
State(services): State<crate::State>,
|
||||
body: Ruma<create_knock_event_template::v1::Request>,
|
||||
) -> Result<create_knock_event_template::v1::Response> {
|
||||
if !services.rooms.metadata.exists(&body.room_id).await {
|
||||
if !services
|
||||
.rooms
|
||||
.metadata
|
||||
.exists(&body.room_id)
|
||||
.await
|
||||
{
|
||||
return Err!(Request(NotFound("Room is unknown to this server.")));
|
||||
}
|
||||
|
||||
@@ -57,7 +62,11 @@ pub(crate) async fn create_knock_event_template_route(
|
||||
}
|
||||
}
|
||||
|
||||
let room_version_id = services.rooms.state.get_room_version(&body.room_id).await?;
|
||||
let room_version_id = services
|
||||
.rooms
|
||||
.state
|
||||
.get_room_version(&body.room_id)
|
||||
.await?;
|
||||
|
||||
if matches!(room_version_id, V1 | V2 | V3 | V4 | V5 | V6) {
|
||||
return Err(Error::BadRequest(
|
||||
@@ -73,7 +82,12 @@ pub(crate) async fn create_knock_event_template_route(
|
||||
));
|
||||
}
|
||||
|
||||
let state_lock = services.rooms.state.mutex.lock(&body.room_id).await;
|
||||
let state_lock = services
|
||||
.rooms
|
||||
.state
|
||||
.mutex
|
||||
.lock(&body.room_id)
|
||||
.await;
|
||||
|
||||
if let Ok(membership) = services
|
||||
.rooms
|
||||
|
||||
@@ -16,7 +16,12 @@ pub(crate) async fn create_leave_event_template_route(
|
||||
State(services): State<crate::State>,
|
||||
body: Ruma<prepare_leave_event::v1::Request>,
|
||||
) -> Result<prepare_leave_event::v1::Response> {
|
||||
if !services.rooms.metadata.exists(&body.room_id).await {
|
||||
if !services
|
||||
.rooms
|
||||
.metadata
|
||||
.exists(&body.room_id)
|
||||
.await
|
||||
{
|
||||
return Err!(Request(NotFound("Room is unknown to this server.")));
|
||||
}
|
||||
|
||||
@@ -33,8 +38,17 @@ pub(crate) async fn create_leave_event_template_route(
|
||||
.acl_check(body.origin(), &body.room_id)
|
||||
.await?;
|
||||
|
||||
let room_version_id = services.rooms.state.get_room_version(&body.room_id).await?;
|
||||
let state_lock = services.rooms.state.mutex.lock(&body.room_id).await;
|
||||
let room_version_id = services
|
||||
.rooms
|
||||
.state
|
||||
.get_room_version(&body.room_id)
|
||||
.await?;
|
||||
let state_lock = services
|
||||
.rooms
|
||||
.state
|
||||
.mutex
|
||||
.lock(&body.room_id)
|
||||
.await;
|
||||
|
||||
let (_pdu, mut pdu_json) = services
|
||||
.rooms
|
||||
|
||||
@@ -73,7 +73,10 @@ pub(crate) async fn get_profile_information_route(
|
||||
));
|
||||
}
|
||||
|
||||
if !services.globals.server_is_ours(body.user_id.server_name()) {
|
||||
if !services
|
||||
.globals
|
||||
.server_is_ours(body.user_id.server_name())
|
||||
{
|
||||
return Err(Error::BadRequest(
|
||||
ErrorKind::InvalidParam,
|
||||
"User does not belong to this server.",
|
||||
@@ -88,10 +91,18 @@ pub(crate) async fn get_profile_information_route(
|
||||
|
||||
match &body.field {
|
||||
| Some(ProfileField::DisplayName) => {
|
||||
displayname = services.users.displayname(&body.user_id).await.ok();
|
||||
displayname = services
|
||||
.users
|
||||
.displayname(&body.user_id)
|
||||
.await
|
||||
.ok();
|
||||
},
|
||||
| Some(ProfileField::AvatarUrl) => {
|
||||
avatar_url = services.users.avatar_url(&body.user_id).await.ok();
|
||||
avatar_url = services
|
||||
.users
|
||||
.avatar_url(&body.user_id)
|
||||
.await
|
||||
.ok();
|
||||
blurhash = services.users.blurhash(&body.user_id).await.ok();
|
||||
},
|
||||
| Some(custom_field) => {
|
||||
@@ -104,8 +115,16 @@ pub(crate) async fn get_profile_information_route(
|
||||
}
|
||||
},
|
||||
| None => {
|
||||
displayname = services.users.displayname(&body.user_id).await.ok();
|
||||
avatar_url = services.users.avatar_url(&body.user_id).await.ok();
|
||||
displayname = services
|
||||
.users
|
||||
.displayname(&body.user_id)
|
||||
.await
|
||||
.ok();
|
||||
avatar_url = services
|
||||
.users
|
||||
.avatar_url(&body.user_id)
|
||||
.await
|
||||
.ok();
|
||||
blurhash = services.users.blurhash(&body.user_id).await.ok();
|
||||
tz = services.users.timezone(&body.user_id).await.ok();
|
||||
custom_profile_fields = services
|
||||
|
||||
@@ -92,7 +92,12 @@ pub(crate) async fn send_transaction_message_route(
|
||||
.pdus
|
||||
.iter()
|
||||
.stream()
|
||||
.broad_then(|pdu| services.rooms.event_handler.parse_incoming_pdu(pdu))
|
||||
.broad_then(|pdu| {
|
||||
services
|
||||
.rooms
|
||||
.event_handler
|
||||
.parse_incoming_pdu(pdu)
|
||||
})
|
||||
.inspect_err(|e| debug_warn!("Could not parse PDU: {e}"))
|
||||
.ready_filter_map(Result::ok);
|
||||
|
||||
@@ -215,7 +220,11 @@ async fn handle_edu(services: &Services, client: &IpAddr, origin: &ServerName, e
|
||||
| Edu::Presence(presence) if services.server.config.allow_incoming_presence =>
|
||||
handle_edu_presence(services, client, origin, presence).await,
|
||||
|
||||
| Edu::Receipt(receipt) if services.server.config.allow_incoming_read_receipts =>
|
||||
| Edu::Receipt(receipt)
|
||||
if services
|
||||
.server
|
||||
.config
|
||||
.allow_incoming_read_receipts =>
|
||||
handle_edu_receipt(services, client, origin, receipt).await,
|
||||
|
||||
| Edu::Typing(typing) if services.server.config.allow_incoming_typing =>
|
||||
@@ -454,7 +463,10 @@ async fn handle_edu_device_list_update(
|
||||
return;
|
||||
}
|
||||
|
||||
services.users.mark_device_key_update(&user_id).await;
|
||||
services
|
||||
.users
|
||||
.mark_device_key_update(&user_id)
|
||||
.await;
|
||||
}
|
||||
|
||||
async fn handle_edu_direct_to_device(
|
||||
|
||||
@@ -53,7 +53,11 @@ async fn create_join_event(
|
||||
|
||||
// We do not add the event_id field to the pdu here because of signature and
|
||||
// hashes checks
|
||||
let room_version_id = services.rooms.state.get_room_version(room_id).await?;
|
||||
let room_version_id = services
|
||||
.rooms
|
||||
.state
|
||||
.get_room_version(room_id)
|
||||
.await?;
|
||||
|
||||
let Ok((event_id, mut value)) = gen_event_id_canonical_json(pdu, &room_version_id) else {
|
||||
// Event could not be converted to canonical json
|
||||
@@ -239,7 +243,11 @@ async fn create_join_event(
|
||||
.auth_chain
|
||||
.event_ids_iter(room_id, starting_events)
|
||||
.broad_and_then(|event_id| async move {
|
||||
services.rooms.timeline.get_pdu_json(&event_id).await
|
||||
services
|
||||
.rooms
|
||||
.timeline
|
||||
.get_pdu_json(&event_id)
|
||||
.await
|
||||
})
|
||||
.broad_and_then(|pdu| {
|
||||
services
|
||||
@@ -251,7 +259,10 @@ async fn create_join_event(
|
||||
.boxed()
|
||||
.await?;
|
||||
|
||||
services.sending.send_pdu_room(room_id, &pdu_id).await?;
|
||||
services
|
||||
.sending
|
||||
.send_pdu_room(room_id, &pdu_id)
|
||||
.await?;
|
||||
|
||||
Ok(create_join_event::v1::RoomState {
|
||||
auth_chain,
|
||||
|
||||
@@ -55,7 +55,12 @@ pub(crate) async fn create_knock_event_v1_route(
|
||||
}
|
||||
}
|
||||
|
||||
if !services.rooms.metadata.exists(&body.room_id).await {
|
||||
if !services
|
||||
.rooms
|
||||
.metadata
|
||||
.exists(&body.room_id)
|
||||
.await
|
||||
{
|
||||
return Err!(Request(NotFound("Room is unknown to this server.")));
|
||||
}
|
||||
|
||||
@@ -66,7 +71,11 @@ pub(crate) async fn create_knock_event_v1_route(
|
||||
.acl_check(body.origin(), &body.room_id)
|
||||
.await?;
|
||||
|
||||
let room_version_id = services.rooms.state.get_room_version(&body.room_id).await?;
|
||||
let room_version_id = services
|
||||
.rooms
|
||||
.state
|
||||
.get_room_version(&body.room_id)
|
||||
.await?;
|
||||
|
||||
if matches!(room_version_id, V1 | V2 | V3 | V4 | V5 | V6) {
|
||||
return Err!(Request(Forbidden("Room version does not support knocking.")));
|
||||
|
||||
@@ -59,7 +59,11 @@ async fn create_leave_event(
|
||||
|
||||
// We do not add the event_id field to the pdu here because of signature and
|
||||
// hashes checks
|
||||
let room_version_id = services.rooms.state.get_room_version(room_id).await?;
|
||||
let room_version_id = services
|
||||
.rooms
|
||||
.state
|
||||
.get_room_version(room_id)
|
||||
.await?;
|
||||
let Ok((event_id, value)) = gen_event_id_canonical_json(pdu, &room_version_id) else {
|
||||
// Event could not be converted to canonical json
|
||||
return Err!(Request(BadJson("Could not convert event to canonical json.")));
|
||||
|
||||
@@ -43,11 +43,10 @@ pub(super) async fn check(&self) -> Result {
|
||||
let server_can_see: OptionFuture<_> = self
|
||||
.event_id
|
||||
.map(|event_id| {
|
||||
self.services.rooms.state_accessor.server_can_see_event(
|
||||
self.origin,
|
||||
self.room_id,
|
||||
event_id,
|
||||
)
|
||||
self.services
|
||||
.rooms
|
||||
.state_accessor
|
||||
.server_can_see_event(self.origin, self.room_id, event_id)
|
||||
})
|
||||
.into();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user