Refactor account_data to be more similar to other endpoints

next
Devin Ragotzy 2020-07-25 15:48:12 -04:00
parent 60381ddcf4
commit 87fd432527
1 changed files with 8 additions and 7 deletions

View File

@ -589,18 +589,19 @@ pub fn get_global_account_data_route(
) -> ConduitResult<get_global_account_data::Response> { ) -> ConduitResult<get_global_account_data::Response> {
let user_id = body.user_id.as_ref().expect("user is authenticated"); let user_id = body.user_id.as_ref().expect("user is authenticated");
db.account_data let event = db
.account_data
.get( .get(
None, None,
user_id, user_id,
&EventType::try_from(&body.event_type).expect("EventType::try_from can never fail"), &EventType::try_from(&body.event_type).expect("EventType::try_from can never fail"),
)? )?
.and_then(|ev| { .ok_or(Error::BadRequest(ErrorKind::NotFound, "Data not found."))?;
serde_json::from_str(ev.json().get())
.map(|data| get_global_account_data::Response { account_data: data }.into()) let data = serde_json::from_str(event.json().get())
.ok() .map_err(|_| Error::bad_database("Invalid account data event in db."))?;
})
.ok_or(Error::BadRequest(ErrorKind::NotFound, "Data not found.")) Ok(get_global_account_data::Response { account_data: data }.into())
} }
#[put("/_matrix/client/r0/profile/<_user_id>/displayname", data = "<body>")] #[put("/_matrix/client/r0/profile/<_user_id>/displayname", data = "<body>")]