mirror of
https://forgejo.ellis.link/continuwuation/continuwuity.git
synced 2025-09-12 17:33:57 +02:00
feat(hydra): Initial public commit for v12 support
# Conflicts: # src/core/info/room_version.rs # src/service/rooms/timeline/create.rs # Conflicts: # Cargo.lock # src/core/matrix/state_res/event_auth.rs
This commit is contained in:
parent
9c147b182f
commit
a7944a5e58
57 changed files with 951 additions and 386 deletions
|
@ -929,7 +929,7 @@ pub async fn full_user_deactivate(
|
|||
.build_and_append_pdu(
|
||||
PduBuilder::state(String::new(), &power_levels_content),
|
||||
user_id,
|
||||
room_id,
|
||||
Some(room_id),
|
||||
&state_lock,
|
||||
)
|
||||
.await
|
||||
|
|
|
@ -69,7 +69,7 @@ pub(crate) async fn get_context_route(
|
|||
|
||||
let (base_id, base_pdu, visible) = try_join3(base_id, base_pdu, visible).await?;
|
||||
|
||||
if base_pdu.room_id != *room_id || base_pdu.event_id != *event_id {
|
||||
if base_pdu.room_id_or_hash() != *room_id || base_pdu.event_id != *event_id {
|
||||
return Err!(Request(NotFound("Base event not found.")));
|
||||
}
|
||||
|
||||
|
|
|
@ -49,7 +49,7 @@ pub(crate) async fn ban_user_route(
|
|||
..current_member_content
|
||||
}),
|
||||
sender_user,
|
||||
&body.room_id,
|
||||
Some(&body.room_id),
|
||||
&state_lock,
|
||||
)
|
||||
.await?;
|
||||
|
|
|
@ -128,12 +128,12 @@ pub(crate) async fn invite_helper(
|
|||
.create_hash_and_sign_event(
|
||||
PduBuilder::state(user_id.to_string(), &content),
|
||||
sender_user,
|
||||
room_id,
|
||||
Some(room_id),
|
||||
&state_lock,
|
||||
)
|
||||
.await?;
|
||||
|
||||
let invite_room_state = services.rooms.state.summary_stripped(&pdu).await;
|
||||
let invite_room_state = services.rooms.state.summary_stripped(&pdu, room_id).await;
|
||||
|
||||
drop(state_lock);
|
||||
|
||||
|
@ -227,7 +227,7 @@ pub(crate) async fn invite_helper(
|
|||
.build_and_append_pdu(
|
||||
PduBuilder::state(user_id.to_string(), &content),
|
||||
sender_user,
|
||||
room_id,
|
||||
Some(room_id),
|
||||
&state_lock,
|
||||
)
|
||||
.await?;
|
||||
|
|
|
@ -18,7 +18,7 @@ use conduwuit::{
|
|||
},
|
||||
warn,
|
||||
};
|
||||
use futures::{FutureExt, StreamExt};
|
||||
use futures::{FutureExt, StreamExt, TryFutureExt};
|
||||
use ruma::{
|
||||
CanonicalJsonObject, CanonicalJsonValue, OwnedRoomId, OwnedServerName, OwnedUserId, RoomId,
|
||||
RoomVersionId, UserId,
|
||||
|
@ -553,12 +553,20 @@ async fn join_room_by_id_helper_remote(
|
|||
.iter()
|
||||
.stream()
|
||||
.then(|pdu| {
|
||||
debug!(?pdu, "Validating send_join response room_state event");
|
||||
services
|
||||
.server_keys
|
||||
.validate_and_add_event_id_no_fetch(pdu, &room_version_id)
|
||||
.inspect_err(|e| {
|
||||
debug_warn!(
|
||||
"Could not validate send_join response room_state event: {e:?}"
|
||||
);
|
||||
})
|
||||
.inspect(|_| debug!("Completed validating send_join response room_state event"))
|
||||
})
|
||||
.ready_filter_map(Result::ok)
|
||||
.fold(HashMap::new(), |mut state, (event_id, value)| async move {
|
||||
debug!(?event_id, "Processing send_join response room_state event");
|
||||
let pdu = match PduEvent::from_id_val(&event_id, value.clone()) {
|
||||
| Ok(pdu) => pdu,
|
||||
| Err(e) => {
|
||||
|
@ -566,9 +574,10 @@ async fn join_room_by_id_helper_remote(
|
|||
return state;
|
||||
},
|
||||
};
|
||||
|
||||
debug!(event_id = ?event_id.clone(), "Adding PDU outlier for send_join response room_state event");
|
||||
services.rooms.outlier.add_pdu_outlier(&event_id, &value);
|
||||
if let Some(state_key) = &pdu.state_key {
|
||||
debug!(?state_key, "Creating shortstatekey for state event in send_join response");
|
||||
let shortstatekey = services
|
||||
.rooms
|
||||
.short
|
||||
|
@ -577,7 +586,7 @@ async fn join_room_by_id_helper_remote(
|
|||
|
||||
state.insert(shortstatekey, pdu.event_id.clone());
|
||||
}
|
||||
|
||||
debug!("Completed send_join response");
|
||||
state
|
||||
})
|
||||
.await;
|
||||
|
@ -618,6 +627,9 @@ async fn join_room_by_id_helper_remote(
|
|||
&parsed_join_pdu,
|
||||
None, // TODO: third party invite
|
||||
|k, s| state_fetch(k.clone(), s.into()),
|
||||
&state_fetch(StateEventType::RoomCreate, "".into())
|
||||
.await
|
||||
.expect("create event is missing from send_join auth"),
|
||||
)
|
||||
.await
|
||||
.map_err(|e| err!(Request(Forbidden(warn!("Auth check failed: {e:?}")))))?;
|
||||
|
@ -665,7 +677,7 @@ async fn join_room_by_id_helper_remote(
|
|||
let statehash_after_join = services
|
||||
.rooms
|
||||
.state
|
||||
.append_to_state(&parsed_join_pdu)
|
||||
.append_to_state(&parsed_join_pdu, room_id)
|
||||
.await?;
|
||||
|
||||
info!("Appending new room join event");
|
||||
|
@ -677,6 +689,7 @@ async fn join_room_by_id_helper_remote(
|
|||
join_event,
|
||||
once(parsed_join_pdu.event_id.borrow()),
|
||||
&state_lock,
|
||||
room_id,
|
||||
)
|
||||
.await?;
|
||||
|
||||
|
@ -776,7 +789,7 @@ async fn join_room_by_id_helper_local(
|
|||
.build_and_append_pdu(
|
||||
PduBuilder::state(sender_user.to_string(), &content),
|
||||
sender_user,
|
||||
room_id,
|
||||
Some(room_id),
|
||||
&state_lock,
|
||||
)
|
||||
.await
|
||||
|
|
|
@ -54,7 +54,7 @@ pub(crate) async fn kick_user_route(
|
|||
..event
|
||||
}),
|
||||
sender_user,
|
||||
&body.room_id,
|
||||
Some(&body.room_id),
|
||||
&state_lock,
|
||||
)
|
||||
.await?;
|
||||
|
|
|
@ -373,7 +373,7 @@ async fn knock_room_helper_local(
|
|||
.build_and_append_pdu(
|
||||
PduBuilder::state(sender_user.to_string(), &content),
|
||||
sender_user,
|
||||
room_id,
|
||||
Some(room_id),
|
||||
&state_lock,
|
||||
)
|
||||
.await
|
||||
|
@ -502,6 +502,7 @@ async fn knock_room_helper_local(
|
|||
knock_event,
|
||||
once(parsed_knock_pdu.event_id.borrow()),
|
||||
&state_lock,
|
||||
room_id,
|
||||
)
|
||||
.await?;
|
||||
|
||||
|
@ -672,7 +673,7 @@ async fn knock_room_helper_remote(
|
|||
let statehash_after_knock = services
|
||||
.rooms
|
||||
.state
|
||||
.append_to_state(&parsed_knock_pdu)
|
||||
.append_to_state(&parsed_knock_pdu, room_id)
|
||||
.await?;
|
||||
|
||||
info!("Updating membership locally to knock state with provided stripped state events");
|
||||
|
@ -701,6 +702,7 @@ async fn knock_room_helper_remote(
|
|||
knock_event,
|
||||
once(parsed_knock_pdu.event_id.borrow()),
|
||||
&state_lock,
|
||||
room_id,
|
||||
)
|
||||
.await?;
|
||||
|
||||
|
|
|
@ -206,7 +206,7 @@ pub async fn leave_room(
|
|||
..event
|
||||
}),
|
||||
user_id,
|
||||
room_id,
|
||||
Some(room_id),
|
||||
&state_lock,
|
||||
)
|
||||
.await?;
|
||||
|
|
|
@ -70,9 +70,10 @@ pub(crate) async fn banned_room_check(
|
|||
|
||||
if let Some(room_id) = room_id {
|
||||
if services.rooms.metadata.is_banned(room_id).await
|
||||
|| services
|
||||
.moderation
|
||||
.is_remote_server_forbidden(room_id.server_name().expect("legacy room mxid"))
|
||||
|| (room_id.server_name().is_some()
|
||||
&& services
|
||||
.moderation
|
||||
.is_remote_server_forbidden(room_id.server_name().expect("legacy room mxid")))
|
||||
{
|
||||
warn!(
|
||||
"User {user_id} who is not an admin attempted to send an invite for or \
|
||||
|
|
|
@ -47,7 +47,7 @@ pub(crate) async fn unban_user_route(
|
|||
..current_member_content
|
||||
}),
|
||||
sender_user,
|
||||
&body.room_id,
|
||||
Some(&body.room_id),
|
||||
&state_lock,
|
||||
)
|
||||
.await?;
|
||||
|
|
|
@ -309,7 +309,7 @@ pub(crate) async fn visibility_filter(
|
|||
services
|
||||
.rooms
|
||||
.state_accessor
|
||||
.user_can_see_event(user_id, pdu.room_id(), pdu.event_id())
|
||||
.user_can_see_event(user_id, &pdu.room_id_or_hash(), pdu.event_id())
|
||||
.await
|
||||
.then_some(item)
|
||||
}
|
||||
|
|
|
@ -423,7 +423,7 @@ pub async fn update_all_rooms(
|
|||
if let Err(e) = services
|
||||
.rooms
|
||||
.timeline
|
||||
.build_and_append_pdu(pdu_builder, user_id, room_id, &state_lock)
|
||||
.build_and_append_pdu(pdu_builder, 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}");
|
||||
|
|
|
@ -36,7 +36,7 @@ pub(crate) async fn redact_event_route(
|
|||
})
|
||||
},
|
||||
sender_user,
|
||||
&body.room_id,
|
||||
Some(&body.room_id),
|
||||
&state_lock,
|
||||
)
|
||||
.await?;
|
||||
|
|
|
@ -222,7 +222,7 @@ async fn visibility_filter<Pdu: Event + Send + Sync>(
|
|||
services
|
||||
.rooms
|
||||
.state_accessor
|
||||
.user_can_see_event(sender_user, pdu.room_id(), pdu.event_id())
|
||||
.user_can_see_event(sender_user, &pdu.room_id_or_hash(), pdu.event_id())
|
||||
.await
|
||||
.then_some(item)
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@ use std::{fmt::Write as _, time::Duration};
|
|||
|
||||
use axum::extract::State;
|
||||
use axum_client_ip::InsecureClientIp;
|
||||
use conduwuit::{Err, Result, debug_info, info, matrix::pdu::PduEvent, utils::ReadyExt};
|
||||
use conduwuit::{Err, Event, Result, debug_info, info, matrix::pdu::PduEvent, utils::ReadyExt};
|
||||
use conduwuit_service::Services;
|
||||
use rand::Rng;
|
||||
use ruma::{
|
||||
|
@ -197,7 +197,7 @@ async fn is_event_report_valid(
|
|||
valid"
|
||||
);
|
||||
|
||||
if room_id != pdu.room_id {
|
||||
if room_id != &pdu.room_id_or_hash() {
|
||||
return Err!(Request(NotFound("Event ID does not belong to the reported room",)));
|
||||
}
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@ use std::collections::BTreeMap;
|
|||
|
||||
use axum::extract::State;
|
||||
use conduwuit::{
|
||||
Err, Result, debug_info, debug_warn, err, info,
|
||||
Err, Result, RoomVersion, debug, debug_info, debug_warn, err, info,
|
||||
matrix::{StateKey, pdu::PduBuilder},
|
||||
warn,
|
||||
};
|
||||
|
@ -68,51 +68,6 @@ pub(crate) async fn create_room_route(
|
|||
return Err!(Request(UserSuspended("You cannot perform this action while suspended.")));
|
||||
}
|
||||
|
||||
let room_id: OwnedRoomId = match &body.room_id {
|
||||
| Some(custom_room_id) => custom_room_id_check(&services, custom_room_id)?,
|
||||
| _ => RoomId::new(&services.server.name),
|
||||
};
|
||||
|
||||
// check if room ID doesn't already exist instead of erroring on auth check
|
||||
if services.rooms.short.get_shortroomid(&room_id).await.is_ok() {
|
||||
return Err!(Request(RoomInUse("Room with that custom room ID already exists",)));
|
||||
}
|
||||
|
||||
if body.visibility == room::Visibility::Public
|
||||
&& services.server.config.lockdown_public_room_directory
|
||||
&& !services.users.is_admin(sender_user).await
|
||||
&& body.appservice_info.is_none()
|
||||
{
|
||||
warn!(
|
||||
"Non-admin user {sender_user} tried to publish {room_id} to the room directory \
|
||||
while \"lockdown_public_room_directory\" is enabled"
|
||||
);
|
||||
|
||||
if services.server.config.admin_room_notices {
|
||||
services
|
||||
.admin
|
||||
.notice(&format!(
|
||||
"Non-admin user {sender_user} tried to publish {room_id} to the room \
|
||||
directory while \"lockdown_public_room_directory\" is enabled"
|
||||
))
|
||||
.await;
|
||||
}
|
||||
|
||||
return Err!(Request(Forbidden("Publishing rooms to the room directory is not allowed")));
|
||||
}
|
||||
let _short_id = services
|
||||
.rooms
|
||||
.short
|
||||
.get_or_create_shortroomid(&room_id)
|
||||
.await;
|
||||
let state_lock = services.rooms.state.mutex.lock(&room_id).await;
|
||||
|
||||
let alias: Option<OwnedRoomAliasId> = match body.room_alias_name.as_ref() {
|
||||
| Some(alias) =>
|
||||
Some(room_alias_check(&services, alias, body.appservice_info.as_ref()).await?),
|
||||
| _ => None,
|
||||
};
|
||||
|
||||
let room_version = match body.room_version.clone() {
|
||||
| Some(room_version) =>
|
||||
if services.server.supported_room_version(&room_version) {
|
||||
|
@ -124,6 +79,51 @@ pub(crate) async fn create_room_route(
|
|||
},
|
||||
| None => services.server.config.default_room_version.clone(),
|
||||
};
|
||||
let room_features = RoomVersion::new(&room_version)?;
|
||||
|
||||
let room_id: Option<OwnedRoomId> = match room_features.room_ids_as_hashes {
|
||||
| true => None,
|
||||
| false => match &body.room_id {
|
||||
| Some(custom_room_id) => Some(custom_room_id_check(&services, custom_room_id)?),
|
||||
| None => Some(RoomId::new(services.globals.server_name())),
|
||||
},
|
||||
};
|
||||
|
||||
// check if room ID doesn't already exist instead of erroring on auth check
|
||||
if let Some(ref room_id) = room_id {
|
||||
if services.rooms.short.get_shortroomid(&room_id).await.is_ok() {
|
||||
return Err!(Request(RoomInUse("Room with that custom room ID already exists",)));
|
||||
}
|
||||
}
|
||||
|
||||
if body.visibility == room::Visibility::Public
|
||||
&& services.server.config.lockdown_public_room_directory
|
||||
&& !services.users.is_admin(sender_user).await
|
||||
&& body.appservice_info.is_none()
|
||||
{
|
||||
warn!(
|
||||
"Non-admin user {sender_user} tried to publish {room_id:?} to the room directory \
|
||||
while \"lockdown_public_room_directory\" is enabled"
|
||||
);
|
||||
|
||||
if services.server.config.admin_room_notices {
|
||||
services
|
||||
.admin
|
||||
.notice(&format!(
|
||||
"Non-admin user {sender_user} tried to publish {room_id:?} to the room \
|
||||
directory while \"lockdown_public_room_directory\" is enabled"
|
||||
))
|
||||
.await;
|
||||
}
|
||||
|
||||
return Err!(Request(Forbidden("Publishing rooms to the room directory is not allowed")));
|
||||
}
|
||||
|
||||
let alias: Option<OwnedRoomAliasId> = match body.room_alias_name.as_ref() {
|
||||
| Some(alias) =>
|
||||
Some(room_alias_check(&services, alias, body.appservice_info.as_ref()).await?),
|
||||
| _ => None,
|
||||
};
|
||||
|
||||
let create_content = match &body.creation_content {
|
||||
| Some(content) => {
|
||||
|
@ -156,6 +156,10 @@ pub(crate) async fn create_room_route(
|
|||
.try_into()
|
||||
.map_err(|e| err!(Request(BadJson("Invalid creation content: {e}"))))?,
|
||||
);
|
||||
if room_version == V12 {
|
||||
// TODO(hydra): v12 rooms cannot be federated until they are stable.
|
||||
content.insert("m.federate".into(), false.into());
|
||||
}
|
||||
content
|
||||
},
|
||||
| None => {
|
||||
|
@ -164,18 +168,32 @@ pub(crate) async fn create_room_route(
|
|||
let content = match room_version {
|
||||
| V1 | V2 | V3 | V4 | V5 | V6 | V7 | V8 | V9 | V10 =>
|
||||
RoomCreateEventContent::new_v1(sender_user.to_owned()),
|
||||
| _ => RoomCreateEventContent::new_v11(),
|
||||
| V11 => RoomCreateEventContent::new_v11(),
|
||||
| _ => RoomCreateEventContent::new_v12(),
|
||||
};
|
||||
let mut content =
|
||||
serde_json::from_str::<CanonicalJsonObject>(to_raw_value(&content)?.get())
|
||||
.unwrap();
|
||||
serde_json::from_str::<CanonicalJsonObject>(to_raw_value(&content)?.get())?;
|
||||
content.insert("room_version".into(), json!(room_version.as_str()).try_into()?);
|
||||
if room_version == V12 {
|
||||
// TODO(hydra): v12 rooms cannot be federated until they are stable.
|
||||
content.insert("m.federate".into(), false.into());
|
||||
}
|
||||
content
|
||||
},
|
||||
};
|
||||
|
||||
let state_lock = match room_id.clone() {
|
||||
| Some(room_id) => services.rooms.state.mutex.lock(&room_id).await,
|
||||
| None => {
|
||||
let temp_room_id = RoomId::new(services.globals.server_name());
|
||||
debug_info!("Locking temporary room state mutex for {temp_room_id}");
|
||||
services.rooms.state.mutex.lock(&temp_room_id).await
|
||||
},
|
||||
};
|
||||
|
||||
// 1. The room create event
|
||||
services
|
||||
debug!("Creating room create event for {sender_user} in room {room_id:?}");
|
||||
let create_event_id = services
|
||||
.rooms
|
||||
.timeline
|
||||
.build_and_append_pdu(
|
||||
|
@ -186,13 +204,26 @@ pub(crate) async fn create_room_route(
|
|||
..Default::default()
|
||||
},
|
||||
sender_user,
|
||||
&room_id,
|
||||
None,
|
||||
&state_lock,
|
||||
)
|
||||
.boxed()
|
||||
.await?;
|
||||
debug!("Created room create event with ID {}", create_event_id);
|
||||
let room_id = match room_id {
|
||||
| Some(room_id) => room_id,
|
||||
| None => {
|
||||
let as_room_id = create_event_id.as_str().replace('$', "!");
|
||||
debug_info!("Creating room with v12 room ID {as_room_id}");
|
||||
RoomId::parse(&as_room_id)?.to_owned()
|
||||
},
|
||||
};
|
||||
drop(state_lock);
|
||||
debug!("Room created with ID {room_id}");
|
||||
let state_lock = services.rooms.state.mutex.lock(&room_id).await;
|
||||
|
||||
// 2. Let the room creator join
|
||||
debug_info!("Joining {sender_user} to room {room_id}");
|
||||
services
|
||||
.rooms
|
||||
.timeline
|
||||
|
@ -205,7 +236,7 @@ pub(crate) async fn create_room_route(
|
|||
..RoomMemberEventContent::new(MembershipState::Join)
|
||||
}),
|
||||
sender_user,
|
||||
&room_id,
|
||||
Some(&room_id),
|
||||
&state_lock,
|
||||
)
|
||||
.boxed()
|
||||
|
@ -235,10 +266,28 @@ pub(crate) async fn create_room_route(
|
|||
}
|
||||
}
|
||||
|
||||
let mut creators: Vec<OwnedUserId> = vec![sender_user.to_owned()];
|
||||
if let Some(additional_creators) = create_content.get("additional_creators") {
|
||||
if let Some(additional_creators) = additional_creators.as_array() {
|
||||
for creator in additional_creators {
|
||||
if let Some(creator) = creator.as_str() {
|
||||
if let Ok(creator) = OwnedUserId::parse(creator) {
|
||||
creators.push(creator.clone());
|
||||
users.insert(creator.clone(), int!(100));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if !(RoomVersion::new(&room_version)?).explicitly_privilege_room_creators {
|
||||
creators.clear();
|
||||
}
|
||||
|
||||
let power_levels_content = default_power_levels_content(
|
||||
body.power_level_content_override.as_ref(),
|
||||
&body.visibility,
|
||||
users,
|
||||
creators,
|
||||
)?;
|
||||
|
||||
services
|
||||
|
@ -252,7 +301,7 @@ pub(crate) async fn create_room_route(
|
|||
..Default::default()
|
||||
},
|
||||
sender_user,
|
||||
&room_id,
|
||||
Some(&room_id),
|
||||
&state_lock,
|
||||
)
|
||||
.boxed()
|
||||
|
@ -269,7 +318,7 @@ pub(crate) async fn create_room_route(
|
|||
alt_aliases: vec![],
|
||||
}),
|
||||
sender_user,
|
||||
&room_id,
|
||||
Some(&room_id),
|
||||
&state_lock,
|
||||
)
|
||||
.boxed()
|
||||
|
@ -292,7 +341,7 @@ pub(crate) async fn create_room_route(
|
|||
}),
|
||||
),
|
||||
sender_user,
|
||||
&room_id,
|
||||
Some(&room_id),
|
||||
&state_lock,
|
||||
)
|
||||
.boxed()
|
||||
|
@ -308,7 +357,7 @@ pub(crate) async fn create_room_route(
|
|||
&RoomHistoryVisibilityEventContent::new(HistoryVisibility::Shared),
|
||||
),
|
||||
sender_user,
|
||||
&room_id,
|
||||
Some(&room_id),
|
||||
&state_lock,
|
||||
)
|
||||
.boxed()
|
||||
|
@ -327,7 +376,7 @@ pub(crate) async fn create_room_route(
|
|||
}),
|
||||
),
|
||||
sender_user,
|
||||
&room_id,
|
||||
Some(&room_id),
|
||||
&state_lock,
|
||||
)
|
||||
.boxed()
|
||||
|
@ -363,7 +412,7 @@ pub(crate) async fn create_room_route(
|
|||
services
|
||||
.rooms
|
||||
.timeline
|
||||
.build_and_append_pdu(pdu_builder, sender_user, &room_id, &state_lock)
|
||||
.build_and_append_pdu(pdu_builder, sender_user, Some(&room_id), &state_lock)
|
||||
.boxed()
|
||||
.await?;
|
||||
}
|
||||
|
@ -376,7 +425,7 @@ pub(crate) async fn create_room_route(
|
|||
.build_and_append_pdu(
|
||||
PduBuilder::state(String::new(), &RoomNameEventContent::new(name.clone())),
|
||||
sender_user,
|
||||
&room_id,
|
||||
Some(&room_id),
|
||||
&state_lock,
|
||||
)
|
||||
.boxed()
|
||||
|
@ -390,7 +439,7 @@ pub(crate) async fn create_room_route(
|
|||
.build_and_append_pdu(
|
||||
PduBuilder::state(String::new(), &RoomTopicEventContent { topic: topic.clone() }),
|
||||
sender_user,
|
||||
&room_id,
|
||||
Some(&room_id),
|
||||
&state_lock,
|
||||
)
|
||||
.boxed()
|
||||
|
@ -450,6 +499,7 @@ fn default_power_levels_content(
|
|||
power_level_content_override: Option<&Raw<RoomPowerLevelsEventContent>>,
|
||||
visibility: &room::Visibility,
|
||||
users: BTreeMap<OwnedUserId, Int>,
|
||||
creators: Vec<OwnedUserId>,
|
||||
) -> Result<serde_json::Value> {
|
||||
let mut power_levels_content =
|
||||
serde_json::to_value(RoomPowerLevelsEventContent { users, ..Default::default() })
|
||||
|
@ -499,6 +549,19 @@ fn default_power_levels_content(
|
|||
}
|
||||
}
|
||||
|
||||
if !creators.is_empty() {
|
||||
// Raise the default power level of tombstone to 150
|
||||
power_levels_content["events"]["m.room.tombstone"] =
|
||||
serde_json::to_value(150).expect("150 is valid Value");
|
||||
for creator in creators {
|
||||
// Omit creators from the power level list altogether
|
||||
power_levels_content["users"]
|
||||
.as_object_mut()
|
||||
.expect("users is an object")
|
||||
.remove(creator.as_str());
|
||||
}
|
||||
}
|
||||
|
||||
Ok(power_levels_content)
|
||||
}
|
||||
|
||||
|
|
|
@ -91,7 +91,7 @@ pub(crate) async fn upgrade_room_route(
|
|||
replacement_room: replacement_room.clone(),
|
||||
}),
|
||||
sender_user,
|
||||
&body.room_id,
|
||||
Some(&body.room_id),
|
||||
&state_lock,
|
||||
)
|
||||
.await?;
|
||||
|
@ -173,7 +173,7 @@ pub(crate) async fn upgrade_room_route(
|
|||
timestamp: None,
|
||||
},
|
||||
sender_user,
|
||||
&replacement_room,
|
||||
Some(&replacement_room),
|
||||
&state_lock,
|
||||
)
|
||||
.boxed()
|
||||
|
@ -204,7 +204,7 @@ pub(crate) async fn upgrade_room_route(
|
|||
timestamp: None,
|
||||
},
|
||||
sender_user,
|
||||
&replacement_room,
|
||||
Some(&replacement_room),
|
||||
&state_lock,
|
||||
)
|
||||
.boxed()
|
||||
|
@ -243,7 +243,7 @@ pub(crate) async fn upgrade_room_route(
|
|||
..Default::default()
|
||||
},
|
||||
sender_user,
|
||||
&replacement_room,
|
||||
Some(&replacement_room),
|
||||
&state_lock,
|
||||
)
|
||||
.boxed()
|
||||
|
@ -302,7 +302,7 @@ pub(crate) async fn upgrade_room_route(
|
|||
..power_levels_event_content
|
||||
}),
|
||||
sender_user,
|
||||
&body.room_id,
|
||||
Some(&body.room_id),
|
||||
&state_lock,
|
||||
)
|
||||
.boxed()
|
||||
|
@ -352,7 +352,7 @@ pub(crate) async fn upgrade_room_route(
|
|||
..Default::default()
|
||||
},
|
||||
sender_user,
|
||||
space_id,
|
||||
Some(space_id),
|
||||
&state_lock,
|
||||
)
|
||||
.boxed()
|
||||
|
@ -376,7 +376,7 @@ pub(crate) async fn upgrade_room_route(
|
|||
..Default::default()
|
||||
},
|
||||
sender_user,
|
||||
space_id,
|
||||
Some(space_id),
|
||||
&state_lock,
|
||||
)
|
||||
.boxed()
|
||||
|
|
|
@ -80,7 +80,7 @@ pub(crate) async fn send_message_event_route(
|
|||
..Default::default()
|
||||
},
|
||||
sender_user,
|
||||
&body.room_id,
|
||||
Some(&body.room_id),
|
||||
&state_lock,
|
||||
)
|
||||
.await?;
|
||||
|
|
|
@ -201,7 +201,7 @@ async fn send_state_event_for_key_helper(
|
|||
..Default::default()
|
||||
},
|
||||
sender,
|
||||
room_id,
|
||||
Some(room_id),
|
||||
&state_lock,
|
||||
)
|
||||
.await?;
|
||||
|
|
|
@ -457,7 +457,7 @@ async fn handle_left_room(
|
|||
state_key: Some(sender_user.as_str().into()),
|
||||
unsigned: None,
|
||||
// The following keys are dropped on conversion
|
||||
room_id: room_id.clone(),
|
||||
room_id: Some(room_id.clone()),
|
||||
prev_events: vec![],
|
||||
depth: uint!(1),
|
||||
auth_events: vec![],
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue