mirror of
https://forgejo.ellis.link/continuwuation/continuwuity.git
synced 2026-05-26 20:49:55 +00:00
chore: Clippy fixes
This commit is contained in:
@@ -121,7 +121,7 @@ pub(super) async fn get_pdu(&self, event_id: OwnedEventId) -> Result {
|
|||||||
} else {
|
} else {
|
||||||
"PDU found in our database"
|
"PDU found in our database"
|
||||||
};
|
};
|
||||||
write!(self, "{msg}\n```json\n{text}\n```",)
|
write!(self, "{msg}\n```json\n{text}\n```")
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
.await
|
.await
|
||||||
@@ -189,10 +189,7 @@ pub(super) async fn get_remote_pdu_list(&self, server: OwnedServerName, force: b
|
|||||||
|
|
||||||
for event_id in list {
|
for event_id in list {
|
||||||
if force {
|
if force {
|
||||||
match self
|
match self.get_remote_pdu(event_id.clone(), server.clone()).await {
|
||||||
.get_remote_pdu(event_id.to_owned(), server.clone())
|
|
||||||
.await
|
|
||||||
{
|
|
||||||
| Err(e) => {
|
| Err(e) => {
|
||||||
failed_count = failed_count.saturating_add(1);
|
failed_count = failed_count.saturating_add(1);
|
||||||
self.services
|
self.services
|
||||||
@@ -207,7 +204,7 @@ pub(super) async fn get_remote_pdu_list(&self, server: OwnedServerName, force: b
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
self.get_remote_pdu(event_id.to_owned(), server.clone())
|
self.get_remote_pdu(event_id.clone(), server.clone())
|
||||||
.await?;
|
.await?;
|
||||||
success_count = success_count.saturating_add(1);
|
success_count = success_count.saturating_add(1);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -129,6 +129,6 @@ pub(super) async fn remote_user_in_rooms(&self, user_id: OwnedUserId) -> Result
|
|||||||
.collect::<Vec<_>>()
|
.collect::<Vec<_>>()
|
||||||
.join("\n");
|
.join("\n");
|
||||||
|
|
||||||
self.write_str(&format!("Rooms {user_id} shares with us ({num}):\n```\n{body}\n```",))
|
self.write_str(&format!("Rooms {user_id} shares with us ({num}):\n```\n{body}\n```"))
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -262,7 +262,7 @@ pub(super) async fn delete_past_remote_media(
|
|||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
self.write_str(&format!("Deleted {deleted_count} total files.",))
|
self.write_str(&format!("Deleted {deleted_count} total files."))
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -272,7 +272,7 @@ pub(super) async fn delete_all_from_user(&self, username: String) -> Result {
|
|||||||
|
|
||||||
let deleted_count = self.services.media.delete_from_user(&user_id).await?;
|
let deleted_count = self.services.media.delete_from_user(&user_id).await?;
|
||||||
|
|
||||||
self.write_str(&format!("Deleted {deleted_count} total files.",))
|
self.write_str(&format!("Deleted {deleted_count} total files."))
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -331,7 +331,7 @@ pub(super) async fn delete_all_from_server(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
self.write_str(&format!("Deleted {deleted_count} total files.",))
|
self.write_str(&format!("Deleted {deleted_count} total files."))
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -53,7 +53,7 @@ pub(super) async fn process(subcommand: RoomAliasCommand, context: &Context<'_>)
|
|||||||
.rooms
|
.rooms
|
||||||
.alias
|
.alias
|
||||||
.all_local_aliases()
|
.all_local_aliases()
|
||||||
.map(|(room_id, alias)| (room_id.to_owned(), alias.to_owned()))
|
.map(|(room_id, alias)| (room_id, alias.to_owned()))
|
||||||
.collect::<Vec<_>>()
|
.collect::<Vec<_>>()
|
||||||
.await;
|
.await;
|
||||||
let query_time = timer.elapsed();
|
let query_time = timer.elapsed();
|
||||||
|
|||||||
@@ -139,7 +139,7 @@ pub(super) async fn process(command: RoomAliasCommand, context: &Context<'_>) ->
|
|||||||
.rooms
|
.rooms
|
||||||
.alias
|
.alias
|
||||||
.all_local_aliases()
|
.all_local_aliases()
|
||||||
.map(|(room_id, localpart)| (room_id.into(), localpart.into()))
|
.map(|(room_id, localpart)| (room_id, localpart.into()))
|
||||||
.collect::<Vec<(OwnedRoomId, String)>>()
|
.collect::<Vec<(OwnedRoomId, String)>>()
|
||||||
.await;
|
.await;
|
||||||
|
|
||||||
|
|||||||
@@ -72,7 +72,7 @@ pub(super) async fn list_rooms(
|
|||||||
.collect::<Vec<_>>()
|
.collect::<Vec<_>>()
|
||||||
.join("\n");
|
.join("\n");
|
||||||
|
|
||||||
self.write_str(&format!("Rooms ({}):\n```\n{body}\n```", rooms.len(),))
|
self.write_str(&format!("Rooms ({}):\n```\n{body}\n```", rooms.len()))
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -67,7 +67,7 @@ pub(super) async fn process(command: RoomDirectoryCommand, context: &Context<'_>
|
|||||||
.join("\n");
|
.join("\n");
|
||||||
|
|
||||||
context
|
context
|
||||||
.write_str(&format!("Rooms (page {page}):\n```\n{body}\n```",))
|
.write_str(&format!("Rooms (page {page}):\n```\n{body}\n```"))
|
||||||
.await
|
.await
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -66,7 +66,7 @@ async fn list_joined_members(&self, room_id: OwnedRoomId, local_only: bool) -> R
|
|||||||
.collect::<Vec<_>>()
|
.collect::<Vec<_>>()
|
||||||
.join("\n");
|
.join("\n");
|
||||||
|
|
||||||
self.write_str(&format!("{num} Members in Room \"{room_name}\":\n```\n{body}\n```",))
|
self.write_str(&format!("{num} Members in Room \"{room_name}\":\n```\n{body}\n```"))
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -71,7 +71,7 @@ async fn ban_room(&self, room: OwnedRoomOrAliasId) -> Result {
|
|||||||
|
|
||||||
debug!("Room specified is a room ID, banning room ID");
|
debug!("Room specified is a room ID, banning room ID");
|
||||||
|
|
||||||
room_id.to_owned()
|
room_id.clone()
|
||||||
} else if room.is_room_alias_id() {
|
} else if room.is_room_alias_id() {
|
||||||
let room_alias = match RoomAliasId::parse(&room) {
|
let room_alias = match RoomAliasId::parse(&room) {
|
||||||
| Ok(room_alias) => room_alias,
|
| Ok(room_alias) => room_alias,
|
||||||
@@ -203,7 +203,7 @@ async fn ban_list_of_rooms(&self) -> Result {
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
room_ids.push(room_id.to_owned());
|
room_ids.push(room_id.clone());
|
||||||
}
|
}
|
||||||
|
|
||||||
if room_alias_or_id.is_room_alias_id() {
|
if room_alias_or_id.is_room_alias_id() {
|
||||||
@@ -346,7 +346,7 @@ async fn unban_room(&self, room: OwnedRoomOrAliasId) -> Result {
|
|||||||
debug!("Room specified is a room ID, unbanning room ID");
|
debug!("Room specified is a room ID, unbanning room ID");
|
||||||
self.services.rooms.metadata.ban_room(&room_id, false);
|
self.services.rooms.metadata.ban_room(&room_id, false);
|
||||||
|
|
||||||
room_id.to_owned()
|
room_id.clone()
|
||||||
} else if room.is_room_alias_id() {
|
} else if room.is_room_alias_id() {
|
||||||
let room_alias = match RoomAliasId::parse(&room) {
|
let room_alias = match RoomAliasId::parse(&room) {
|
||||||
| Ok(room_alias) => room_alias,
|
| Ok(room_alias) => room_alias,
|
||||||
@@ -449,6 +449,6 @@ async fn list_banned_rooms(&self, no_details: bool) -> Result {
|
|||||||
.collect::<Vec<_>>()
|
.collect::<Vec<_>>()
|
||||||
.join("\n");
|
.join("\n");
|
||||||
|
|
||||||
self.write_str(&format!("Rooms Banned ({num}):\n```\n{body}\n```",))
|
self.write_str(&format!("Rooms Banned ({num}):\n```\n{body}\n```"))
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -159,8 +159,8 @@ pub(super) async fn list_features(&self) -> Result {
|
|||||||
let mut enabled_features = conduwuit::info::introspection::ENABLED_FEATURES
|
let mut enabled_features = conduwuit::info::introspection::ENABLED_FEATURES
|
||||||
.lock()
|
.lock()
|
||||||
.expect("locked")
|
.expect("locked")
|
||||||
.iter()
|
.values()
|
||||||
.flat_map(|(_, f)| f.iter())
|
.flat_map(|f| f.iter())
|
||||||
.collect::<Vec<_>>();
|
.collect::<Vec<_>>();
|
||||||
|
|
||||||
enabled_features.sort_unstable();
|
enabled_features.sort_unstable();
|
||||||
|
|||||||
@@ -295,7 +295,7 @@ pub(super) async fn reset_password(
|
|||||||
self.services
|
self.services
|
||||||
.users
|
.users
|
||||||
.remove_device(&user_id, &device_id)
|
.remove_device(&user_id, &device_id)
|
||||||
.await
|
.await;
|
||||||
})
|
})
|
||||||
.await;
|
.await;
|
||||||
write!(self, "\nAll existing sessions have been logged out.").await?;
|
write!(self, "\nAll existing sessions have been logged out.").await?;
|
||||||
@@ -458,7 +458,7 @@ pub(super) async fn list_joined_rooms(&self, user_id: String) -> Result {
|
|||||||
.collect::<Vec<_>>()
|
.collect::<Vec<_>>()
|
||||||
.join("\n");
|
.join("\n");
|
||||||
|
|
||||||
self.write_str(&format!("Rooms {user_id} Joined ({}):\n```\n{body}\n```", rooms.len(),))
|
self.write_str(&format!("Rooms {user_id} Joined ({}):\n```\n{body}\n```", rooms.len()))
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -510,7 +510,7 @@ pub(super) async fn force_join_list_of_local_users(
|
|||||||
.rooms
|
.rooms
|
||||||
.state_cache
|
.state_cache
|
||||||
.room_members(&room_id)
|
.room_members(&room_id)
|
||||||
.ready_any(|user_id| server_admins.contains(&user_id.to_owned()))
|
.ready_any(|user_id| server_admins.contains(&user_id))
|
||||||
.await
|
.await
|
||||||
{
|
{
|
||||||
return Err!("There is not a single server admin in the room.",);
|
return Err!("There is not a single server admin in the room.",);
|
||||||
@@ -624,7 +624,7 @@ pub(super) async fn force_join_all_local_users(
|
|||||||
.rooms
|
.rooms
|
||||||
.state_cache
|
.state_cache
|
||||||
.room_members(&room_id)
|
.room_members(&room_id)
|
||||||
.ready_any(|user_id| server_admins.contains(&user_id.to_owned()))
|
.ready_any(|user_id| server_admins.contains(&user_id))
|
||||||
.await
|
.await
|
||||||
{
|
{
|
||||||
return Err!("There is not a single server admin in the room.",);
|
return Err!("There is not a single server admin in the room.",);
|
||||||
@@ -687,7 +687,7 @@ pub(super) async fn force_join_room(
|
|||||||
);
|
);
|
||||||
join_room_by_id_helper(self.services, &user_id, &room_id, None, &servers, &None).await?;
|
join_room_by_id_helper(self.services, &user_id, &room_id, None, &servers, &None).await?;
|
||||||
|
|
||||||
self.write_str(&format!("{user_id} has been joined to {room_id}.",))
|
self.write_str(&format!("{user_id} has been joined to {room_id}."))
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -719,7 +719,7 @@ pub(super) async fn force_leave_room(
|
|||||||
.boxed()
|
.boxed()
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
self.write_str(&format!("{user_id} has left {room_id}.",))
|
self.write_str(&format!("{user_id} has left {room_id}."))
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -788,7 +788,7 @@ pub(super) async fn make_user_admin(&self, user_id: String) -> Result {
|
|||||||
.boxed()
|
.boxed()
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
self.write_str(&format!("{user_id} has been granted admin privileges.",))
|
self.write_str(&format!("{user_id} has been granted admin privileges."))
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1044,7 +1044,7 @@ pub(super) async fn logout(&self, user_id: String) -> Result {
|
|||||||
self.services
|
self.services
|
||||||
.users
|
.users
|
||||||
.remove_device(&user_id, &device_id)
|
.remove_device(&user_id, &device_id)
|
||||||
.await
|
.await;
|
||||||
})
|
})
|
||||||
.await;
|
.await;
|
||||||
self.write_str(&format!("User {user_id} has been logged out from all devices."))
|
self.write_str(&format!("User {user_id} has been logged out from all devices."))
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ use ruma::{
|
|||||||
RoomId, UserId,
|
RoomId, UserId,
|
||||||
api::{
|
api::{
|
||||||
client::membership::invite_user::{self, v3::InviteUserId},
|
client::membership::invite_user::{self, v3::InviteUserId},
|
||||||
federation::membership::{RawStrippedState, create_invite},
|
federation::membership::create_invite,
|
||||||
},
|
},
|
||||||
events::room::member::{MembershipState, RoomMemberEventContent},
|
events::room::member::{MembershipState, RoomMemberEventContent},
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ pub(super) struct Auth {
|
|||||||
pub(super) appservice_info: Option<RegistrationInfo>,
|
pub(super) appservice_info: Option<RegistrationInfo>,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) trait CheckAuth: AuthScheme {
|
pub(super) trait CheckAuth: AuthScheme {
|
||||||
fn authenticate<R: IncomingRequest + Any, B: AsRef<[u8]> + Sync>(
|
fn authenticate<R: IncomingRequest + Any, B: AsRef<[u8]> + Sync>(
|
||||||
services: &Services,
|
services: &Services,
|
||||||
incoming_request: &hyper::Request<B>,
|
incoming_request: &hyper::Request<B>,
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ use std::fmt::Debug;
|
|||||||
|
|
||||||
use ruma::{
|
use ruma::{
|
||||||
CanonicalJsonObject, EventId, MilliSecondsSinceUnixEpoch, OwnedEventId, OwnedRoomId, RoomId,
|
CanonicalJsonObject, EventId, MilliSecondsSinceUnixEpoch, OwnedEventId, OwnedRoomId, RoomId,
|
||||||
RoomVersionId, UserId, events::TimelineEventType, room_version_rules::RoomVersionRules,
|
UserId, events::TimelineEventType, room_version_rules::RoomVersionRules,
|
||||||
};
|
};
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
use serde_json::{Value as JsonValue, value::RawValue as RawJsonValue};
|
use serde_json::{Value as JsonValue, value::RawValue as RawJsonValue};
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
use ruma::{CanonicalJsonObject, OwnedEventId, room_version_rules::RoomVersionRules};
|
use ruma::{CanonicalJsonObject, OwnedEventId, room_version_rules::RoomVersionRules};
|
||||||
use serde_json::value::RawValue as RawJsonValue;
|
use serde_json::value::RawValue as RawJsonValue;
|
||||||
|
|
||||||
use crate::{Err, Result, err};
|
use crate::{Result, err};
|
||||||
|
|
||||||
/// Generates a correct eventId for the incoming pdu.
|
/// Generates a correct eventId for the incoming pdu.
|
||||||
///
|
///
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
use ruma::{
|
use ruma::{
|
||||||
OwnedEventId, RoomVersionId,
|
OwnedEventId,
|
||||||
events::{TimelineEventType, room::redaction::RoomRedactionEventContent},
|
events::{TimelineEventType, room::redaction::RoomRedactionEventContent},
|
||||||
room_version_rules::RoomVersionRules,
|
room_version_rules::RoomVersionRules,
|
||||||
};
|
};
|
||||||
@@ -64,8 +64,6 @@ pub(super) fn redacts_id<E: Event>(
|
|||||||
event: &E,
|
event: &E,
|
||||||
room_version_rules: &RoomVersionRules,
|
room_version_rules: &RoomVersionRules,
|
||||||
) -> Option<OwnedEventId> {
|
) -> Option<OwnedEventId> {
|
||||||
use RoomVersionId::*;
|
|
||||||
|
|
||||||
if *event.kind() != TimelineEventType::RoomRedaction {
|
if *event.kind() != TimelineEventType::RoomRedaction {
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -127,9 +127,7 @@ impl Event for Pdu {
|
|||||||
} else {
|
} else {
|
||||||
// v12+
|
// v12+
|
||||||
let constructed_hash = self.event_id.as_str().replace('$', "!");
|
let constructed_hash = self.event_id.as_str().replace('$', "!");
|
||||||
RoomId::parse(&constructed_hash)
|
RoomId::parse(&constructed_hash).expect("event ID can be parsed")
|
||||||
.expect("event ID can be parsed")
|
|
||||||
.to_owned()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -200,9 +198,7 @@ impl Event for &Pdu {
|
|||||||
} else {
|
} else {
|
||||||
// v12+
|
// v12+
|
||||||
let constructed_hash = self.event_id.as_str().replace('$', "!");
|
let constructed_hash = self.event_id.as_str().replace('$', "!");
|
||||||
RoomId::parse(&constructed_hash)
|
RoomId::parse(&constructed_hash).expect("event ID can be parsed")
|
||||||
.expect("event ID can be parsed")
|
|
||||||
.to_owned()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
use ruma::{RoomVersionId, canonical_json::redact_content_in_place};
|
use ruma::{RoomVersionId, canonical_json::redact_content_in_place};
|
||||||
use serde_json::{Value as JsonValue, json, value::to_raw_value};
|
use serde_json::{Value as JsonValue, json, value::to_raw_value};
|
||||||
|
|
||||||
use crate::{Err, Error, Result, err, implement};
|
use crate::{Err, Result, err, implement};
|
||||||
|
|
||||||
#[implement(super::Pdu)]
|
#[implement(super::Pdu)]
|
||||||
pub fn redact(&mut self, room_version_id: &RoomVersionId, reason: JsonValue) -> Result {
|
pub fn redact(&mut self, room_version_id: &RoomVersionId, reason: JsonValue) -> Result {
|
||||||
|
|||||||
@@ -85,6 +85,7 @@ pub fn auth_types_for_event(
|
|||||||
|
|
||||||
if kind == &TimelineEventType::RoomMember {
|
if kind == &TimelineEventType::RoomMember {
|
||||||
#[derive(Deserialize)]
|
#[derive(Deserialize)]
|
||||||
|
#[allow(unused)]
|
||||||
struct RoomMemberContentFields {
|
struct RoomMemberContentFields {
|
||||||
membership: Option<Raw<MembershipState>>,
|
membership: Option<Raw<MembershipState>>,
|
||||||
third_party_invite: Option<Raw<ThirdPartyInvite>>,
|
third_party_invite: Option<Raw<ThirdPartyInvite>>,
|
||||||
@@ -1003,8 +1004,8 @@ where
|
|||||||
} else {
|
} else {
|
||||||
let allow = sender_creator
|
let allow = sender_creator
|
||||||
|| sender_power
|
|| sender_power
|
||||||
.filter(|&p| p >= &power_levels.invite)
|
.as_ref()
|
||||||
.is_some();
|
.is_some_and(|&p| p >= &power_levels.invite);
|
||||||
if !allow {
|
if !allow {
|
||||||
warn!(
|
warn!(
|
||||||
%sender,
|
%sender,
|
||||||
@@ -1029,7 +1030,10 @@ where
|
|||||||
},
|
},
|
||||||
| MembershipState::Leave => {
|
| MembershipState::Leave => {
|
||||||
let can_unban = if target_user_current_membership == MembershipState::Ban {
|
let can_unban = if target_user_current_membership == MembershipState::Ban {
|
||||||
sender_creator || sender_power.filter(|&p| p >= &power_levels.ban).is_some()
|
sender_creator
|
||||||
|
|| sender_power
|
||||||
|
.as_ref()
|
||||||
|
.is_some_and(|&p| p >= &power_levels.ban)
|
||||||
} else {
|
} else {
|
||||||
true
|
true
|
||||||
};
|
};
|
||||||
@@ -1040,7 +1044,10 @@ where
|
|||||||
if sender_creator {
|
if sender_creator {
|
||||||
// sender is a creator
|
// sender is a creator
|
||||||
true
|
true
|
||||||
} else if sender_power.filter(|&p| p >= &power_levels.kick).is_none() {
|
} else if sender_power
|
||||||
|
.as_ref()
|
||||||
|
.is_none_or(|&p| p < &power_levels.kick)
|
||||||
|
{
|
||||||
// sender lacks kick power level
|
// sender lacks kick power level
|
||||||
false
|
false
|
||||||
} else if let Some(sp) = sender_power {
|
} else if let Some(sp) = sender_power {
|
||||||
@@ -1128,7 +1135,9 @@ where
|
|||||||
false
|
false
|
||||||
} else {
|
} else {
|
||||||
let allow = sender_creator
|
let allow = sender_creator
|
||||||
|| (sender_power.filter(|&p| p >= &power_levels.ban).is_some()
|
|| (sender_power
|
||||||
|
.as_ref()
|
||||||
|
.is_some_and(|&p| p >= &power_levels.ban)
|
||||||
&& target_power < sender_power);
|
&& target_power < sender_power);
|
||||||
if !allow {
|
if !allow {
|
||||||
warn!(
|
warn!(
|
||||||
|
|||||||
@@ -163,7 +163,7 @@ where
|
|||||||
|
|
||||||
// Sequentially auth check each control event.
|
// Sequentially auth check each control event.
|
||||||
let resolved_control = iterative_auth_check(
|
let resolved_control = iterative_auth_check(
|
||||||
&room_version,
|
room_version,
|
||||||
sorted_control_levels.iter().stream().map(AsRef::as_ref),
|
sorted_control_levels.iter().stream().map(AsRef::as_ref),
|
||||||
initial_state,
|
initial_state,
|
||||||
&event_fetch,
|
&event_fetch,
|
||||||
@@ -203,7 +203,7 @@ where
|
|||||||
trace!(list = ?sorted_left_events, "events left, sorted, running iterative auth check");
|
trace!(list = ?sorted_left_events, "events left, sorted, running iterative auth check");
|
||||||
|
|
||||||
let mut resolved_state = iterative_auth_check(
|
let mut resolved_state = iterative_auth_check(
|
||||||
&room_version,
|
room_version,
|
||||||
sorted_left_events.iter().stream().map(AsRef::as_ref),
|
sorted_left_events.iter().stream().map(AsRef::as_ref),
|
||||||
resolved_control, // The control events are added to the final resolved state
|
resolved_control, // The control events are added to the final resolved state
|
||||||
&event_fetch,
|
&event_fetch,
|
||||||
@@ -668,7 +668,7 @@ where
|
|||||||
"Failed to parse create event ID from room ID/hash: {e}"
|
"Failed to parse create event ID from room ID/hash: {e}"
|
||||||
))
|
))
|
||||||
})?;
|
})?;
|
||||||
let create_event = fetch_event(create_event_id.into())
|
let create_event = fetch_event(create_event_id)
|
||||||
.await
|
.await
|
||||||
.ok_or_else(|| Error::NotFound("Failed to find create event".into()))?;
|
.ok_or_else(|| Error::NotFound("Failed to find create event".into()))?;
|
||||||
auth_state.insert(create_event.event_type().with_state_key(""), create_event);
|
auth_state.insert(create_event.event_type().with_state_key(""), create_event);
|
||||||
|
|||||||
@@ -10,7 +10,12 @@ use ruma::{
|
|||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
use serde_json::{Error, from_str as from_json_str};
|
use serde_json::{Error, from_str as from_json_str};
|
||||||
|
|
||||||
use super::{Result, serde_backports::*};
|
use super::{
|
||||||
|
Result,
|
||||||
|
serde_backports::{
|
||||||
|
vec_deserialize_int_powerlevel_values, vec_deserialize_v1_powerlevel_values,
|
||||||
|
},
|
||||||
|
};
|
||||||
use crate::error;
|
use crate::error;
|
||||||
|
|
||||||
#[derive(Deserialize)]
|
#[derive(Deserialize)]
|
||||||
@@ -47,11 +52,11 @@ struct IntRoomPowerLevelsEventContent {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl IntRoomPowerLevelsEventContent {
|
impl IntRoomPowerLevelsEventContent {
|
||||||
fn to_room_power_levels_content(
|
fn into_room_power_levels_content(
|
||||||
self,
|
self,
|
||||||
auth_rules: &AuthorizationRules,
|
auth_rules: &AuthorizationRules,
|
||||||
) -> RoomPowerLevelsEventContent {
|
) -> RoomPowerLevelsEventContent {
|
||||||
let IntRoomPowerLevelsEventContent {
|
let Self {
|
||||||
ban,
|
ban,
|
||||||
events,
|
events,
|
||||||
events_default,
|
events_default,
|
||||||
@@ -116,7 +121,7 @@ fn deserialize_integer_power_levels(
|
|||||||
auth_rules: &AuthorizationRules,
|
auth_rules: &AuthorizationRules,
|
||||||
) -> Option<RoomPowerLevelsEventContent> {
|
) -> Option<RoomPowerLevelsEventContent> {
|
||||||
match from_json_str::<IntRoomPowerLevelsEventContent>(content) {
|
match from_json_str::<IntRoomPowerLevelsEventContent>(content) {
|
||||||
| Ok(content) => Some(content.to_room_power_levels_content(auth_rules)),
|
| Ok(content) => Some(content.into_room_power_levels_content(auth_rules)),
|
||||||
| Err(_) => {
|
| Err(_) => {
|
||||||
error!("m.room.power_levels event is not valid with integer values");
|
error!("m.room.power_levels event is not valid with integer values");
|
||||||
None
|
None
|
||||||
|
|||||||
@@ -16,7 +16,9 @@ use serde::{
|
|||||||
///
|
///
|
||||||
/// To be used like this:
|
/// To be used like this:
|
||||||
/// `#[serde(deserialize_with = "vec_deserialize_v1_powerlevel_values")]`
|
/// `#[serde(deserialize_with = "vec_deserialize_v1_powerlevel_values")]`
|
||||||
pub fn vec_deserialize_v1_powerlevel_values<'de, D, T>(de: D) -> Result<Vec<(T, Int)>, D::Error>
|
pub(super) fn vec_deserialize_v1_powerlevel_values<'de, D, T>(
|
||||||
|
de: D,
|
||||||
|
) -> Result<Vec<(T, Int)>, D::Error>
|
||||||
where
|
where
|
||||||
D: Deserializer<'de>,
|
D: Deserializer<'de>,
|
||||||
T: Deserialize<'de> + Ord,
|
T: Deserialize<'de> + Ord,
|
||||||
@@ -76,7 +78,9 @@ where
|
|||||||
///
|
///
|
||||||
/// To be used like this:
|
/// To be used like this:
|
||||||
/// `#[serde(deserialize_with = "vec_deserialize_int_powerlevel_values")]`
|
/// `#[serde(deserialize_with = "vec_deserialize_int_powerlevel_values")]`
|
||||||
pub fn vec_deserialize_int_powerlevel_values<'de, D, T>(de: D) -> Result<Vec<(T, Int)>, D::Error>
|
pub(super) fn vec_deserialize_int_powerlevel_values<'de, D, T>(
|
||||||
|
de: D,
|
||||||
|
) -> Result<Vec<(T, Int)>, D::Error>
|
||||||
where
|
where
|
||||||
D: Deserializer<'de>,
|
D: Deserializer<'de>,
|
||||||
T: Deserialize<'de> + Ord,
|
T: Deserialize<'de> + Ord,
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
use std::collections::BTreeMap;
|
use std::collections::BTreeMap;
|
||||||
|
|
||||||
|
#[must_use]
|
||||||
pub fn versions() -> Vec<String> {
|
pub fn versions() -> Vec<String> {
|
||||||
vec![
|
vec![
|
||||||
"r0.0.1".to_owned(),
|
"r0.0.1".to_owned(),
|
||||||
@@ -23,6 +24,7 @@ pub fn versions() -> Vec<String> {
|
|||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[must_use]
|
||||||
pub fn unstable_features() -> BTreeMap<String, bool> {
|
pub fn unstable_features() -> BTreeMap<String, bool> {
|
||||||
BTreeMap::from_iter([
|
BTreeMap::from_iter([
|
||||||
("org.matrix.e2e_cross_signing".to_owned(), true),
|
("org.matrix.e2e_cross_signing".to_owned(), true),
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
#![allow(clippy::needless_borrows_for_generic_args)]
|
#![allow(clippy::needless_borrows_for_generic_args)]
|
||||||
|
|
||||||
use std::{borrow::Cow, fmt::Debug};
|
use std::borrow::Cow;
|
||||||
|
|
||||||
use conduwuit::{
|
use conduwuit::{
|
||||||
arrayvec::ArrayVec,
|
arrayvec::ArrayVec,
|
||||||
@@ -12,7 +12,7 @@ use conduwuit::{
|
|||||||
use serde::Serialize;
|
use serde::Serialize;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
Ignore, Interfix, de, ser,
|
Ignore, de, ser,
|
||||||
ser::{Json, serialize_to_vec},
|
ser::{Json, serialize_to_vec},
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -470,6 +470,7 @@ fn serde_tuple_option_none_none() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
#[allow(clippy::type_complexity)]
|
||||||
fn serde_tuple_option_some_none_some() {
|
fn serde_tuple_option_some_none_some() {
|
||||||
let room_id = room_id!("!room:example.com");
|
let room_id = room_id!("!room:example.com");
|
||||||
let user_id = user_id!("@user:example.com");
|
let user_id = user_id!("@user:example.com");
|
||||||
|
|||||||
+1
-1
@@ -22,7 +22,7 @@ const WORKER_NAME: &str = "conduwuit:worker";
|
|||||||
const WORKER_MIN: usize = 2;
|
const WORKER_MIN: usize = 2;
|
||||||
const WORKER_KEEPALIVE: u64 = 36;
|
const WORKER_KEEPALIVE: u64 = 36;
|
||||||
const MAX_BLOCKING_THREADS: usize = 1024;
|
const MAX_BLOCKING_THREADS: usize = 1024;
|
||||||
const SHUTDOWN_TIMEOUT: Duration = Duration::from_millis(10000);
|
const SHUTDOWN_TIMEOUT: Duration = Duration::from_secs(10);
|
||||||
#[cfg(all(not(target_env = "msvc"), feature = "jemalloc"))]
|
#[cfg(all(not(target_env = "msvc"), feature = "jemalloc"))]
|
||||||
const DISABLE_MUZZY_THRESHOLD: usize = 4;
|
const DISABLE_MUZZY_THRESHOLD: usize = 4;
|
||||||
|
|
||||||
|
|||||||
@@ -163,7 +163,7 @@ fn cors_layer(_server: &Server) -> CorsLayer {
|
|||||||
.allow_origin(cors::Any)
|
.allow_origin(cors::Any)
|
||||||
.allow_methods(METHODS)
|
.allow_methods(METHODS)
|
||||||
.allow_headers(headers)
|
.allow_headers(headers)
|
||||||
.max_age(Duration::from_secs(86400))
|
.max_age(Duration::from_hours(24))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn body_limit_layer(server: &Server) -> DefaultBodyLimit {
|
fn body_limit_layer(server: &Server) -> DefaultBodyLimit {
|
||||||
|
|||||||
@@ -395,7 +395,7 @@ impl Service {
|
|||||||
let mut stream = admin_users;
|
let mut stream = admin_users;
|
||||||
|
|
||||||
while let Some(user_id) = stream.next().await {
|
while let Some(user_id) = stream.next().await {
|
||||||
generated_admin_list.push(user_id.to_owned());
|
generated_admin_list.push(user_id.clone());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -72,7 +72,7 @@ impl Service {
|
|||||||
None,
|
None,
|
||||||
server_user,
|
server_user,
|
||||||
GlobalAccountDataEventType::PushRules.to_string().into(),
|
GlobalAccountDataEventType::PushRules.to_string().into(),
|
||||||
&serde_json::to_value(&GlobalAccountDataEvent::new(PushRulesEventContent::new(
|
&serde_json::to_value(GlobalAccountDataEvent::new(PushRulesEventContent::new(
|
||||||
ruleset,
|
ruleset,
|
||||||
)))
|
)))
|
||||||
.expect("to json value always works"),
|
.expect("to json value always works"),
|
||||||
|
|||||||
@@ -289,7 +289,7 @@ fn handle_error(
|
|||||||
/// requests for either versioned or unversioned endpoints, by requiring that
|
/// requests for either versioned or unversioned endpoints, by requiring that
|
||||||
/// the `Input` of the `PathBuilder` of the endpoint implements
|
/// the `Input` of the `PathBuilder` of the endpoint implements
|
||||||
/// `FederationPathBuilderInput`.
|
/// `FederationPathBuilderInput`.
|
||||||
pub(crate) trait FederationPathBuilderInput {
|
pub trait FederationPathBuilderInput {
|
||||||
fn create() -> Self;
|
fn create() -> Self;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -210,7 +210,7 @@ pub async fn get_all(
|
|||||||
.ignore_err()
|
.ignore_err()
|
||||||
.ready_for_each(|((_, _, room_id, session_id), key_backup_data): KeyVal<'_>| {
|
.ready_for_each(|((_, _, room_id, session_id), key_backup_data): KeyVal<'_>| {
|
||||||
rooms
|
rooms
|
||||||
.entry(room_id.into())
|
.entry(room_id)
|
||||||
.or_insert_with(default)
|
.or_insert_with(default)
|
||||||
.sessions
|
.sessions
|
||||||
.insert(session_id.into(), key_backup_data);
|
.insert(session_id.into(), key_backup_data);
|
||||||
|
|||||||
@@ -215,7 +215,7 @@ async fn handle_thumbnail_file(
|
|||||||
.await
|
.await
|
||||||
.map(|()| FileMeta {
|
.map(|()| FileMeta {
|
||||||
content: Some(content.file),
|
content: Some(content.file),
|
||||||
content_type: content.content_type.map(Into::into),
|
content_type: content.content_type,
|
||||||
content_disposition: Some(content_disposition),
|
content_disposition: Some(content_disposition),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@@ -243,7 +243,7 @@ async fn handle_content_file(
|
|||||||
.await
|
.await
|
||||||
.map(|()| FileMeta {
|
.map(|()| FileMeta {
|
||||||
content: Some(content.file),
|
content: Some(content.file),
|
||||||
content_type: content.content_type.map(Into::into),
|
content_type: content.content_type,
|
||||||
content_disposition: Some(content_disposition),
|
content_disposition: Some(content_disposition),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@@ -364,7 +364,7 @@ pub async fn fetch_remote_thumbnail_legacy(
|
|||||||
body.width,
|
body.width,
|
||||||
body.height,
|
body.height,
|
||||||
);
|
);
|
||||||
request.method = body.method.clone();
|
request.method.clone_from(&body.method);
|
||||||
request.allow_remote = body.allow_remote;
|
request.allow_remote = body.allow_remote;
|
||||||
request.allow_redirect = body.allow_redirect;
|
request.allow_redirect = body.allow_redirect;
|
||||||
request.animated = body.animated;
|
request.animated = body.animated;
|
||||||
|
|||||||
@@ -610,19 +610,9 @@ async fn fix_readreceiptid_readreceipt_duplicates(services: &Services) -> Result
|
|||||||
.expect_ok()
|
.expect_ok()
|
||||||
.ready_for_each(|key: Key| {
|
.ready_for_each(|key: Key| {
|
||||||
let (ref room_id, _, ref user_id) = key;
|
let (ref room_id, _, ref user_id) = key;
|
||||||
let last_room = cur_room.replace(
|
let last_room = cur_room.replace(room_id.as_str().into());
|
||||||
room_id
|
|
||||||
.as_str()
|
|
||||||
.try_into()
|
|
||||||
.expect("invalid room_id in database"),
|
|
||||||
);
|
|
||||||
|
|
||||||
let last_user = cur_user.replace(
|
let last_user = cur_user.replace(user_id.as_str().into());
|
||||||
user_id
|
|
||||||
.as_str()
|
|
||||||
.try_into()
|
|
||||||
.expect("invalid user_id in database"),
|
|
||||||
);
|
|
||||||
|
|
||||||
let is_dup = cur_room == last_room && cur_user == last_user;
|
let is_dup = cur_room == last_room && cur_user == last_user;
|
||||||
if is_dup {
|
if is_dup {
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ pub struct ResetTokenInfo {
|
|||||||
|
|
||||||
impl ResetTokenInfo {
|
impl ResetTokenInfo {
|
||||||
// one hour
|
// one hour
|
||||||
const MAX_TOKEN_AGE: Duration = Duration::from_secs(60 * 60);
|
const MAX_TOKEN_AGE: Duration = Duration::from_hours(1);
|
||||||
|
|
||||||
pub fn is_valid(&self) -> bool {
|
pub fn is_valid(&self) -> bool {
|
||||||
let now = SystemTime::now();
|
let now = SystemTime::now();
|
||||||
|
|||||||
@@ -48,7 +48,7 @@ impl Presence {
|
|||||||
let now = utils::millis_since_unix_epoch();
|
let now = utils::millis_since_unix_epoch();
|
||||||
let last_active_ago = Some(UInt::new_saturating(now.saturating_sub(self.last_active_ts)));
|
let last_active_ago = Some(UInt::new_saturating(now.saturating_sub(self.last_active_ts)));
|
||||||
let mut content = PresenceEventContent::new(self.state.clone());
|
let mut content = PresenceEventContent::new(self.state.clone());
|
||||||
content.status_msg = self.status_msg.clone();
|
content.status_msg.clone_from(&self.status_msg);
|
||||||
content.currently_active = Some(self.currently_active);
|
content.currently_active = Some(self.currently_active);
|
||||||
content.last_active_ago = last_active_ago;
|
content.last_active_ago = last_active_ago;
|
||||||
content.displayname = users.displayname(user_id).await.ok();
|
content.displayname = users.displayname(user_id).await.ok();
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ use ipaddress::IPAddress;
|
|||||||
use ruma::{
|
use ruma::{
|
||||||
DeviceId, OwnedDeviceId, RoomId, UInt, UserId,
|
DeviceId, OwnedDeviceId, RoomId, UInt, UserId,
|
||||||
api::{
|
api::{
|
||||||
IncomingResponse, MatrixVersion, OutgoingRequest,
|
IncomingResponse, OutgoingRequest,
|
||||||
auth_scheme::NoAuthentication,
|
auth_scheme::NoAuthentication,
|
||||||
client::push::{Pusher, PusherKind, set_pusher},
|
client::push::{Pusher, PusherKind, set_pusher},
|
||||||
path_builder::SinglePath,
|
path_builder::SinglePath,
|
||||||
@@ -42,7 +42,6 @@ struct Services {
|
|||||||
globals: Dep<globals::Service>,
|
globals: Dep<globals::Service>,
|
||||||
config: Dep<config::Service>,
|
config: Dep<config::Service>,
|
||||||
client: Dep<client::Service>,
|
client: Dep<client::Service>,
|
||||||
state: Dep<rooms::state::Service>,
|
|
||||||
state_accessor: Dep<rooms::state_accessor::Service>,
|
state_accessor: Dep<rooms::state_accessor::Service>,
|
||||||
state_cache: Dep<rooms::state_cache::Service>,
|
state_cache: Dep<rooms::state_cache::Service>,
|
||||||
users: Dep<users::Service>,
|
users: Dep<users::Service>,
|
||||||
@@ -65,7 +64,6 @@ impl crate::Service for Service {
|
|||||||
globals: args.depend::<globals::Service>("globals"),
|
globals: args.depend::<globals::Service>("globals"),
|
||||||
client: args.depend::<client::Service>("client"),
|
client: args.depend::<client::Service>("client"),
|
||||||
config: args.depend::<config::Service>("config"),
|
config: args.depend::<config::Service>("config"),
|
||||||
state: args.depend::<rooms::state::Service>("rooms::state"),
|
|
||||||
state_accessor: args
|
state_accessor: args
|
||||||
.depend::<rooms::state_accessor::Service>("rooms::state_accessor"),
|
.depend::<rooms::state_accessor::Service>("rooms::state_accessor"),
|
||||||
state_cache: args.depend::<rooms::state_cache::Service>("rooms::state_cache"),
|
state_cache: args.depend::<rooms::state_cache::Service>("rooms::state_cache"),
|
||||||
@@ -200,8 +198,6 @@ impl Service {
|
|||||||
+ Debug
|
+ Debug
|
||||||
+ Send,
|
+ Send,
|
||||||
{
|
{
|
||||||
const VERSIONS: [MatrixVersion; 1] = [MatrixVersion::V1_0];
|
|
||||||
|
|
||||||
let dest = dest.replace(self.services.globals.notification_push_path(), "");
|
let dest = dest.replace(self.services.globals.notification_push_path(), "");
|
||||||
trace!("Push gateway destination: {dest}");
|
trace!("Push gateway destination: {dest}");
|
||||||
|
|
||||||
|
|||||||
@@ -53,9 +53,9 @@ impl Resolver {
|
|||||||
opts.cache_size = config.dns_cache_entries as usize;
|
opts.cache_size = config.dns_cache_entries as usize;
|
||||||
opts.preserve_intermediates = true;
|
opts.preserve_intermediates = true;
|
||||||
opts.negative_min_ttl = Some(Duration::from_secs(config.dns_min_ttl_nxdomain));
|
opts.negative_min_ttl = Some(Duration::from_secs(config.dns_min_ttl_nxdomain));
|
||||||
opts.negative_max_ttl = Some(Duration::from_secs(60 * 60 * 24 * 30));
|
opts.negative_max_ttl = Some(Duration::from_hours(720));
|
||||||
opts.positive_min_ttl = Some(Duration::from_secs(config.dns_min_ttl));
|
opts.positive_min_ttl = Some(Duration::from_secs(config.dns_min_ttl));
|
||||||
opts.positive_max_ttl = Some(Duration::from_secs(60 * 60 * 24 * 7));
|
opts.positive_max_ttl = Some(Duration::from_hours(168));
|
||||||
opts.timeout = Duration::from_secs(config.dns_timeout);
|
opts.timeout = Duration::from_secs(config.dns_timeout);
|
||||||
opts.attempts = config.dns_attempts as usize;
|
opts.attempts = config.dns_attempts as usize;
|
||||||
opts.try_tcp_on_error = config.dns_tcp_fallback;
|
opts.try_tcp_on_error = config.dns_tcp_fallback;
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ use conduwuit::{
|
|||||||
utils::{ReadyExt, stream::TryIgnore},
|
utils::{ReadyExt, stream::TryIgnore},
|
||||||
};
|
};
|
||||||
use database::{Deserialized, Ignore, Interfix, Map};
|
use database::{Deserialized, Ignore, Interfix, Map};
|
||||||
use futures::{Stream, StreamExt, TryFutureExt};
|
use futures::{Stream, StreamExt};
|
||||||
use ruma::{
|
use ruma::{
|
||||||
OwnedRoomAliasId, OwnedRoomId, OwnedServerName, OwnedUserId, RoomAliasId, RoomId,
|
OwnedRoomAliasId, OwnedRoomId, OwnedServerName, OwnedUserId, RoomAliasId, RoomId,
|
||||||
RoomOrAliasId, UserId, events::StateEventType,
|
RoomOrAliasId, UserId, events::StateEventType,
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ use futures::{
|
|||||||
use ruma::{
|
use ruma::{
|
||||||
CanonicalJsonValue, EventId, OwnedUserId, RoomId, ServerName, UserId,
|
CanonicalJsonValue, EventId, OwnedUserId, RoomId, ServerName, UserId,
|
||||||
events::{
|
events::{
|
||||||
StateEventType, TimelineEventType,
|
TimelineEventType,
|
||||||
room::member::{MembershipState, RoomMemberEventContent},
|
room::member::{MembershipState, RoomMemberEventContent},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
@@ -209,7 +209,7 @@ pub async fn handle_incoming_pdu<'a>(
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Fetch create event
|
// Fetch create event
|
||||||
let ref create_event = self
|
let create_event = &self
|
||||||
.services
|
.services
|
||||||
.state_accessor
|
.state_accessor
|
||||||
.get_room_create_event(room_id)
|
.get_room_create_event(room_id)
|
||||||
|
|||||||
@@ -278,8 +278,8 @@ where
|
|||||||
let (short_state_keys, short_event_ids): pair_of!(Vec<_>) = short_state.unzip().await;
|
let (short_state_keys, short_event_ids): pair_of!(Vec<_>) = short_state.unzip().await;
|
||||||
|
|
||||||
StreamExt::zip(
|
StreamExt::zip(
|
||||||
self.multi_get_statekey_from_short(stream::iter(short_state_keys.into_iter())),
|
self.multi_get_statekey_from_short(stream::iter(short_state_keys)),
|
||||||
self.multi_get_eventid_from_short(stream::iter(short_event_ids.into_iter())),
|
self.multi_get_eventid_from_short(stream::iter(short_event_ids)),
|
||||||
)
|
)
|
||||||
.ready_filter_map(|state_event| match state_event {
|
.ready_filter_map(|state_event| match state_event {
|
||||||
| (Ok(state_key), Ok(event_id)) => Some(Ok((state_key, event_id))),
|
| (Ok(state_key), Ok(event_id)) => Some(Ok((state_key, event_id))),
|
||||||
|
|||||||
@@ -98,18 +98,16 @@ impl Service {
|
|||||||
pub async fn is_world_readable(&self, room_id: &RoomId) -> bool {
|
pub async fn is_world_readable(&self, room_id: &RoomId) -> bool {
|
||||||
self.room_state_get_content(room_id, &StateEventType::RoomHistoryVisibility, "")
|
self.room_state_get_content(room_id, &StateEventType::RoomHistoryVisibility, "")
|
||||||
.await
|
.await
|
||||||
.map(|c: RoomHistoryVisibilityEventContent| {
|
.is_ok_and(|c: RoomHistoryVisibilityEventContent| {
|
||||||
c.history_visibility == HistoryVisibility::WorldReadable
|
c.history_visibility == HistoryVisibility::WorldReadable
|
||||||
})
|
})
|
||||||
.unwrap_or(false)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Checks if guests are able to join a given room
|
/// Checks if guests are able to join a given room
|
||||||
pub async fn guest_can_join(&self, room_id: &RoomId) -> bool {
|
pub async fn guest_can_join(&self, room_id: &RoomId) -> bool {
|
||||||
self.room_state_get_content(room_id, &StateEventType::RoomGuestAccess, "")
|
self.room_state_get_content(room_id, &StateEventType::RoomGuestAccess, "")
|
||||||
.await
|
.await
|
||||||
.map(|c: RoomGuestAccessEventContent| c.guest_access == GuestAccess::CanJoin)
|
.is_ok_and(|c: RoomGuestAccessEventContent| c.guest_access == GuestAccess::CanJoin)
|
||||||
.unwrap_or(false)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Gets the primary alias from canonical alias event
|
/// Gets the primary alias from canonical alias event
|
||||||
|
|||||||
@@ -254,7 +254,7 @@ impl Service {
|
|||||||
};
|
};
|
||||||
|
|
||||||
summaries.push(summary.summary);
|
summaries.push(summary.summary);
|
||||||
inaccessible_children.extend(summary.inaccessible_children.into_iter());
|
inaccessible_children.extend(summary.inaccessible_children);
|
||||||
|
|
||||||
// Don't traverse the tree deeper than max_depth
|
// Don't traverse the tree deeper than max_depth
|
||||||
#[allow(
|
#[allow(
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ use conduwuit_core::{
|
|||||||
},
|
},
|
||||||
validated, warn,
|
validated, warn,
|
||||||
};
|
};
|
||||||
use futures::{FutureExt, StreamExt};
|
use futures::FutureExt;
|
||||||
use ruma::{
|
use ruma::{
|
||||||
CanonicalJsonObject, EventId, OwnedServerName, RoomId, ServerName, api::federation,
|
CanonicalJsonObject, EventId, OwnedServerName, RoomId, ServerName, api::federation,
|
||||||
events::TimelineEventType, uint,
|
events::TimelineEventType, uint,
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ use bytes::BytesMut;
|
|||||||
use conduwuit::{Err, Result, debug_error, err, utils, utils::response::LimitReadExt, warn};
|
use conduwuit::{Err, Result, debug_error, err, utils, utils::response::LimitReadExt, warn};
|
||||||
use reqwest::Client;
|
use reqwest::Client;
|
||||||
use ruma::api::{
|
use ruma::api::{
|
||||||
IncomingResponse, MatrixVersion, OutgoingRequest,
|
IncomingResponse, OutgoingRequest,
|
||||||
auth_scheme::{AppserviceToken, SendAccessToken},
|
auth_scheme::{AppserviceToken, SendAccessToken},
|
||||||
path_builder::VersionHistory,
|
path_builder::VersionHistory,
|
||||||
};
|
};
|
||||||
@@ -23,7 +23,6 @@ where
|
|||||||
+ Debug
|
+ Debug
|
||||||
+ Send,
|
+ Send,
|
||||||
{
|
{
|
||||||
const VERSIONS: [MatrixVersion; 1] = [MatrixVersion::V1_15];
|
|
||||||
let http_request = request
|
let http_request = request
|
||||||
.try_into_http_request::<BytesMut>(
|
.try_into_http_request::<BytesMut>(
|
||||||
base_url,
|
base_url,
|
||||||
|
|||||||
@@ -224,7 +224,7 @@ fn parse_servercurrentevent(key: &[u8], value: &[u8]) -> Result<(Destination, Se
|
|||||||
.ok_or_else(|| Error::bad_database("Invalid bytes in servercurrentpdus."))?;
|
.ok_or_else(|| Error::bad_database("Invalid bytes in servercurrentpdus."))?;
|
||||||
|
|
||||||
(
|
(
|
||||||
Destination::Push(user_id.to_owned(), pushkey_string),
|
Destination::Push(user_id, pushkey_string),
|
||||||
if value.is_empty() {
|
if value.is_empty() {
|
||||||
SendingEvent::Pdu(event.into())
|
SendingEvent::Pdu(event.into())
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -203,9 +203,7 @@ impl Service {
|
|||||||
S: Stream<Item = OwnedServerName> + Send,
|
S: Stream<Item = OwnedServerName> + Send,
|
||||||
{
|
{
|
||||||
let requests = servers
|
let requests = servers
|
||||||
.map(|server| {
|
.map(|server| (Destination::Federation(server), SendingEvent::Pdu(pdu_id.to_owned())))
|
||||||
(Destination::Federation(server.into()), SendingEvent::Pdu(pdu_id.to_owned()))
|
|
||||||
})
|
|
||||||
.collect::<Vec<_>>()
|
.collect::<Vec<_>>()
|
||||||
.await;
|
.await;
|
||||||
|
|
||||||
|
|||||||
@@ -236,5 +236,5 @@ async fn acquire_notary_result(&self, missing: &mut Batch, server_keys: ServerSi
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn keys_count(batch: &Batch) -> usize {
|
fn keys_count(batch: &Batch) -> usize {
|
||||||
batch.iter().flat_map(|(_, key_ids)| key_ids.iter()).count()
|
batch.values().flat_map(|key_ids| key_ids.iter()).count()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -50,7 +50,7 @@ pub type PubKeys = PublicKeySet;
|
|||||||
|
|
||||||
impl crate::Service for Service {
|
impl crate::Service for Service {
|
||||||
fn build(args: crate::Args<'_>) -> Result<Arc<Self>> {
|
fn build(args: crate::Args<'_>) -> Result<Arc<Self>> {
|
||||||
let minimum_valid = Duration::from_secs(3600);
|
let minimum_valid = Duration::from_hours(1);
|
||||||
|
|
||||||
let (keypair, verify_keys) = keypair::init(args.db)?;
|
let (keypair, verify_keys) = keypair::init(args.db)?;
|
||||||
debug_assert!(verify_keys.len() == 1, "only one active verify_key supported");
|
debug_assert!(verify_keys.len() == 1, "only one active verify_key supported");
|
||||||
@@ -171,11 +171,10 @@ pub async fn verify_keys_for(&self, origin: &ServerName) -> VerifyKeys {
|
|||||||
let mut keys = self
|
let mut keys = self
|
||||||
.signing_keys_for(origin)
|
.signing_keys_for(origin)
|
||||||
.await
|
.await
|
||||||
.map(|keys| merge_old_keys(keys).verify_keys)
|
.map_or(BTreeMap::new(), |keys| merge_old_keys(keys).verify_keys);
|
||||||
.unwrap_or(BTreeMap::new());
|
|
||||||
|
|
||||||
if self.services.globals.server_is_ours(origin) {
|
if self.services.globals.server_is_ours(origin) {
|
||||||
keys.extend(self.verify_keys.clone().into_iter());
|
keys.extend(self.verify_keys.clone());
|
||||||
}
|
}
|
||||||
|
|
||||||
keys
|
keys
|
||||||
|
|||||||
@@ -23,8 +23,8 @@ pub(super) fn required_keys(
|
|||||||
};
|
};
|
||||||
|
|
||||||
let entry = map.entry(server.clone()).or_default();
|
let entry = map.entry(server.clone()).or_default();
|
||||||
set.iter()
|
set.keys()
|
||||||
.map(|(k, _)| k.clone())
|
.cloned()
|
||||||
.map(TryInto::try_into)
|
.map(TryInto::try_into)
|
||||||
.filter_map(Result::ok)
|
.filter_map(Result::ok)
|
||||||
.for_each(|key_id| entry.push(key_id));
|
.for_each(|key_id| entry.push(key_id));
|
||||||
|
|||||||
@@ -39,6 +39,7 @@ struct Services {
|
|||||||
typing: Dep<rooms::typing::Service>,
|
typing: Dep<rooms::typing::Service>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[allow(unused, reason = "TODO refactor")]
|
||||||
struct SlidingSyncCache {
|
struct SlidingSyncCache {
|
||||||
lists: BTreeMap<String, v5::request::List>,
|
lists: BTreeMap<String, v5::request::List>,
|
||||||
subscriptions: BTreeMap<OwnedRoomId, v5::request::RoomSubscription>,
|
subscriptions: BTreeMap<OwnedRoomId, v5::request::RoomSubscription>,
|
||||||
|
|||||||
@@ -64,7 +64,7 @@ pub async fn watch(&self, user_id: &UserId, device_id: &DeviceId) -> Result {
|
|||||||
futures.push(self.db.pduid_pdu.watch_prefix(&short_roomid));
|
futures.push(self.db.pduid_pdu.watch_prefix(&short_roomid));
|
||||||
|
|
||||||
// EDUs
|
// EDUs
|
||||||
let typing_room_id = room_id.to_owned();
|
let typing_room_id = room_id.clone();
|
||||||
let typing_wait_for_update = async move {
|
let typing_wait_for_update = async move {
|
||||||
self.services.typing.wait_for_update(&typing_room_id).await;
|
self.services.typing.wait_for_update(&typing_room_id).await;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -43,7 +43,7 @@ pub(crate) struct ValidationToken {
|
|||||||
|
|
||||||
impl ValidationToken {
|
impl ValidationToken {
|
||||||
// one hour
|
// one hour
|
||||||
const MAX_TOKEN_AGE: Duration = Duration::from_secs(60 * 60);
|
const MAX_TOKEN_AGE: Duration = Duration::from_hours(1);
|
||||||
const RANDOM_TOKEN_LENGTH: usize = 16;
|
const RANDOM_TOKEN_LENGTH: usize = 16;
|
||||||
|
|
||||||
pub(super) fn new_random() -> Self {
|
pub(super) fn new_random() -> Self {
|
||||||
|
|||||||
@@ -315,7 +315,7 @@ impl Service {
|
|||||||
| TxnState::Active(_) => None,
|
| TxnState::Active(_) => None,
|
||||||
})
|
})
|
||||||
.collect();
|
.collect();
|
||||||
cached_entries.sort_by(|a, b| a.1.cmp(&b.1));
|
cached_entries.sort_by_key(|a| a.1);
|
||||||
|
|
||||||
// Remove the oldest cached entries to get under the limit
|
// Remove the oldest cached entries to get under the limit
|
||||||
for (key, _) in cached_entries.into_iter().take(excess) {
|
for (key, _) in cached_entries.into_iter().take(excess) {
|
||||||
|
|||||||
@@ -165,10 +165,9 @@ impl Service {
|
|||||||
.account_data
|
.account_data
|
||||||
.get_global(recipient_user, GlobalAccountDataEventType::InvitePermissionConfig)
|
.get_global(recipient_user, GlobalAccountDataEventType::InvitePermissionConfig)
|
||||||
.await
|
.await
|
||||||
.map(|config: InvitePermissionConfigEvent| {
|
.map_or(FilterLevel::Allow, |config: InvitePermissionConfigEvent| {
|
||||||
config.content.user_filter_level(sender_user)
|
config.content.user_filter_level(sender_user)
|
||||||
})
|
})
|
||||||
.unwrap_or(FilterLevel::Allow)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user