Merge branch 'leave-room-reason' into 'main'

Draft: do not ignore reason for leaving remote rooms

Closes #107

See merge request matrix/grapevine!182
This commit is contained in:
mikoto 2025-09-22 13:29:34 +00:00
commit c2bd5b0200

View file

@ -1559,7 +1559,7 @@ pub(crate) async fn leave_room(
)
.await?;
} 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");
// Don't tell the client about this error
}
@ -1588,7 +1588,11 @@ pub(crate) async fn leave_room(
}
#[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(
"No server available to assist in leaving.",
));
@ -1657,6 +1661,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?
leave_event_stub.insert(
"origin".to_owned(),