mirror of
https://github.com/girlbossceo/conduwuit.git
synced 2025-03-14 18:55:37 +00:00
refactor for ruma identifiers optimizations
Signed-off-by: Jason Volk <jason@zemos.net>
This commit is contained in:
parent
d91570d0e6
commit
0a9b6c136f
19 changed files with 81 additions and 88 deletions
26
Cargo.lock
generated
26
Cargo.lock
generated
|
@ -3173,7 +3173,7 @@ dependencies = [
|
|||
[[package]]
|
||||
name = "ruma"
|
||||
version = "0.10.1"
|
||||
source = "git+https://github.com/girlbossceo/ruwuma?rev=54da128bbe09a0c6d14c9a6bf7b6b54a2d7c835a#54da128bbe09a0c6d14c9a6bf7b6b54a2d7c835a"
|
||||
source = "git+https://github.com/girlbossceo/ruwuma?rev=30a08ff7be779df6858036c3f01f3ba64c1ee785#30a08ff7be779df6858036c3f01f3ba64c1ee785"
|
||||
dependencies = [
|
||||
"assign",
|
||||
"js_int",
|
||||
|
@ -3195,7 +3195,7 @@ dependencies = [
|
|||
[[package]]
|
||||
name = "ruma-appservice-api"
|
||||
version = "0.10.0"
|
||||
source = "git+https://github.com/girlbossceo/ruwuma?rev=54da128bbe09a0c6d14c9a6bf7b6b54a2d7c835a#54da128bbe09a0c6d14c9a6bf7b6b54a2d7c835a"
|
||||
source = "git+https://github.com/girlbossceo/ruwuma?rev=30a08ff7be779df6858036c3f01f3ba64c1ee785#30a08ff7be779df6858036c3f01f3ba64c1ee785"
|
||||
dependencies = [
|
||||
"js_int",
|
||||
"ruma-common",
|
||||
|
@ -3207,7 +3207,7 @@ dependencies = [
|
|||
[[package]]
|
||||
name = "ruma-client-api"
|
||||
version = "0.18.0"
|
||||
source = "git+https://github.com/girlbossceo/ruwuma?rev=54da128bbe09a0c6d14c9a6bf7b6b54a2d7c835a#54da128bbe09a0c6d14c9a6bf7b6b54a2d7c835a"
|
||||
source = "git+https://github.com/girlbossceo/ruwuma?rev=30a08ff7be779df6858036c3f01f3ba64c1ee785#30a08ff7be779df6858036c3f01f3ba64c1ee785"
|
||||
dependencies = [
|
||||
"as_variant",
|
||||
"assign",
|
||||
|
@ -3230,7 +3230,7 @@ dependencies = [
|
|||
[[package]]
|
||||
name = "ruma-common"
|
||||
version = "0.13.0"
|
||||
source = "git+https://github.com/girlbossceo/ruwuma?rev=54da128bbe09a0c6d14c9a6bf7b6b54a2d7c835a#54da128bbe09a0c6d14c9a6bf7b6b54a2d7c835a"
|
||||
source = "git+https://github.com/girlbossceo/ruwuma?rev=30a08ff7be779df6858036c3f01f3ba64c1ee785#30a08ff7be779df6858036c3f01f3ba64c1ee785"
|
||||
dependencies = [
|
||||
"as_variant",
|
||||
"base64 0.22.1",
|
||||
|
@ -3261,7 +3261,7 @@ dependencies = [
|
|||
[[package]]
|
||||
name = "ruma-events"
|
||||
version = "0.28.1"
|
||||
source = "git+https://github.com/girlbossceo/ruwuma?rev=54da128bbe09a0c6d14c9a6bf7b6b54a2d7c835a#54da128bbe09a0c6d14c9a6bf7b6b54a2d7c835a"
|
||||
source = "git+https://github.com/girlbossceo/ruwuma?rev=30a08ff7be779df6858036c3f01f3ba64c1ee785#30a08ff7be779df6858036c3f01f3ba64c1ee785"
|
||||
dependencies = [
|
||||
"as_variant",
|
||||
"indexmap 2.7.0",
|
||||
|
@ -3286,7 +3286,7 @@ dependencies = [
|
|||
[[package]]
|
||||
name = "ruma-federation-api"
|
||||
version = "0.9.0"
|
||||
source = "git+https://github.com/girlbossceo/ruwuma?rev=54da128bbe09a0c6d14c9a6bf7b6b54a2d7c835a#54da128bbe09a0c6d14c9a6bf7b6b54a2d7c835a"
|
||||
source = "git+https://github.com/girlbossceo/ruwuma?rev=30a08ff7be779df6858036c3f01f3ba64c1ee785#30a08ff7be779df6858036c3f01f3ba64c1ee785"
|
||||
dependencies = [
|
||||
"bytes",
|
||||
"http",
|
||||
|
@ -3304,7 +3304,7 @@ dependencies = [
|
|||
[[package]]
|
||||
name = "ruma-identifiers-validation"
|
||||
version = "0.9.5"
|
||||
source = "git+https://github.com/girlbossceo/ruwuma?rev=54da128bbe09a0c6d14c9a6bf7b6b54a2d7c835a#54da128bbe09a0c6d14c9a6bf7b6b54a2d7c835a"
|
||||
source = "git+https://github.com/girlbossceo/ruwuma?rev=30a08ff7be779df6858036c3f01f3ba64c1ee785#30a08ff7be779df6858036c3f01f3ba64c1ee785"
|
||||
dependencies = [
|
||||
"js_int",
|
||||
"thiserror 2.0.7",
|
||||
|
@ -3313,7 +3313,7 @@ dependencies = [
|
|||
[[package]]
|
||||
name = "ruma-identity-service-api"
|
||||
version = "0.9.0"
|
||||
source = "git+https://github.com/girlbossceo/ruwuma?rev=54da128bbe09a0c6d14c9a6bf7b6b54a2d7c835a#54da128bbe09a0c6d14c9a6bf7b6b54a2d7c835a"
|
||||
source = "git+https://github.com/girlbossceo/ruwuma?rev=30a08ff7be779df6858036c3f01f3ba64c1ee785#30a08ff7be779df6858036c3f01f3ba64c1ee785"
|
||||
dependencies = [
|
||||
"js_int",
|
||||
"ruma-common",
|
||||
|
@ -3323,7 +3323,7 @@ dependencies = [
|
|||
[[package]]
|
||||
name = "ruma-macros"
|
||||
version = "0.13.0"
|
||||
source = "git+https://github.com/girlbossceo/ruwuma?rev=54da128bbe09a0c6d14c9a6bf7b6b54a2d7c835a#54da128bbe09a0c6d14c9a6bf7b6b54a2d7c835a"
|
||||
source = "git+https://github.com/girlbossceo/ruwuma?rev=30a08ff7be779df6858036c3f01f3ba64c1ee785#30a08ff7be779df6858036c3f01f3ba64c1ee785"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"proc-macro-crate",
|
||||
|
@ -3338,7 +3338,7 @@ dependencies = [
|
|||
[[package]]
|
||||
name = "ruma-push-gateway-api"
|
||||
version = "0.9.0"
|
||||
source = "git+https://github.com/girlbossceo/ruwuma?rev=54da128bbe09a0c6d14c9a6bf7b6b54a2d7c835a#54da128bbe09a0c6d14c9a6bf7b6b54a2d7c835a"
|
||||
source = "git+https://github.com/girlbossceo/ruwuma?rev=30a08ff7be779df6858036c3f01f3ba64c1ee785#30a08ff7be779df6858036c3f01f3ba64c1ee785"
|
||||
dependencies = [
|
||||
"js_int",
|
||||
"ruma-common",
|
||||
|
@ -3350,7 +3350,7 @@ dependencies = [
|
|||
[[package]]
|
||||
name = "ruma-server-util"
|
||||
version = "0.3.0"
|
||||
source = "git+https://github.com/girlbossceo/ruwuma?rev=54da128bbe09a0c6d14c9a6bf7b6b54a2d7c835a#54da128bbe09a0c6d14c9a6bf7b6b54a2d7c835a"
|
||||
source = "git+https://github.com/girlbossceo/ruwuma?rev=30a08ff7be779df6858036c3f01f3ba64c1ee785#30a08ff7be779df6858036c3f01f3ba64c1ee785"
|
||||
dependencies = [
|
||||
"headers",
|
||||
"http",
|
||||
|
@ -3363,7 +3363,7 @@ dependencies = [
|
|||
[[package]]
|
||||
name = "ruma-signatures"
|
||||
version = "0.15.0"
|
||||
source = "git+https://github.com/girlbossceo/ruwuma?rev=54da128bbe09a0c6d14c9a6bf7b6b54a2d7c835a#54da128bbe09a0c6d14c9a6bf7b6b54a2d7c835a"
|
||||
source = "git+https://github.com/girlbossceo/ruwuma?rev=30a08ff7be779df6858036c3f01f3ba64c1ee785#30a08ff7be779df6858036c3f01f3ba64c1ee785"
|
||||
dependencies = [
|
||||
"base64 0.22.1",
|
||||
"ed25519-dalek",
|
||||
|
@ -3379,7 +3379,7 @@ dependencies = [
|
|||
[[package]]
|
||||
name = "ruma-state-res"
|
||||
version = "0.11.0"
|
||||
source = "git+https://github.com/girlbossceo/ruwuma?rev=54da128bbe09a0c6d14c9a6bf7b6b54a2d7c835a#54da128bbe09a0c6d14c9a6bf7b6b54a2d7c835a"
|
||||
source = "git+https://github.com/girlbossceo/ruwuma?rev=30a08ff7be779df6858036c3f01f3ba64c1ee785#30a08ff7be779df6858036c3f01f3ba64c1ee785"
|
||||
dependencies = [
|
||||
"futures-util",
|
||||
"js_int",
|
||||
|
|
|
@ -336,7 +336,7 @@ version = "0.1.2"
|
|||
[workspace.dependencies.ruma]
|
||||
git = "https://github.com/girlbossceo/ruwuma"
|
||||
#branch = "conduwuit-changes"
|
||||
rev = "54da128bbe09a0c6d14c9a6bf7b6b54a2d7c835a"
|
||||
rev = "30a08ff7be779df6858036c3f01f3ba64c1ee785"
|
||||
features = [
|
||||
"compat",
|
||||
"rand",
|
||||
|
|
|
@ -75,7 +75,7 @@ pub(super) async fn parse_pdu(&self) -> Result<RoomMessageEventContent> {
|
|||
match serde_json::from_str(&string) {
|
||||
| Ok(value) => match ruma::signatures::reference_hash(&value, &RoomVersionId::V6) {
|
||||
| Ok(hash) => {
|
||||
let event_id = EventId::parse(format!("${hash}"));
|
||||
let event_id = OwnedEventId::parse(format!("${hash}"));
|
||||
|
||||
match serde_json::from_value::<PduEvent>(
|
||||
serde_json::to_value(value).expect("value is json"),
|
||||
|
|
|
@ -4,8 +4,7 @@ use clap::Subcommand;
|
|||
use conduwuit::Result;
|
||||
use futures::StreamExt;
|
||||
use ruma::{
|
||||
events::room::message::RoomMessageEventContent, OwnedRoomAliasId, OwnedRoomId, RoomAliasId,
|
||||
RoomId,
|
||||
events::room::message::RoomMessageEventContent, OwnedRoomAliasId, OwnedRoomId, RoomId,
|
||||
};
|
||||
|
||||
use crate::{escape_html, Command};
|
||||
|
@ -58,7 +57,7 @@ pub(super) async fn process(
|
|||
| RoomAliasCommand::Which { ref room_alias_localpart } => {
|
||||
let room_alias_str =
|
||||
format!("#{}:{}", room_alias_localpart, services.globals.server_name());
|
||||
let room_alias = match RoomAliasId::parse_box(room_alias_str) {
|
||||
let room_alias = match OwnedRoomAliasId::parse(room_alias_str) {
|
||||
| Ok(alias) => alias,
|
||||
| Err(err) =>
|
||||
return Ok(RoomMessageEventContent::text_plain(format!(
|
||||
|
|
|
@ -105,10 +105,9 @@ async fn ban_room(
|
|||
};
|
||||
|
||||
debug!("Room specified is a room ID, banning room ID");
|
||||
self.services.rooms.metadata.ban_room(room_id, true);
|
||||
|
||||
self.services.rooms.metadata.ban_room(&room_id, true);
|
||||
|
||||
room_id
|
||||
room_id.to_owned()
|
||||
} else if room.is_room_alias_id() {
|
||||
let room_alias = match RoomAliasId::parse(&room) {
|
||||
| Ok(room_alias) => room_alias,
|
||||
|
@ -129,7 +128,7 @@ async fn ban_room(
|
|||
.services
|
||||
.rooms
|
||||
.alias
|
||||
.resolve_local_alias(&room_alias)
|
||||
.resolve_local_alias(room_alias)
|
||||
.await
|
||||
{
|
||||
room_id
|
||||
|
@ -143,20 +142,20 @@ async fn ban_room(
|
|||
.services
|
||||
.rooms
|
||||
.alias
|
||||
.resolve_alias(&room_alias, None)
|
||||
.resolve_alias(room_alias, None)
|
||||
.await
|
||||
{
|
||||
| Ok((room_id, servers)) => {
|
||||
debug!(
|
||||
?room_id,
|
||||
?servers,
|
||||
"Got federation response fetching room ID for {room}"
|
||||
"Got federation response fetching room ID for {room_id}"
|
||||
);
|
||||
room_id
|
||||
},
|
||||
| Err(e) => {
|
||||
return Ok(RoomMessageEventContent::notice_plain(format!(
|
||||
"Failed to resolve room alias {room} to a room ID: {e}"
|
||||
"Failed to resolve room alias {room_alias} to a room ID: {e}"
|
||||
)));
|
||||
},
|
||||
}
|
||||
|
@ -316,7 +315,7 @@ async fn ban_list_of_rooms(
|
|||
},
|
||||
};
|
||||
|
||||
room_ids.push(room_id);
|
||||
room_ids.push(room_id.to_owned());
|
||||
}
|
||||
|
||||
if room_alias_or_id.is_room_alias_id() {
|
||||
|
@ -326,7 +325,7 @@ async fn ban_list_of_rooms(
|
|||
.services
|
||||
.rooms
|
||||
.alias
|
||||
.resolve_local_alias(&room_alias)
|
||||
.resolve_local_alias(room_alias)
|
||||
.await
|
||||
{
|
||||
room_id
|
||||
|
@ -340,7 +339,7 @@ async fn ban_list_of_rooms(
|
|||
.services
|
||||
.rooms
|
||||
.alias
|
||||
.resolve_alias(&room_alias, None)
|
||||
.resolve_alias(room_alias, None)
|
||||
.await
|
||||
{
|
||||
| Ok((room_id, servers)) => {
|
||||
|
@ -519,10 +518,9 @@ async fn unban_room(
|
|||
};
|
||||
|
||||
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
|
||||
room_id.to_owned()
|
||||
} else if room.is_room_alias_id() {
|
||||
let room_alias = match RoomAliasId::parse(&room) {
|
||||
| Ok(room_alias) => room_alias,
|
||||
|
@ -543,7 +541,7 @@ async fn unban_room(
|
|||
.services
|
||||
.rooms
|
||||
.alias
|
||||
.resolve_local_alias(&room_alias)
|
||||
.resolve_local_alias(room_alias)
|
||||
.await
|
||||
{
|
||||
room_id
|
||||
|
@ -557,7 +555,7 @@ async fn unban_room(
|
|||
.services
|
||||
.rooms
|
||||
.alias
|
||||
.resolve_alias(&room_alias, None)
|
||||
.resolve_alias(room_alias, None)
|
||||
.await
|
||||
{
|
||||
| Ok((room_id, servers)) => {
|
||||
|
|
|
@ -1,7 +1,9 @@
|
|||
use std::collections::BTreeMap;
|
||||
|
||||
use axum::extract::State;
|
||||
use conduwuit::{debug_info, debug_warn, error, info, pdu::PduBuilder, warn, Err, Error, Result};
|
||||
use conduwuit::{
|
||||
debug_info, debug_warn, err, error, info, pdu::PduBuilder, warn, Err, Error, Result,
|
||||
};
|
||||
use futures::FutureExt;
|
||||
use ruma::{
|
||||
api::client::{
|
||||
|
@ -24,8 +26,7 @@ use ruma::{
|
|||
},
|
||||
int,
|
||||
serde::{JsonObject, Raw},
|
||||
CanonicalJsonObject, Int, OwnedRoomAliasId, OwnedRoomId, OwnedUserId, RoomAliasId, RoomId,
|
||||
RoomVersionId,
|
||||
CanonicalJsonObject, Int, OwnedRoomAliasId, OwnedRoomId, OwnedUserId, RoomId, RoomVersionId,
|
||||
};
|
||||
use serde_json::{json, value::to_raw_value};
|
||||
use service::{appservice::RegistrationInfo, Services};
|
||||
|
@ -554,14 +555,15 @@ async fn room_alias_check(
|
|||
return Err(Error::BadRequest(ErrorKind::Unknown, "Room alias name is forbidden."));
|
||||
}
|
||||
|
||||
let full_room_alias = RoomAliasId::parse(format!(
|
||||
"#{}:{}",
|
||||
room_alias_name, services.globals.config.server_name
|
||||
))
|
||||
.map_err(|e| {
|
||||
info!("Failed to parse room alias {room_alias_name}: {e}");
|
||||
Error::BadRequest(ErrorKind::InvalidParam, "Invalid room alias specified.")
|
||||
})?;
|
||||
let server_name = services.globals.server_name();
|
||||
let full_room_alias = OwnedRoomAliasId::parse(format!("#{room_alias_name}:{server_name}"))
|
||||
.map_err(|e| {
|
||||
err!(Request(InvalidParam(debug_error!(
|
||||
?e,
|
||||
?room_alias_name,
|
||||
"Failed to parse room alias.",
|
||||
))))
|
||||
})?;
|
||||
|
||||
if services
|
||||
.rooms
|
||||
|
@ -620,15 +622,11 @@ fn custom_room_id_check(services: &Services, custom_room_id: &str) -> Result<Own
|
|||
));
|
||||
}
|
||||
|
||||
let full_room_id = format!("!{}:{}", custom_room_id, services.globals.config.server_name);
|
||||
let server_name = services.globals.server_name();
|
||||
let full_room_id = format!("!{custom_room_id}:{server_name}");
|
||||
|
||||
debug_info!("Full custom room ID: {full_room_id}");
|
||||
|
||||
RoomId::parse(full_room_id).map_err(|e| {
|
||||
info!(
|
||||
"User attempted to create room with custom room ID {custom_room_id} but failed \
|
||||
parsing: {e}"
|
||||
);
|
||||
Error::BadRequest(ErrorKind::InvalidParam, "Custom room ID could not be parsed")
|
||||
})
|
||||
OwnedRoomId::parse(full_room_id)
|
||||
.map_err(Into::into)
|
||||
.inspect(|full_room_id| debug_info!(?full_room_id, "Full custom room ID"))
|
||||
.inspect_err(|e| warn!(?e, ?custom_room_id, "Failed to create room with custom room ID",))
|
||||
}
|
||||
|
|
|
@ -18,7 +18,7 @@ use ruma::{
|
|||
},
|
||||
uiaa::UserIdentifier,
|
||||
},
|
||||
UserId,
|
||||
OwnedUserId, UserId,
|
||||
};
|
||||
use serde::Deserialize;
|
||||
|
||||
|
@ -83,7 +83,7 @@ pub(crate) async fn login_route(
|
|||
services.globals.server_name(),
|
||||
)
|
||||
} else if let Some(user) = user {
|
||||
UserId::parse(user)
|
||||
OwnedUserId::parse(user)
|
||||
} else {
|
||||
warn!("Bad login type: {:?}", &body.login_info);
|
||||
return Err!(Request(Forbidden("Bad login type.")));
|
||||
|
@ -147,7 +147,7 @@ pub(crate) async fn login_route(
|
|||
services.globals.server_name(),
|
||||
)
|
||||
} else if let Some(user) = user {
|
||||
UserId::parse(user)
|
||||
OwnedUserId::parse(user)
|
||||
} else {
|
||||
warn!("Bad login type: {:?}", &body.login_info);
|
||||
return Err(Error::BadRequest(ErrorKind::forbidden(), "Bad login type."));
|
||||
|
|
|
@ -962,7 +962,7 @@ async fn calculate_state_initial(
|
|||
};
|
||||
|
||||
// This check is in case a bad user ID made it into the database
|
||||
if let Ok(uid) = UserId::parse(&state_key) {
|
||||
if let Ok(uid) = OwnedUserId::parse(&state_key) {
|
||||
lazy_loaded.insert(uid);
|
||||
}
|
||||
|
||||
|
@ -1079,7 +1079,7 @@ async fn calculate_state_incremental(
|
|||
}
|
||||
|
||||
if let Some(state_key) = &state_event.state_key {
|
||||
let user_id = UserId::parse(state_key.clone())
|
||||
let user_id = UserId::parse(state_key)
|
||||
.map_err(|_| Error::bad_database("Invalid UserId in member PDU."))?;
|
||||
|
||||
if user_id == sender_user {
|
||||
|
@ -1091,15 +1091,15 @@ async fn calculate_state_incremental(
|
|||
match content.membership {
|
||||
| MembershipState::Join => {
|
||||
// A new user joined an encrypted room
|
||||
if !share_encrypted_room(services, sender_user, &user_id, Some(room_id))
|
||||
if !share_encrypted_room(services, sender_user, user_id, Some(room_id))
|
||||
.await
|
||||
{
|
||||
device_list_updates.insert(user_id);
|
||||
device_list_updates.insert(user_id.into());
|
||||
}
|
||||
},
|
||||
| MembershipState::Leave => {
|
||||
// Write down users that have left encrypted rooms we are in
|
||||
left_encrypted_users.insert(user_id);
|
||||
left_encrypted_users.insert(user_id.into());
|
||||
},
|
||||
| _ => {},
|
||||
}
|
||||
|
|
|
@ -30,7 +30,7 @@ use ruma::{
|
|||
TimelineEventType::{self, *},
|
||||
},
|
||||
serde::Raw,
|
||||
uint, MilliSecondsSinceUnixEpoch, OwnedEventId, OwnedRoomId, UInt, UserId,
|
||||
uint, MilliSecondsSinceUnixEpoch, OwnedEventId, OwnedRoomId, OwnedUserId, UInt,
|
||||
};
|
||||
use service::{rooms::read_receipt::pack_receipts, Services};
|
||||
|
||||
|
@ -243,7 +243,7 @@ pub(crate) async fn sync_events_v4_route(
|
|||
if pdu.kind == RoomMember {
|
||||
if let Some(state_key) = &pdu.state_key {
|
||||
let user_id =
|
||||
UserId::parse(state_key.clone()).map_err(|_| {
|
||||
OwnedUserId::parse(state_key.clone()).map_err(|_| {
|
||||
Error::bad_database("Invalid UserId in member PDU.")
|
||||
})?;
|
||||
|
||||
|
|
|
@ -212,7 +212,7 @@ async fn auth_appservice(
|
|||
.query
|
||||
.user_id
|
||||
.clone()
|
||||
.map_or_else(user_id_default, UserId::parse)
|
||||
.map_or_else(user_id_default, OwnedUserId::parse)
|
||||
else {
|
||||
return Err!(Request(InvalidUsername("Username is invalid.")));
|
||||
};
|
||||
|
|
|
@ -6,7 +6,7 @@ use ruma::{
|
|||
api::{client::error::ErrorKind, federation::membership::create_invite},
|
||||
events::room::member::{MembershipState, RoomMemberEventContent},
|
||||
serde::JsonObject,
|
||||
CanonicalJsonValue, EventId, OwnedUserId, UserId,
|
||||
CanonicalJsonValue, OwnedEventId, OwnedUserId, UserId,
|
||||
};
|
||||
|
||||
use crate::Ruma;
|
||||
|
@ -86,7 +86,7 @@ pub(crate) async fn create_invite_route(
|
|||
.map_err(|e| err!(Request(InvalidParam("Failed to sign event: {e}"))))?;
|
||||
|
||||
// Generate event id
|
||||
let event_id = EventId::parse(format!(
|
||||
let event_id = OwnedEventId::parse(format!(
|
||||
"${}",
|
||||
ruma::signatures::reference_hash(&signed_event, &body.room_version)
|
||||
.expect("ruma can calculate reference hashes")
|
||||
|
|
|
@ -10,9 +10,7 @@ use std::{
|
|||
use conduwuit::{error, Config, Result};
|
||||
use data::Data;
|
||||
use regex::RegexSet;
|
||||
use ruma::{
|
||||
OwnedEventId, OwnedRoomAliasId, OwnedServerName, OwnedUserId, RoomAliasId, ServerName, UserId,
|
||||
};
|
||||
use ruma::{OwnedEventId, OwnedRoomAliasId, OwnedServerName, OwnedUserId, ServerName, UserId};
|
||||
use tokio::sync::Mutex;
|
||||
|
||||
use crate::service;
|
||||
|
@ -73,7 +71,7 @@ impl crate::Service for Service {
|
|||
jwt_decoding_key,
|
||||
bad_event_ratelimiter: Arc::new(RwLock::new(HashMap::new())),
|
||||
stateres_mutex: Arc::new(Mutex::new(())),
|
||||
admin_alias: RoomAliasId::parse(format!("#admins:{}", &config.server_name))
|
||||
admin_alias: OwnedRoomAliasId::try_from(format!("#admins:{}", &config.server_name))
|
||||
.expect("#admins:server_name is valid alias name"),
|
||||
server_user: UserId::parse_with_server_name(
|
||||
String::from("conduit"),
|
||||
|
|
|
@ -129,10 +129,10 @@ impl Service {
|
|||
servers: Option<Vec<OwnedServerName>>,
|
||||
) -> Result<(OwnedRoomId, Vec<OwnedServerName>)> {
|
||||
if room.is_room_id() {
|
||||
let room_id = RoomId::parse(room).expect("valid RoomId");
|
||||
Ok((room_id, servers.unwrap_or_default()))
|
||||
let room_id: &RoomId = room.try_into().expect("valid RoomId");
|
||||
Ok((room_id.to_owned(), servers.unwrap_or_default()))
|
||||
} else {
|
||||
let alias = &RoomAliasId::parse(room).expect("valid RoomAliasId");
|
||||
let alias: &RoomAliasId = room.try_into().expect("valid RoomAliasId");
|
||||
self.resolve_alias(alias, servers).await
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
use conduwuit::{err, implement, pdu::gen_event_id_canonical_json, result::FlatOk, Result};
|
||||
use ruma::{CanonicalJsonObject, CanonicalJsonValue, OwnedEventId, OwnedRoomId, RoomId};
|
||||
use ruma::{CanonicalJsonObject, CanonicalJsonValue, OwnedEventId, OwnedRoomId};
|
||||
use serde_json::value::RawValue as RawJsonValue;
|
||||
|
||||
#[implement(super::Service)]
|
||||
|
@ -14,7 +14,7 @@ pub async fn parse_incoming_pdu(
|
|||
let room_id: OwnedRoomId = value
|
||||
.get("room_id")
|
||||
.and_then(CanonicalJsonValue::as_str)
|
||||
.map(RoomId::parse)
|
||||
.map(OwnedRoomId::parse)
|
||||
.flat_ok_or(err!(Request(InvalidParam("Invalid room_id in pdu"))))?;
|
||||
|
||||
let room_version_id = self
|
||||
|
|
|
@ -139,7 +139,7 @@ impl Service {
|
|||
.state_cache
|
||||
.update_membership(
|
||||
room_id,
|
||||
&user_id,
|
||||
user_id,
|
||||
membership_event,
|
||||
&pdu.sender,
|
||||
None,
|
||||
|
|
|
@ -35,7 +35,7 @@ use ruma::{
|
|||
push::{Action, Ruleset, Tweak},
|
||||
state_res::{self, Event, RoomVersion},
|
||||
uint, user_id, CanonicalJsonObject, CanonicalJsonValue, EventId, OwnedEventId, OwnedRoomId,
|
||||
OwnedServerName, RoomId, RoomVersionId, ServerName, UserId,
|
||||
OwnedServerName, OwnedUserId, RoomId, RoomVersionId, ServerName, UserId,
|
||||
};
|
||||
use serde::Deserialize;
|
||||
use serde_json::value::{to_raw_value, RawValue as RawJsonValue};
|
||||
|
@ -424,7 +424,7 @@ impl Service {
|
|||
|
||||
if pdu.kind == TimelineEventType::RoomMember {
|
||||
if let Some(state_key) = &pdu.state_key {
|
||||
let target_user_id = UserId::parse(state_key.clone())?;
|
||||
let target_user_id = OwnedUserId::parse(state_key)?;
|
||||
|
||||
if self.services.users.is_active_local(&target_user_id).await {
|
||||
push_target.insert(target_user_id);
|
||||
|
@ -534,7 +534,7 @@ impl Service {
|
|||
| TimelineEventType::RoomMember => {
|
||||
if let Some(state_key) = &pdu.state_key {
|
||||
// if the state_key fails
|
||||
let target_user_id = UserId::parse(state_key.clone())
|
||||
let target_user_id = UserId::parse(state_key)
|
||||
.expect("This state_key was previously validated");
|
||||
|
||||
let content: RoomMemberEventContent = pdu.get_content()?;
|
||||
|
@ -550,7 +550,7 @@ impl Service {
|
|||
.state_cache
|
||||
.update_membership(
|
||||
&pdu.room_id,
|
||||
&target_user_id,
|
||||
target_user_id,
|
||||
content,
|
||||
&pdu.sender,
|
||||
invite_state,
|
||||
|
@ -627,7 +627,7 @@ impl Service {
|
|||
.and_then(|state_key| UserId::parse(state_key.as_str()).ok())
|
||||
{
|
||||
let appservice_uid = appservice.registration.sender_localpart.as_str();
|
||||
if state_key_uid == appservice_uid {
|
||||
if state_key_uid == &appservice_uid {
|
||||
self.services
|
||||
.sending
|
||||
.send_pdu_appservice(appservice.registration.id.clone(), pdu_id)?;
|
||||
|
|
|
@ -7,7 +7,7 @@ use conduwuit::{
|
|||
};
|
||||
use database::{Database, Deserialized, Map};
|
||||
use futures::{Stream, StreamExt};
|
||||
use ruma::{ServerName, UserId};
|
||||
use ruma::{OwnedServerName, ServerName, UserId};
|
||||
|
||||
use super::{Destination, SendingEvent};
|
||||
use crate::{globals, Dep};
|
||||
|
@ -209,7 +209,7 @@ fn parse_servercurrentevent(key: &[u8], value: &[u8]) -> Result<(Destination, Se
|
|||
let mut parts = key[1..].splitn(3, |&b| b == 0xFF);
|
||||
|
||||
let user = parts.next().expect("splitn always returns one element");
|
||||
let user_string = utils::string_from_bytes(user)
|
||||
let user_string = utils::str_from_bytes(user)
|
||||
.map_err(|_| Error::bad_database("Invalid user string in servercurrentevent"))?;
|
||||
let user_id = UserId::parse(user_string)
|
||||
.map_err(|_| Error::bad_database("Invalid user id in servercurrentevent"))?;
|
||||
|
@ -225,7 +225,7 @@ fn parse_servercurrentevent(key: &[u8], value: &[u8]) -> Result<(Destination, Se
|
|||
.ok_or_else(|| Error::bad_database("Invalid bytes in servercurrentpdus."))?;
|
||||
|
||||
(
|
||||
Destination::Push(user_id, pushkey_string),
|
||||
Destination::Push(user_id.to_owned(), pushkey_string),
|
||||
if value.is_empty() {
|
||||
SendingEvent::Pdu(event.into())
|
||||
} else {
|
||||
|
@ -246,7 +246,7 @@ fn parse_servercurrentevent(key: &[u8], value: &[u8]) -> Result<(Destination, Se
|
|||
})?;
|
||||
|
||||
(
|
||||
Destination::Federation(ServerName::parse(server).map_err(|_| {
|
||||
Destination::Federation(OwnedServerName::parse(&server).map_err(|_| {
|
||||
Error::bad_database("Invalid server string in server_currenttransaction")
|
||||
})?),
|
||||
if value.is_empty() {
|
||||
|
|
|
@ -883,7 +883,7 @@ impl Service {
|
|||
.get("room_id")
|
||||
.and_then(|val| RoomId::parse(val.as_str()?).ok())
|
||||
{
|
||||
match self.services.state.get_room_version(&room_id).await {
|
||||
match self.services.state.get_room_version(room_id).await {
|
||||
| Ok(room_version_id) => match room_version_id {
|
||||
| RoomVersionId::V1 | RoomVersionId::V2 => {},
|
||||
| _ => _ = pdu_json.remove("event_id"),
|
||||
|
|
|
@ -937,7 +937,7 @@ impl Service {
|
|||
let user_string = utils::string_from_bytes(user_bytes)
|
||||
.map_err(|e| err!(Database("User ID in openid_userid is invalid unicode. {e}")))?;
|
||||
|
||||
UserId::parse(user_string)
|
||||
OwnedUserId::try_from(user_string)
|
||||
.map_err(|e| err!(Database("User ID in openid_userid is invalid. {e}")))
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue