do not ignore reason for leaving remote rooms

This commit is contained in:
avdb13 2025-04-20 08:06:35 +00:00
parent 1529d60a6a
commit a93d32e9f2

View file

@ -1556,7 +1556,7 @@ pub(crate) async fn leave_room(
) )
.await?; .await?;
} else { } else {
if let Err(error) = remote_leave_room(user_id, room_id).await { if let Err(error) = remote_leave_room(user_id, room_id, reason).await {
warn!(%error, "Failed to leave room remotely"); warn!(%error, "Failed to leave room remotely");
// Don't tell the client about this error // Don't tell the client about this error
} }
@ -1585,7 +1585,11 @@ pub(crate) async fn leave_room(
} }
#[allow(clippy::too_many_lines)] #[allow(clippy::too_many_lines)]
async fn remote_leave_room(user_id: &UserId, room_id: &RoomId) -> Result<()> { async fn remote_leave_room(
user_id: &UserId,
room_id: &RoomId,
reason: Option<String>,
) -> Result<()> {
let mut make_leave_response_and_server = Err(Error::BadServerResponse( let mut make_leave_response_and_server = Err(Error::BadServerResponse(
"No server available to assist in leaving.", "No server available to assist in leaving.",
)); ));
@ -1651,6 +1655,17 @@ async fn remote_leave_room(user_id: &UserId, room_id: &RoomId) -> Result<()> {
) )
})?; })?;
if let Some(reason) = reason {
if let Some(CanonicalJsonValue::Object(content)) =
leave_event_stub.get_mut("content")
{
content.insert(
"reason".to_owned(),
CanonicalJsonValue::String(reason),
);
}
}
// TODO: Is origin needed? // TODO: Is origin needed?
leave_event_stub.insert( leave_event_stub.insert(
"origin".to_owned(), "origin".to_owned(),