1
0
Fork 0
mirror of https://gitlab.com/famedly/conduit.git synced 2024-12-29 11:34:35 +01:00

Return only event content in account_data endpoints, not the entire event

This commit is contained in:
Jonas Platte 2021-04-29 21:06:15 +02:00
parent 8bfaf09f37
commit e1c4e5c73e
No known key found for this signature in database
GPG key ID: 7D261D771D915378

View file

@ -11,6 +11,8 @@ use ruma::{
events::{custom::CustomEventContent, AnyBasicEventContent, BasicEvent},
serde::Raw,
};
use serde::Deserialize;
use serde_json::value::RawValue as RawJsonValue;
#[cfg(feature = "conduit_bin")]
use rocket::{get, put};
@ -91,13 +93,16 @@ pub async fn get_global_account_data_route(
) -> ConduitResult<get_global_account_data::Response> {
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
let account_data = db
let event = db
.account_data
.get::<Raw<AnyBasicEventContent>>(None, sender_user, body.event_type.clone().into())?
.get::<Box<RawJsonValue>>(None, sender_user, body.event_type.clone().into())?
.ok_or(Error::BadRequest(ErrorKind::NotFound, "Data not found."))?;
db.flush().await?;
let account_data = serde_json::from_str::<ExtractEventContent>(event.get())
.map_err(|_| Error::bad_database("Invalid account data event in db."))?
.content;
Ok(get_global_account_data::Response { account_data }.into())
}
@ -115,16 +120,24 @@ pub async fn get_room_account_data_route(
) -> ConduitResult<get_room_account_data::Response> {
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
let account_data = db
let event = db
.account_data
.get::<Raw<AnyBasicEventContent>>(
.get::<Box<RawJsonValue>>(
Some(&body.room_id),
sender_user,
body.event_type.clone().into(),
)?
.ok_or(Error::BadRequest(ErrorKind::NotFound, "Data not found."))?;
db.flush().await?;
let account_data = serde_json::from_str::<ExtractEventContent>(event.get())
.map_err(|_| Error::bad_database("Invalid account data event in db."))?
.content;
Ok(get_room_account_data::Response { account_data }.into())
}
#[derive(Deserialize)]
struct ExtractEventContent {
content: Raw<AnyBasicEventContent>,
}