1
0
Fork 0
mirror of https://gitlab.com/famedly/conduit.git synced 2025-08-11 17:50:59 +00:00

feat(client-api): support format query parameter for GET /state/

This commit is contained in:
Matthias Ahouansou 2025-07-24 12:16:03 +01:00
parent 8170b4ff14
commit bc5145f092
No known key found for this signature in database

View file

@ -4,7 +4,10 @@ use crate::{service::pdu::PduBuilder, services, Error, Result, Ruma, RumaRespons
use ruma::{
api::client::{
error::ErrorKind,
state::{get_state_event_for_key, get_state_events, send_state_event},
state::{
get_state_event_for_key::{self, v3::StateEventFormat},
get_state_events, send_state_event,
},
},
events::{
room::canonical_alias::RoomCanonicalAliasEventContent, AnyStateEventContent, StateEventType,
@ -148,10 +151,14 @@ pub async fn get_state_event_for_key_route(
Error::BadRequest(ErrorKind::NotFound, "State event not found.")
})?;
Ok(get_state_event_for_key::v3::Response {
event_or_content: serde_json::from_str(event.content.get())
.map_err(|_| Error::bad_database("Invalid event content in database"))?,
})
let response: get_state_event_for_key::v3::Response = match body.format {
StateEventFormat::Content => {
Raw::<AnyStateEventContent>::from_json(event.content.clone()).into()
}
StateEventFormat::Event => event.to_state_event().into(),
};
Ok(response)
}
/// # `GET /_matrix/client/r0/rooms/{roomid}/state/{eventType}`
@ -187,11 +194,14 @@ pub async fn get_state_event_for_empty_key_route(
Error::BadRequest(ErrorKind::NotFound, "State event not found.")
})?;
Ok(get_state_event_for_key::v3::Response {
event_or_content: serde_json::from_str(event.content.get())
.map_err(|_| Error::bad_database("Invalid event content in database"))?,
}
.into())
let response: get_state_event_for_key::v3::Response = match body.format {
StateEventFormat::Content => {
Raw::<AnyStateEventContent>::from_json(event.content.clone()).into()
}
StateEventFormat::Event => event.to_state_event().into(),
};
Ok(response.into())
}
async fn send_state_event_for_key_helper(