From 97a01a1500da637b85d59aa4c75327c1c68b3c8e Mon Sep 17 00:00:00 2001 From: Ginger Date: Fri, 10 Apr 2026 11:47:01 -0400 Subject: [PATCH] refactor: Rename PduBuilder to PartialPdu --- src/admin/user/commands.rs | 8 ++--- src/api/client/account/mod.rs | 8 ++--- src/api/client/membership/ban.rs | 4 +-- src/api/client/membership/invite.rs | 4 +-- src/api/client/membership/join.rs | 4 +-- src/api/client/membership/kick.rs | 4 +-- src/api/client/membership/knock.rs | 4 +-- src/api/client/membership/leave.rs | 4 +-- src/api/client/membership/unban.rs | 4 +-- src/api/client/profile.rs | 12 +++---- src/api/client/redact.rs | 6 ++-- src/api/client/room/create.rs | 32 +++++++++---------- src/api/client/room/upgrade.rs | 4 +-- src/api/client/send.rs | 4 +-- src/api/client/state.rs | 4 +-- src/api/server/make_join.rs | 6 ++-- src/api/server/make_knock.rs | 4 +-- src/api/server/make_leave.rs | 4 +-- src/core/matrix/mod.rs | 2 +- src/core/matrix/pdu.rs | 4 +-- .../matrix/pdu/{builder.rs => partial.rs} | 8 ++--- src/service/admin/create.rs | 20 ++++++------ src/service/admin/grant.rs | 12 +++---- src/service/admin/mod.rs | 6 ++-- src/service/rooms/state_accessor/user_can.rs | 2 +- src/service/rooms/timeline/build.rs | 8 ++--- src/service/rooms/timeline/create.rs | 8 ++--- 27 files changed, 95 insertions(+), 95 deletions(-) rename src/core/matrix/pdu/{builder.rs => partial.rs} (91%) diff --git a/src/admin/user/commands.rs b/src/admin/user/commands.rs index 4b6589fda..8e0325c73 100644 --- a/src/admin/user/commands.rs +++ b/src/admin/user/commands.rs @@ -9,7 +9,7 @@ use api::client::{ }; use conduwuit::{ Err, Result, debug_warn, error, info, - matrix::{Event, pdu::PduBuilder}, + matrix::{Event, pdu::PartialPdu}, utils::{self, ReadyExt}, warn, }; @@ -753,7 +753,7 @@ pub(super) async fn force_demote(&self, user_id: String, room_id: OwnedRoomOrAli .rooms .timeline .build_and_append_pdu( - PduBuilder::state( + PartialPdu::state( String::new(), room_power_levels .try_into() @@ -921,9 +921,9 @@ pub(super) async fn redact_event(&self, event_id: OwnedEventId) -> Result { .rooms .timeline .build_and_append_pdu( - PduBuilder { + PartialPdu { redacts: Some(event.event_id().to_owned()), - ..PduBuilder::timeline(&RoomRedactionEventContent { + ..PartialPdu::timeline(&RoomRedactionEventContent { redacts: Some(event.event_id().to_owned()), reason: Some(reason), }) diff --git a/src/api/client/account/mod.rs b/src/api/client/account/mod.rs index 33dadf3ca..5274ca616 100644 --- a/src/api/client/account/mod.rs +++ b/src/api/client/account/mod.rs @@ -2,7 +2,7 @@ use axum::extract::State; use axum_client_ip::ClientIp; use conduwuit::{ Err, Result, err, info, - pdu::PduBuilder, + pdu::PartialPdu, utils::{ReadyExt, stream::BroadbandExt}, }; use conduwuit_service::Services; @@ -367,7 +367,7 @@ pub async fn full_user_deactivate( // TODO: Rescind all user invites - let mut pdu_queue: Vec<(PduBuilder, &OwnedRoomId)> = Vec::new(); + let mut pdu_queue: Vec<(PartialPdu, &OwnedRoomId)> = Vec::new(); for room_id in all_joined_rooms { let room_power_levels = services @@ -384,13 +384,13 @@ pub async fn full_user_deactivate( RoomPowerLevelsEventContent::try_from(room_power_levels) { power_levels_content.users.remove(user_id); - let pl_evt = PduBuilder::state(String::new(), &power_levels_content); + let pl_evt = PartialPdu::state(String::new(), &power_levels_content); pdu_queue.push((pl_evt, room_id)); } // Leave the room pdu_queue.push(( - PduBuilder::state( + PartialPdu::state( user_id.to_string(), &RoomMemberEventContent::new(MembershipState::Leave), ), diff --git a/src/api/client/membership/ban.rs b/src/api/client/membership/ban.rs index 331aa1a86..ed25e1137 100644 --- a/src/api/client/membership/ban.rs +++ b/src/api/client/membership/ban.rs @@ -1,5 +1,5 @@ use axum::extract::State; -use conduwuit::{Err, Result, matrix::pdu::PduBuilder}; +use conduwuit::{Err, Result, matrix::pdu::PartialPdu}; use ruma::{ api::client::membership::ban_user, events::room::member::{MembershipState, RoomMemberEventContent}, @@ -46,7 +46,7 @@ pub(crate) async fn ban_user_route( .rooms .timeline .build_and_append_pdu( - PduBuilder::state(body.user_id.to_string(), &content), + PartialPdu::state(body.user_id.to_string(), &content), sender_user, Some(&body.room_id), &state_lock, diff --git a/src/api/client/membership/invite.rs b/src/api/client/membership/invite.rs index ca7c0eb72..23c466581 100644 --- a/src/api/client/membership/invite.rs +++ b/src/api/client/membership/invite.rs @@ -2,7 +2,7 @@ use axum::extract::State; use axum_client_ip::ClientIp; use conduwuit::{ Err, Result, debug_error, err, info, - matrix::{event::gen_event_id_canonical_json, pdu::PduBuilder}, + matrix::{event::gen_event_id_canonical_json, pdu::PartialPdu}, warn, }; use futures::FutureExt; @@ -156,7 +156,7 @@ pub(crate) async fn invite_helper( .rooms .timeline .create_hash_and_sign_event( - PduBuilder::state(recipient_user.to_string(), &content), + PartialPdu::state(recipient_user.to_string(), &content), sender_user, Some(room_id), &state_lock, diff --git a/src/api/client/membership/join.rs b/src/api/client/membership/join.rs index 64a5c461e..91075c693 100644 --- a/src/api/client/membership/join.rs +++ b/src/api/client/membership/join.rs @@ -7,7 +7,7 @@ use conduwuit::{ matrix::{ StateKey, event::{gen_event_id, gen_event_id_canonical_json}, - pdu::{PduBuilder, PduEvent}, + pdu::{PartialPdu, PduEvent}, state_res, }, result::FlatOk, @@ -761,7 +761,7 @@ async fn join_room_by_id_helper_local( .rooms .timeline .build_and_append_pdu( - PduBuilder::state(sender_user.to_string(), &content), + PartialPdu::state(sender_user.to_string(), &content), sender_user, Some(room_id), &state_lock, diff --git a/src/api/client/membership/kick.rs b/src/api/client/membership/kick.rs index 28b4a71c0..5d78d0c2e 100644 --- a/src/api/client/membership/kick.rs +++ b/src/api/client/membership/kick.rs @@ -1,5 +1,5 @@ use axum::extract::State; -use conduwuit::{Err, Result, matrix::pdu::PduBuilder}; +use conduwuit::{Err, Result, matrix::pdu::PartialPdu}; use ruma::{api::client::membership::kick_user, events::room::member::MembershipState}; use crate::Ruma; @@ -48,7 +48,7 @@ pub(crate) async fn kick_user_route( .rooms .timeline .build_and_append_pdu( - PduBuilder::state(body.user_id.to_string(), &event), + PartialPdu::state(body.user_id.to_string(), &event), sender_user, Some(&body.room_id), &state_lock, diff --git a/src/api/client/membership/knock.rs b/src/api/client/membership/knock.rs index 4e2175b0f..fb6f16909 100644 --- a/src/api/client/membership/knock.rs +++ b/src/api/client/membership/knock.rs @@ -6,7 +6,7 @@ use conduwuit::{ Err, Result, debug, debug_info, debug_warn, err, info, matrix::{ event::gen_event_id, - pdu::{PduBuilder, PduEvent}, + pdu::{PartialPdu, PduEvent}, }, result::FlatOk, trace, @@ -354,7 +354,7 @@ async fn knock_room_helper_local( .rooms .timeline .build_and_append_pdu( - PduBuilder::state(sender_user.to_string(), &content), + PartialPdu::state(sender_user.to_string(), &content), sender_user, Some(room_id), &state_lock, diff --git a/src/api/client/membership/leave.rs b/src/api/client/membership/leave.rs index 304f23f4a..af8c042dd 100644 --- a/src/api/client/membership/leave.rs +++ b/src/api/client/membership/leave.rs @@ -3,7 +3,7 @@ use std::collections::HashSet; use axum::extract::State; use conduwuit::{ Err, Pdu, Result, debug_info, debug_warn, err, - matrix::{event::gen_event_id, pdu::PduBuilder}, + matrix::{event::gen_event_id, pdu::PartialPdu}, utils::{self, FutureBoolExt, future::ReadyEqExt}, warn, }; @@ -148,7 +148,7 @@ pub async fn leave_room( .rooms .timeline .build_and_append_pdu( - PduBuilder::state(user_id.to_string(), &content), + PartialPdu::state(user_id.to_string(), &content), user_id, Some(room_id), &state_lock, diff --git a/src/api/client/membership/unban.rs b/src/api/client/membership/unban.rs index 3ddd60b3e..e5ad757a8 100644 --- a/src/api/client/membership/unban.rs +++ b/src/api/client/membership/unban.rs @@ -1,5 +1,5 @@ use axum::extract::State; -use conduwuit::{Err, Result, matrix::pdu::PduBuilder}; +use conduwuit::{Err, Result, matrix::pdu::PartialPdu}; use ruma::{ api::client::membership::unban_user, events::room::member::{MembershipState, RoomMemberEventContent}, @@ -44,7 +44,7 @@ pub(crate) async fn unban_user_route( .rooms .timeline .build_and_append_pdu( - PduBuilder::state(body.user_id.to_string(), ¤t_member_content), + PartialPdu::state(body.user_id.to_string(), ¤t_member_content), sender_user, Some(&body.room_id), &state_lock, diff --git a/src/api/client/profile.rs b/src/api/client/profile.rs index 17bd5691d..8ed4a0b41 100644 --- a/src/api/client/profile.rs +++ b/src/api/client/profile.rs @@ -1,7 +1,7 @@ use axum::extract::State; use conduwuit::{ Err, Result, - matrix::pdu::PduBuilder, + matrix::pdu::PartialPdu, utils::{IterStream, future::TryExtExt, stream::TryIgnore}, warn, }; @@ -328,7 +328,7 @@ pub async fn update_displayname( .iter() .try_stream() .and_then(|room_id: &OwnedRoomId| async move { - let pdu = PduBuilder::state(user_id.to_string(), &RoomMemberEventContent { + let pdu = PartialPdu::state(user_id.to_string(), &RoomMemberEventContent { displayname: displayname.clone(), membership: MembershipState::Join, avatar_url: avatar_url.clone(), @@ -380,7 +380,7 @@ pub async fn update_avatar_url( .iter() .try_stream() .and_then(|room_id: &OwnedRoomId| async move { - let pdu = PduBuilder::state(user_id.to_string(), &RoomMemberEventContent { + let pdu = PartialPdu::state(user_id.to_string(), &RoomMemberEventContent { avatar_url: avatar_url.clone(), blurhash: blurhash.clone(), membership: MembershipState::Join, @@ -405,15 +405,15 @@ pub async fn update_avatar_url( pub async fn update_all_rooms( services: &Services, - all_joined_rooms: Vec<(PduBuilder, &OwnedRoomId)>, + all_joined_rooms: Vec<(PartialPdu, &OwnedRoomId)>, user_id: &UserId, ) { - for (pdu_builder, room_id) in all_joined_rooms { + for (partial_pdu, room_id) in all_joined_rooms { let state_lock = services.rooms.state.mutex.lock(room_id).await; if let Err(e) = services .rooms .timeline - .build_and_append_pdu(pdu_builder, user_id, Some(room_id), &state_lock) + .build_and_append_pdu(partial_pdu, user_id, Some(room_id), &state_lock) .await { warn!(%user_id, %room_id, "Failed to update/send new profile join membership update in room: {e}"); diff --git a/src/api/client/redact.rs b/src/api/client/redact.rs index 7ec7f162a..16a9d8296 100644 --- a/src/api/client/redact.rs +++ b/src/api/client/redact.rs @@ -1,6 +1,6 @@ use axum::extract::State; use axum_client_ip::ClientIp; -use conduwuit::{Err, Result, matrix::pdu::PduBuilder}; +use conduwuit::{Err, Result, matrix::pdu::PartialPdu}; use ruma::{ api::client::redact::redact_event, events::room::redaction::RoomRedactionEventContent, }; @@ -34,9 +34,9 @@ pub(crate) async fn redact_event_route( .rooms .timeline .build_and_append_pdu( - PduBuilder { + PartialPdu { redacts: Some(body.event_id.clone()), - ..PduBuilder::timeline(&RoomRedactionEventContent { + ..PartialPdu::timeline(&RoomRedactionEventContent { redacts: Some(body.event_id.clone()), reason: body.reason.clone(), }) diff --git a/src/api/client/room/create.rs b/src/api/client/room/create.rs index 4a7652b73..12cab7533 100644 --- a/src/api/client/room/create.rs +++ b/src/api/client/room/create.rs @@ -3,7 +3,7 @@ use std::collections::{BTreeMap, BTreeSet}; use axum::extract::State; use conduwuit::{ Err, Result, debug, debug_info, debug_warn, err, info, - matrix::{StateKey, pdu::PduBuilder}, + matrix::{StateKey, pdu::PartialPdu}, trace, warn, }; use conduwuit_service::{Services, appservice::RegistrationInfo}; @@ -230,7 +230,7 @@ pub(crate) async fn create_room_route( .rooms .timeline .build_and_append_pdu( - PduBuilder { + PartialPdu { event_type: TimelineEventType::RoomCreate, content: to_raw_value(&create_content)?, state_key: Some(StateKey::new()), @@ -269,7 +269,7 @@ pub(crate) async fn create_room_route( .rooms .timeline .build_and_append_pdu( - PduBuilder::state(sender_user.to_string(), &join_event), + PartialPdu::state(sender_user.to_string(), &join_event), sender_user, Some(&room_id), &state_lock, @@ -330,7 +330,7 @@ pub(crate) async fn create_room_route( .rooms .timeline .build_and_append_pdu( - PduBuilder { + PartialPdu { event_type: TimelineEventType::RoomPowerLevels, content: to_raw_value(&power_levels_content)?, state_key: Some(StateKey::new()), @@ -349,7 +349,7 @@ pub(crate) async fn create_room_route( .rooms .timeline .build_and_append_pdu( - PduBuilder::state(String::new(), &RoomCanonicalAliasEventContent { + PartialPdu::state(String::new(), &RoomCanonicalAliasEventContent { alias: Some(room_alias_id.to_owned()), alt_aliases: vec![], }), @@ -368,7 +368,7 @@ pub(crate) async fn create_room_route( .rooms .timeline .build_and_append_pdu( - PduBuilder::state( + PartialPdu::state( String::new(), &RoomJoinRulesEventContent::new(match preset { | RoomPreset::PublicChat => JoinRule::Public, @@ -388,7 +388,7 @@ pub(crate) async fn create_room_route( .rooms .timeline .build_and_append_pdu( - PduBuilder::state( + PartialPdu::state( String::new(), &RoomHistoryVisibilityEventContent::new(HistoryVisibility::Shared), ), @@ -404,7 +404,7 @@ pub(crate) async fn create_room_route( .rooms .timeline .build_and_append_pdu( - PduBuilder::state( + PartialPdu::state( String::new(), &RoomGuestAccessEventContent::new(match preset { | RoomPreset::PublicChat => GuestAccess::Forbidden, @@ -420,7 +420,7 @@ pub(crate) async fn create_room_route( // 6. Events listed in initial_state for event in &body.initial_state { - let mut pdu_builder = event.deserialize_as::().map_err(|e| { + let mut partial_pdu = event.deserialize_as::().map_err(|e| { err!(Request(InvalidParam(warn!("Invalid initial state event: {e:?}")))) })?; @@ -429,17 +429,17 @@ pub(crate) async fn create_room_route( // client/appservice workaround: if a user sends an initial_state event with a // state event in there with the content of literally `{}` (not null or empty // string), let's just skip it over and warn. - if pdu_builder.content.get().eq("{}") { + if partial_pdu.content.get().eq("{}") { debug_warn!("skipping empty initial state event with content of `{{}}`: {event:?}"); - debug_warn!("content: {}", pdu_builder.content.get()); + debug_warn!("content: {}", partial_pdu.content.get()); continue; } // Implicit state key defaults to "" - pdu_builder.state_key.get_or_insert_with(StateKey::new); + partial_pdu.state_key.get_or_insert_with(StateKey::new); // Silently skip encryption events if they are not allowed - if pdu_builder.event_type == TimelineEventType::RoomEncryption + if partial_pdu.event_type == TimelineEventType::RoomEncryption && !services.config.allow_encryption { continue; @@ -448,7 +448,7 @@ pub(crate) async fn create_room_route( services .rooms .timeline - .build_and_append_pdu(pdu_builder, sender_user, Some(&room_id), &state_lock) + .build_and_append_pdu(partial_pdu, sender_user, Some(&room_id), &state_lock) .boxed() .await?; } @@ -459,7 +459,7 @@ pub(crate) async fn create_room_route( .rooms .timeline .build_and_append_pdu( - PduBuilder::state(String::new(), &RoomNameEventContent::new(name.clone())), + PartialPdu::state(String::new(), &RoomNameEventContent::new(name.clone())), sender_user, Some(&room_id), &state_lock, @@ -473,7 +473,7 @@ pub(crate) async fn create_room_route( .rooms .timeline .build_and_append_pdu( - PduBuilder::state(String::new(), &RoomTopicEventContent { topic: topic.clone() }), + PartialPdu::state(String::new(), &RoomTopicEventContent { topic: topic.clone() }), sender_user, Some(&room_id), &state_lock, diff --git a/src/api/client/room/upgrade.rs b/src/api/client/room/upgrade.rs index 8ed73d974..7202744f4 100644 --- a/src/api/client/room/upgrade.rs +++ b/src/api/client/room/upgrade.rs @@ -3,7 +3,7 @@ use std::cmp::max; use axum::extract::State; use conduwuit::{ Err, Error, Event, Result, RoomVersion, debug, err, info, - matrix::{StateKey, pdu::PduBuilder}, + matrix::{StateKey, pdu::PartialPdu}, }; use futures::{FutureExt, StreamExt}; use ruma::{ @@ -85,7 +85,7 @@ pub(crate) async fn upgrade_room_route( .rooms .timeline .create_hash_and_sign_event( - PduBuilder::state(StateKey::new(), &RoomTombstoneEventContent { + PartialPdu::state(StateKey::new(), &RoomTombstoneEventContent { body: "This room has been replaced".to_owned(), replacement_room: RoomId::new(services.globals.server_name()), }), diff --git a/src/api/client/send.rs b/src/api/client/send.rs index 20513c0b7..28f3c416b 100644 --- a/src/api/client/send.rs +++ b/src/api/client/send.rs @@ -2,7 +2,7 @@ use std::collections::BTreeMap; use axum::extract::State; use axum_client_ip::ClientIp; -use conduwuit::{Err, Result, err, matrix::pdu::PduBuilder, utils}; +use conduwuit::{Err, Result, err, matrix::pdu::PartialPdu, utils}; use ruma::{api::client::message::send_message_event, events::MessageLikeEventType}; use serde_json::from_str; @@ -79,7 +79,7 @@ pub(crate) async fn send_message_event_route( .rooms .timeline .build_and_append_pdu( - PduBuilder { + PartialPdu { event_type: body.event_type.clone().into(), content, unsigned: Some(unsigned), diff --git a/src/api/client/state.rs b/src/api/client/state.rs index 11b1933ad..55c0d2d7e 100644 --- a/src/api/client/state.rs +++ b/src/api/client/state.rs @@ -4,7 +4,7 @@ use axum::extract::State; use axum_client_ip::ClientIp; use conduwuit::{ Err, Result, err, - matrix::{Event, pdu::PduBuilder}, + matrix::{Event, pdu::PartialPdu}, utils::BoolExt, }; use conduwuit_service::Services; @@ -204,7 +204,7 @@ async fn send_state_event_for_key_helper( .rooms .timeline .build_and_append_pdu( - PduBuilder { + PartialPdu { event_type: event_type.to_string().into(), content: serde_json::from_str(json.json().get())?, state_key: Some(state_key.into()), diff --git a/src/api/server/make_join.rs b/src/api/server/make_join.rs index 8520525af..d889cc0a4 100644 --- a/src/api/server/make_join.rs +++ b/src/api/server/make_join.rs @@ -2,7 +2,7 @@ use std::borrow::ToOwned; use axum::extract::State; use conduwuit::{ - Err, Error, Result, debug, debug_info, info, matrix::pdu::PduBuilder, utils, warn, + Err, Error, Result, debug, debug_info, info, matrix::pdu::PartialPdu, utils, warn, }; use conduwuit_service::Services; use futures::StreamExt; @@ -140,7 +140,7 @@ pub(crate) async fn create_join_event_template_route( .rooms .timeline .create_event( - PduBuilder::state(body.user_id.to_string(), &RoomMemberEventContent { + PartialPdu::state(body.user_id.to_string(), &RoomMemberEventContent { join_authorized_via_users_server, ..RoomMemberEventContent::new(MembershipState::Join) }), @@ -177,7 +177,7 @@ pub(crate) async fn select_authorising_user( .state_accessor .user_can_invite(room_id, user, user_id, state_lock) }) - .boxed() + .boPartialPdu .next() .await .map(ToOwned::to_owned); diff --git a/src/api/server/make_knock.rs b/src/api/server/make_knock.rs index 4f3003d4e..51e68a2c3 100644 --- a/src/api/server/make_knock.rs +++ b/src/api/server/make_knock.rs @@ -1,6 +1,6 @@ use RoomVersionId::*; use axum::extract::State; -use conduwuit::{Err, Error, Result, debug_warn, info, matrix::pdu::PduBuilder, utils, warn}; +use conduwuit::{Err, Error, Result, debug_warn, info, matrix::pdu::PartialPdu, utils, warn}; use ruma::{ RoomVersionId, api::{client::error::ErrorKind, federation::knock::create_knock_event_template}, @@ -103,7 +103,7 @@ pub(crate) async fn create_knock_event_template_route( .rooms .timeline .create_event( - PduBuilder::state( + PartialPdu::state( body.user_id.to_string(), &RoomMemberEventContent::new(MembershipState::Knock), ), diff --git a/src/api/server/make_leave.rs b/src/api/server/make_leave.rs index 8e046d8bd..82fa5d844 100644 --- a/src/api/server/make_leave.rs +++ b/src/api/server/make_leave.rs @@ -1,5 +1,5 @@ use axum::extract::State; -use conduwuit::{Err, Result, info, matrix::pdu::PduBuilder, utils}; +use conduwuit::{Err, Result, info, matrix::pdu::PartialPdu, utils}; use ruma::{ api::federation::membership::prepare_leave_event, events::room::member::{MembershipState, RoomMemberEventContent}, @@ -52,7 +52,7 @@ pub(crate) async fn create_leave_event_template_route( .rooms .timeline .create_event( - PduBuilder::state( + PartialPdu::state( body.user_id.to_string(), &RoomMemberEventContent::new(MembershipState::Leave), ), diff --git a/src/core/matrix/mod.rs b/src/core/matrix/mod.rs index d50247e4f..cab557411 100644 --- a/src/core/matrix/mod.rs +++ b/src/core/matrix/mod.rs @@ -7,6 +7,6 @@ pub mod state_res; pub mod versions; pub use event::{Event, TypeExt as EventTypeExt}; -pub use pdu::{Pdu, PduBuilder, PduCount, PduEvent, PduId, RawPduId, ShortId}; +pub use pdu::{PartialPdu, Pdu, PduCount, PduEvent, PduId, RawPduId, ShortId}; pub use state_key::StateKey; pub use state_res::{StateMap, TypeStateKey}; diff --git a/src/core/matrix/pdu.rs b/src/core/matrix/pdu.rs index dcde90ff9..436e1c123 100644 --- a/src/core/matrix/pdu.rs +++ b/src/core/matrix/pdu.rs @@ -1,6 +1,6 @@ -mod builder; mod count; mod id; +mod partial; mod raw_id; mod redact; #[cfg(test)] @@ -18,9 +18,9 @@ use serde_json::value::RawValue as RawJsonValue; pub use self::{ Count as PduCount, Id as PduId, Pdu as PduEvent, RawId as RawPduId, - builder::{Builder, Builder as PduBuilder}, count::Count, id::{ShortId, *}, + partial::PartialPdu, raw_id::*, }; use super::{Event, StateKey}; diff --git a/src/core/matrix/pdu/builder.rs b/src/core/matrix/pdu/partial.rs similarity index 91% rename from src/core/matrix/pdu/builder.rs rename to src/core/matrix/pdu/partial.rs index 38ba3f44f..db3010672 100644 --- a/src/core/matrix/pdu/builder.rs +++ b/src/core/matrix/pdu/partial.rs @@ -9,9 +9,9 @@ use serde_json::value::{RawValue as RawJsonValue, to_raw_value}; use super::StateKey; -/// Build the start of a PDU in order to add it to the Database. +/// An event and its associated metadata, without an ID, signatures, or hashes. #[derive(Debug, Deserialize)] -pub struct Builder { +pub struct PartialPdu { #[serde(rename = "type")] pub event_type: TimelineEventType, @@ -30,7 +30,7 @@ pub struct Builder { type Unsigned = BTreeMap; -impl Builder { +impl PartialPdu { pub fn state(state_key: S, content: &T) -> Self where T: StateEventContent, @@ -58,7 +58,7 @@ impl Builder { } } -impl Default for Builder { +impl Default for PartialPdu { fn default() -> Self { Self { event_type: "m.room.message".into(), diff --git a/src/service/admin/create.rs b/src/service/admin/create.rs index 381ed383c..6e41321ea 100644 --- a/src/service/admin/create.rs +++ b/src/service/admin/create.rs @@ -1,6 +1,6 @@ use std::collections::BTreeMap; -use conduwuit::{Result, info, pdu::PduBuilder}; +use conduwuit::{Result, info, pdu::PartialPdu}; use futures::FutureExt; use ruma::{ RoomId, RoomVersionId, @@ -58,7 +58,7 @@ pub async fn create_admin_room(services: &Services) -> Result { .rooms .timeline .build_and_append_pdu( - PduBuilder::state(String::new(), &create_content), + PartialPdu::state(String::new(), &create_content), server_user, Some(&room_id), &state_lock, @@ -71,7 +71,7 @@ pub async fn create_admin_room(services: &Services) -> Result { .rooms .timeline .build_and_append_pdu( - PduBuilder::state( + PartialPdu::state( String::from(server_user), &RoomMemberEventContent::new(MembershipState::Join), ), @@ -93,7 +93,7 @@ pub async fn create_admin_room(services: &Services) -> Result { .rooms .timeline .build_and_append_pdu( - PduBuilder::state(String::new(), &power_levels_content), + PartialPdu::state(String::new(), &power_levels_content), server_user, Some(&room_id), &state_lock, @@ -106,7 +106,7 @@ pub async fn create_admin_room(services: &Services) -> Result { .rooms .timeline .build_and_append_pdu( - PduBuilder::state(String::new(), &RoomJoinRulesEventContent::new(JoinRule::Invite)), + PartialPdu::state(String::new(), &RoomJoinRulesEventContent::new(JoinRule::Invite)), server_user, Some(&room_id), &state_lock, @@ -119,7 +119,7 @@ pub async fn create_admin_room(services: &Services) -> Result { .rooms .timeline .build_and_append_pdu( - PduBuilder::state( + PartialPdu::state( String::new(), &RoomHistoryVisibilityEventContent::new(HistoryVisibility::Shared), ), @@ -135,7 +135,7 @@ pub async fn create_admin_room(services: &Services) -> Result { .rooms .timeline .build_and_append_pdu( - PduBuilder::state( + PartialPdu::state( String::new(), &RoomGuestAccessEventContent::new(GuestAccess::Forbidden), ), @@ -152,7 +152,7 @@ pub async fn create_admin_room(services: &Services) -> Result { .rooms .timeline .build_and_append_pdu( - PduBuilder::state(String::new(), &RoomNameEventContent::new(room_name)), + PartialPdu::state(String::new(), &RoomNameEventContent::new(room_name)), server_user, Some(&room_id), &state_lock, @@ -165,7 +165,7 @@ pub async fn create_admin_room(services: &Services) -> Result { .rooms .timeline .build_and_append_pdu( - PduBuilder::state(String::new(), &RoomTopicEventContent::markdown(room_topic)), + PartialPdu::state(String::new(), &RoomTopicEventContent::markdown(room_topic)), server_user, Some(&room_id), &state_lock, @@ -181,7 +181,7 @@ pub async fn create_admin_room(services: &Services) -> Result { .rooms .timeline .build_and_append_pdu( - PduBuilder::state(String::new(), &alias_content), + PartialPdu::state(String::new(), &alias_content), server_user, Some(&room_id), &state_lock, diff --git a/src/service/admin/grant.rs b/src/service/admin/grant.rs index 1388ab73c..624c6eade 100644 --- a/src/service/admin/grant.rs +++ b/src/service/admin/grant.rs @@ -1,7 +1,7 @@ use std::collections::BTreeMap; use conduwuit::{ - Err, Result, debug_info, debug_warn, error, implement, matrix::pdu::PduBuilder, warn, + Err, Result, debug_info, debug_warn, error, implement, matrix::pdu::PartialPdu, warn, }; use ruma::{ RoomId, UserId, @@ -51,7 +51,7 @@ pub async fn make_user_admin(&self, user_id: &UserId) -> Result { self.services .timeline .build_and_append_pdu( - PduBuilder::state( + PartialPdu::state( String::from(user_id), &RoomMemberEventContent::new(MembershipState::Invite), ), @@ -65,7 +65,7 @@ pub async fn make_user_admin(&self, user_id: &UserId) -> Result { self.services .timeline .build_and_append_pdu( - PduBuilder::state( + PartialPdu::state( String::from(user_id), &RoomMemberEventContent::new(MembershipState::Join), ), @@ -79,7 +79,7 @@ pub async fn make_user_admin(&self, user_id: &UserId) -> Result { self.services .timeline .build_and_append_pdu( - PduBuilder::state( + PartialPdu::state( user_id.to_string(), &RoomMemberEventContent::new(MembershipState::Invite), ), @@ -110,7 +110,7 @@ pub async fn make_user_admin(&self, user_id: &UserId) -> Result { self.services .timeline .build_and_append_pdu( - PduBuilder::state(String::new(), &room_power_levels), + PartialPdu::state(String::new(), &room_power_levels), server_user, Some(&room_id), &state_lock, @@ -207,7 +207,7 @@ pub async fn revoke_admin(&self, user_id: &UserId) -> Result { self.services .timeline .build_and_append_pdu( - PduBuilder::state(user_id.to_string(), &member_content), + PartialPdu::state(user_id.to_string(), &member_content), self.services.globals.server_user.as_ref(), Some(&room_id), &state_lock, diff --git a/src/service/admin/mod.rs b/src/service/admin/mod.rs index d91fca5bb..93bda513d 100644 --- a/src/service/admin/mod.rs +++ b/src/service/admin/mod.rs @@ -11,7 +11,7 @@ use std::{ use async_trait::async_trait; use conduwuit::{Err, SyncRwLock, utils}; use conduwuit_core::{ - Error, Event, Result, Server, debug, err, error, error::default_log, pdu::PduBuilder, + Error, Event, Result, Server, debug, err, error, error::default_log, pdu::PartialPdu, }; pub use create::create_admin_room; use futures::{Future, FutureExt, StreamExt, TryFutureExt}; @@ -493,7 +493,7 @@ impl Service { .services .timeline .build_and_append_pdu( - PduBuilder::timeline(&self.text_or_file(content).await), + PartialPdu::timeline(&self.text_or_file(content).await), user_id, Some(room_id), &state_lock, @@ -525,7 +525,7 @@ impl Service { self.services .timeline .build_and_append_pdu( - PduBuilder::timeline(&content), + PartialPdu::timeline(&content), user_id, Some(room_id), state_lock, diff --git a/src/service/rooms/state_accessor/user_can.rs b/src/service/rooms/state_accessor/user_can.rs index 84eef869f..9ff601360 100644 --- a/src/service/rooms/state_accessor/user_can.rs +++ b/src/service/rooms/state_accessor/user_can.rs @@ -1,4 +1,4 @@ -use conduwuit::{Err, Result, implement, matrix::Event, pdu::PduBuilder}; +use conduwuit::{Err, Result, implement, matrix::Event, pdu::PartialPdu}; use ruma::{ EventId, RoomId, UserId, events::{ diff --git a/src/service/rooms/timeline/build.rs b/src/service/rooms/timeline/build.rs index 11dd8ac80..85f1f88d9 100644 --- a/src/service/rooms/timeline/build.rs +++ b/src/service/rooms/timeline/build.rs @@ -3,7 +3,7 @@ use std::{collections::HashSet, iter::once}; use conduwuit::trace; use conduwuit_core::{ Err, Result, implement, - matrix::{event::Event, pdu::PduBuilder}, + matrix::{event::Event, pdu::PartialPdu}, utils::{IterStream, ReadyExt}, }; use futures::{FutureExt, StreamExt}; @@ -24,16 +24,16 @@ use super::{ExtractBody, RoomMutexGuard}; /// takes a roomid_mutex_state, meaning that only this function is able to /// mutate the room state. #[implement(super::Service)] -#[tracing::instrument(skip(self, state_lock, pdu_builder), level = "trace")] +#[tracing::instrument(skip(self, state_lock, partial_pdu), level = "trace")] pub async fn build_and_append_pdu( &self, - pdu_builder: PduBuilder, + partial_pdu: PartialPdu, sender: &UserId, room_id: Option<&RoomId>, state_lock: &RoomMutexGuard, ) -> Result { let (pdu, pdu_json) = self - .create_hash_and_sign_event(pdu_builder, sender, room_id, state_lock) + .create_hash_and_sign_event(partial_pdu, sender, room_id, state_lock) .await?; let room_id = pdu.room_id_or_hash(); diff --git a/src/service/rooms/timeline/create.rs b/src/service/rooms/timeline/create.rs index 5869b9a36..581c40a14 100644 --- a/src/service/rooms/timeline/create.rs +++ b/src/service/rooms/timeline/create.rs @@ -5,7 +5,7 @@ use conduwuit_core::{ Err, Error, Result, err, implement, matrix::{ event::{Event, gen_event_id}, - pdu::{EventHash, PduBuilder, PduEvent}, + pdu::{EventHash, PartialPdu, PduEvent}, state_res, }, utils::{self, IterStream, ReadyExt, stream::TryIgnore}, @@ -76,19 +76,19 @@ fn room_version_from_event( #[implement(super::Service)] pub async fn create_event( &self, - pdu_builder: PduBuilder, + partial_pdu: PartialPdu, sender: &UserId, room_id: Option<&RoomId>, _mutex_lock: &RoomMutexGuard, ) -> Result<(PduEvent, RoomVersionId)> { - let PduBuilder { + let PartialPdu { event_type, content, unsigned, state_key, redacts, timestamp, - } = pdu_builder; + } = partial_pdu; trace!( "Creating event of type {} in room {}",