From b76af682a6010f663eddbbd979b6dc846f8e3a2b Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Thu, 29 Apr 2021 20:16:49 +0200 Subject: [PATCH 1/6] Fix clippy warnings --- src/client_server/profile.rs | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/client_server/profile.rs b/src/client_server/profile.rs index f2c141bd..79d00772 100644 --- a/src/client_server/profile.rs +++ b/src/client_server/profile.rs @@ -52,8 +52,7 @@ pub async fn set_displayname_route( "Tried to send displayname update for user not in the room.", ) })? - .content - .clone(), + .content, ) .expect("from_value::> can never fail") .deserialize() @@ -153,8 +152,7 @@ pub async fn set_avatar_url_route( "Tried to send displayname update for user not in the room.", ) })? - .content - .clone(), + .content, ) .expect("from_value::> can never fail") .deserialize() From 61c522dcc0e350f59bd69e140e588e74b3d6a96b Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Thu, 29 Apr 2021 20:16:52 +0200 Subject: [PATCH 2/6] Fix formatting --- src/client_server/profile.rs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/client_server/profile.rs b/src/client_server/profile.rs index 79d00772..882b02e7 100644 --- a/src/client_server/profile.rs +++ b/src/client_server/profile.rs @@ -49,8 +49,9 @@ pub async fn set_displayname_route( )? .ok_or_else(|| { Error::bad_database( - "Tried to send displayname update for user not in the room.", - ) + "Tried to send displayname update for user not in the \ + room.", + ) })? .content, ) @@ -149,8 +150,9 @@ pub async fn set_avatar_url_route( )? .ok_or_else(|| { Error::bad_database( - "Tried to send displayname update for user not in the room.", - ) + "Tried to send displayname update for user not in the \ + room.", + ) })? .content, ) From 08ca573df0fa4bf2650643a26f3d46151466bd7f Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Thu, 29 Apr 2021 16:50:04 +0200 Subject: [PATCH 3/6] Remove explicit setting of content-type header `try_into_http_request` takes care of this already. --- src/appservice_server.rs | 6 ------ 1 file changed, 6 deletions(-) diff --git a/src/appservice_server.rs b/src/appservice_server.rs index 8f64edf1..27d0c0d3 100644 --- a/src/appservice_server.rs +++ b/src/appservice_server.rs @@ -1,6 +1,5 @@ use crate::{utils, Error, Result}; use bytes::BytesMut; -use http::header::{HeaderValue, CONTENT_TYPE}; use log::warn; use ruma::api::{IncomingResponse, OutgoingRequest, SendAccessToken}; use std::{ @@ -40,11 +39,6 @@ where ); *http_request.uri_mut() = parts.try_into().expect("our manipulation is always valid"); - http_request.headers_mut().insert( - CONTENT_TYPE, - HeaderValue::from_str("application/json").unwrap(), - ); - let mut reqwest_request = reqwest::Request::try_from(http_request) .expect("all http requests are valid reqwest requests"); From c28eba1e5b1164f5e7021de6172e82e16bd5ffd0 Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Thu, 29 Apr 2021 20:56:45 +0200 Subject: [PATCH 4/6] Bump ruma --- Cargo.lock | 37 +++++++++++++++++++------------------ Cargo.toml | 4 ++-- src/client_server/config.rs | 14 +++++++------- 3 files changed, 28 insertions(+), 27 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index b0212c8b..60301bb8 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1634,7 +1634,7 @@ dependencies = [ [[package]] name = "ruma" version = "0.0.3" -source = "git+https://github.com/ruma/ruma?rev=d27584ae3bdc035529e7389f1c392d4c96f9f8eb#d27584ae3bdc035529e7389f1c392d4c96f9f8eb" +source = "git+https://github.com/ruma/ruma?rev=8c286e78d41770fe431e7304cc2fe23e383793df#8c286e78d41770fe431e7304cc2fe23e383793df" dependencies = [ "assign", "js_int", @@ -1654,7 +1654,7 @@ dependencies = [ [[package]] name = "ruma-api" version = "0.17.0-alpha.4" -source = "git+https://github.com/ruma/ruma?rev=d27584ae3bdc035529e7389f1c392d4c96f9f8eb#d27584ae3bdc035529e7389f1c392d4c96f9f8eb" +source = "git+https://github.com/ruma/ruma?rev=8c286e78d41770fe431e7304cc2fe23e383793df#8c286e78d41770fe431e7304cc2fe23e383793df" dependencies = [ "bytes", "http", @@ -1670,7 +1670,7 @@ dependencies = [ [[package]] name = "ruma-api-macros" version = "0.17.0-alpha.4" -source = "git+https://github.com/ruma/ruma?rev=d27584ae3bdc035529e7389f1c392d4c96f9f8eb#d27584ae3bdc035529e7389f1c392d4c96f9f8eb" +source = "git+https://github.com/ruma/ruma?rev=8c286e78d41770fe431e7304cc2fe23e383793df#8c286e78d41770fe431e7304cc2fe23e383793df" dependencies = [ "proc-macro-crate", "proc-macro2", @@ -1681,7 +1681,7 @@ dependencies = [ [[package]] name = "ruma-appservice-api" version = "0.2.0-alpha.3" -source = "git+https://github.com/ruma/ruma?rev=d27584ae3bdc035529e7389f1c392d4c96f9f8eb#d27584ae3bdc035529e7389f1c392d4c96f9f8eb" +source = "git+https://github.com/ruma/ruma?rev=8c286e78d41770fe431e7304cc2fe23e383793df#8c286e78d41770fe431e7304cc2fe23e383793df" dependencies = [ "ruma-api", "ruma-common", @@ -1695,7 +1695,7 @@ dependencies = [ [[package]] name = "ruma-client-api" version = "0.10.0-alpha.3" -source = "git+https://github.com/ruma/ruma?rev=d27584ae3bdc035529e7389f1c392d4c96f9f8eb#d27584ae3bdc035529e7389f1c392d4c96f9f8eb" +source = "git+https://github.com/ruma/ruma?rev=8c286e78d41770fe431e7304cc2fe23e383793df#8c286e78d41770fe431e7304cc2fe23e383793df" dependencies = [ "assign", "bytes", @@ -1715,7 +1715,7 @@ dependencies = [ [[package]] name = "ruma-common" version = "0.5.0" -source = "git+https://github.com/ruma/ruma?rev=d27584ae3bdc035529e7389f1c392d4c96f9f8eb#d27584ae3bdc035529e7389f1c392d4c96f9f8eb" +source = "git+https://github.com/ruma/ruma?rev=8c286e78d41770fe431e7304cc2fe23e383793df#8c286e78d41770fe431e7304cc2fe23e383793df" dependencies = [ "indexmap", "js_int", @@ -1731,7 +1731,7 @@ dependencies = [ [[package]] name = "ruma-events" version = "0.22.0-alpha.3" -source = "git+https://github.com/ruma/ruma?rev=d27584ae3bdc035529e7389f1c392d4c96f9f8eb#d27584ae3bdc035529e7389f1c392d4c96f9f8eb" +source = "git+https://github.com/ruma/ruma?rev=8c286e78d41770fe431e7304cc2fe23e383793df#8c286e78d41770fe431e7304cc2fe23e383793df" dependencies = [ "js_int", "ruma-common", @@ -1745,7 +1745,7 @@ dependencies = [ [[package]] name = "ruma-events-macros" version = "0.22.0-alpha.3" -source = "git+https://github.com/ruma/ruma?rev=d27584ae3bdc035529e7389f1c392d4c96f9f8eb#d27584ae3bdc035529e7389f1c392d4c96f9f8eb" +source = "git+https://github.com/ruma/ruma?rev=8c286e78d41770fe431e7304cc2fe23e383793df#8c286e78d41770fe431e7304cc2fe23e383793df" dependencies = [ "proc-macro-crate", "proc-macro2", @@ -1756,7 +1756,7 @@ dependencies = [ [[package]] name = "ruma-federation-api" version = "0.1.0-alpha.2" -source = "git+https://github.com/ruma/ruma?rev=d27584ae3bdc035529e7389f1c392d4c96f9f8eb#d27584ae3bdc035529e7389f1c392d4c96f9f8eb" +source = "git+https://github.com/ruma/ruma?rev=8c286e78d41770fe431e7304cc2fe23e383793df#8c286e78d41770fe431e7304cc2fe23e383793df" dependencies = [ "js_int", "ruma-api", @@ -1771,7 +1771,7 @@ dependencies = [ [[package]] name = "ruma-identifiers" version = "0.19.0" -source = "git+https://github.com/ruma/ruma?rev=d27584ae3bdc035529e7389f1c392d4c96f9f8eb#d27584ae3bdc035529e7389f1c392d4c96f9f8eb" +source = "git+https://github.com/ruma/ruma?rev=8c286e78d41770fe431e7304cc2fe23e383793df#8c286e78d41770fe431e7304cc2fe23e383793df" dependencies = [ "paste", "rand", @@ -1785,7 +1785,7 @@ dependencies = [ [[package]] name = "ruma-identifiers-macros" version = "0.19.0" -source = "git+https://github.com/ruma/ruma?rev=d27584ae3bdc035529e7389f1c392d4c96f9f8eb#d27584ae3bdc035529e7389f1c392d4c96f9f8eb" +source = "git+https://github.com/ruma/ruma?rev=8c286e78d41770fe431e7304cc2fe23e383793df#8c286e78d41770fe431e7304cc2fe23e383793df" dependencies = [ "proc-macro2", "quote", @@ -1796,13 +1796,14 @@ dependencies = [ [[package]] name = "ruma-identifiers-validation" version = "0.3.0" -source = "git+https://github.com/ruma/ruma?rev=d27584ae3bdc035529e7389f1c392d4c96f9f8eb#d27584ae3bdc035529e7389f1c392d4c96f9f8eb" +source = "git+https://github.com/ruma/ruma?rev=8c286e78d41770fe431e7304cc2fe23e383793df#8c286e78d41770fe431e7304cc2fe23e383793df" [[package]] name = "ruma-identity-service-api" version = "0.1.0-alpha.1" -source = "git+https://github.com/ruma/ruma?rev=d27584ae3bdc035529e7389f1c392d4c96f9f8eb#d27584ae3bdc035529e7389f1c392d4c96f9f8eb" +source = "git+https://github.com/ruma/ruma?rev=8c286e78d41770fe431e7304cc2fe23e383793df#8c286e78d41770fe431e7304cc2fe23e383793df" dependencies = [ + "js_int", "ruma-api", "ruma-common", "ruma-identifiers", @@ -1814,7 +1815,7 @@ dependencies = [ [[package]] name = "ruma-push-gateway-api" version = "0.1.0-alpha.1" -source = "git+https://github.com/ruma/ruma?rev=d27584ae3bdc035529e7389f1c392d4c96f9f8eb#d27584ae3bdc035529e7389f1c392d4c96f9f8eb" +source = "git+https://github.com/ruma/ruma?rev=8c286e78d41770fe431e7304cc2fe23e383793df#8c286e78d41770fe431e7304cc2fe23e383793df" dependencies = [ "js_int", "ruma-api", @@ -1829,7 +1830,7 @@ dependencies = [ [[package]] name = "ruma-serde" version = "0.3.1" -source = "git+https://github.com/ruma/ruma?rev=d27584ae3bdc035529e7389f1c392d4c96f9f8eb#d27584ae3bdc035529e7389f1c392d4c96f9f8eb" +source = "git+https://github.com/ruma/ruma?rev=8c286e78d41770fe431e7304cc2fe23e383793df#8c286e78d41770fe431e7304cc2fe23e383793df" dependencies = [ "bytes", "form_urlencoded", @@ -1843,7 +1844,7 @@ dependencies = [ [[package]] name = "ruma-serde-macros" version = "0.3.1" -source = "git+https://github.com/ruma/ruma?rev=d27584ae3bdc035529e7389f1c392d4c96f9f8eb#d27584ae3bdc035529e7389f1c392d4c96f9f8eb" +source = "git+https://github.com/ruma/ruma?rev=8c286e78d41770fe431e7304cc2fe23e383793df#8c286e78d41770fe431e7304cc2fe23e383793df" dependencies = [ "proc-macro-crate", "proc-macro2", @@ -1854,7 +1855,7 @@ dependencies = [ [[package]] name = "ruma-signatures" version = "0.7.0" -source = "git+https://github.com/ruma/ruma?rev=d27584ae3bdc035529e7389f1c392d4c96f9f8eb#d27584ae3bdc035529e7389f1c392d4c96f9f8eb" +source = "git+https://github.com/ruma/ruma?rev=8c286e78d41770fe431e7304cc2fe23e383793df#8c286e78d41770fe431e7304cc2fe23e383793df" dependencies = [ "base64 0.13.0", "ring", @@ -2167,7 +2168,7 @@ dependencies = [ [[package]] name = "state-res" version = "0.1.0" -source = "git+https://github.com/ruma/state-res?rev=ce665d213fffeaa47e146d01c6b87f9eb9feaa52#ce665d213fffeaa47e146d01c6b87f9eb9feaa52" +source = "git+https://github.com/ruma/state-res?rev=c20893e536bea4d17a9fe6af28428fb17169b56f#c20893e536bea4d17a9fe6af28428fb17169b56f" dependencies = [ "itertools 0.10.0", "log", diff --git a/Cargo.toml b/Cargo.toml index 8554fa21..f12420e6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -18,12 +18,12 @@ rocket = { git = "https://github.com/SergioBenitez/Rocket.git", rev = "801e04bd5 #rocket = { git = "https://github.com/timokoesters/Rocket.git", branch = "empty_parameters", default-features = false, features = ["tls"] } # Used for matrix spec type definitions and helpers -ruma = { git = "https://github.com/ruma/ruma", rev = "d27584ae3bdc035529e7389f1c392d4c96f9f8eb", features = ["compat", "rand", "appservice-api-c", "client-api", "federation-api", "push-gateway-api-c", "unstable-pre-spec", "unstable-exhaustive-types"] } +ruma = { git = "https://github.com/ruma/ruma", rev = "8c286e78d41770fe431e7304cc2fe23e383793df", features = ["compat", "rand", "appservice-api-c", "client-api", "federation-api", "push-gateway-api-c", "unstable-pre-spec", "unstable-exhaustive-types"] } #ruma = { git = "https://github.com/timokoesters/ruma", rev = "220d5b4a76b3b781f7f8297fbe6b14473b04214b", features = ["compat", "rand", "appservice-api-c", "client-api", "federation-api", "push-gateway-api-c", "unstable-pre-spec", "unstable-exhaustive-types"] } #ruma = { path = "../ruma/ruma", features = ["compat", "rand", "appservice-api-c", "client-api", "federation-api", "push-gateway-api-c", "unstable-pre-spec", "unstable-exhaustive-types"] } # Used when doing state resolution -state-res = { git = "https://github.com/ruma/state-res", rev = "ce665d213fffeaa47e146d01c6b87f9eb9feaa52", features = ["unstable-pre-spec"] } +state-res = { git = "https://github.com/ruma/state-res", rev = "c20893e536bea4d17a9fe6af28428fb17169b56f", features = ["unstable-pre-spec"] } #state-res = { path = "../state-res", features = ["unstable-pre-spec"] } # Used for long polling and federation sender, should be the same as rocket::tokio diff --git a/src/client_server/config.rs b/src/client_server/config.rs index 68cd2e03..b6f272d1 100644 --- a/src/client_server/config.rs +++ b/src/client_server/config.rs @@ -8,7 +8,7 @@ use ruma::{ set_room_account_data, }, }, - events::{custom::CustomEventContent, BasicEvent}, + events::{custom::CustomEventContent, AnyBasicEventContent, BasicEvent}, serde::Raw, }; @@ -91,14 +91,14 @@ pub async fn get_global_account_data_route( ) -> ConduitResult { let sender_user = body.sender_user.as_ref().expect("user is authenticated"); - let data = db + let account_data = db .account_data - .get::>(None, sender_user, body.event_type.clone().into())? + .get::>(None, sender_user, body.event_type.clone().into())? .ok_or(Error::BadRequest(ErrorKind::NotFound, "Data not found."))?; db.flush().await?; - Ok(get_global_account_data::Response { account_data: data }.into()) + Ok(get_global_account_data::Response { account_data }.into()) } #[cfg_attr( @@ -115,9 +115,9 @@ pub async fn get_room_account_data_route( ) -> ConduitResult { let sender_user = body.sender_user.as_ref().expect("user is authenticated"); - let data = db + let account_data = db .account_data - .get::>( + .get::>( Some(&body.room_id), sender_user, body.event_type.clone().into(), @@ -126,5 +126,5 @@ pub async fn get_room_account_data_route( db.flush().await?; - Ok(get_room_account_data::Response { account_data: data }.into()) + Ok(get_room_account_data::Response { account_data }.into()) } From 8bfaf09f3750ddd64762d278827e2e933cec2f52 Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Thu, 29 Apr 2021 20:58:05 +0200 Subject: [PATCH 5/6] Clean up reqwest::Response to http::Response conversion --- src/appservice_server.rs | 30 +++++++++++++++--------------- src/database/pusher.rs | 35 +++++++++++++++++------------------ src/server_server.rs | 34 +++++++++++++++++----------------- 3 files changed, 49 insertions(+), 50 deletions(-) diff --git a/src/appservice_server.rs b/src/appservice_server.rs index 27d0c0d3..42918577 100644 --- a/src/appservice_server.rs +++ b/src/appservice_server.rs @@ -5,6 +5,7 @@ use ruma::api::{IncomingResponse, OutgoingRequest, SendAccessToken}; use std::{ convert::{TryFrom, TryInto}, fmt::Debug, + mem, time::Duration, }; @@ -45,22 +46,21 @@ where *reqwest_request.timeout_mut() = Some(Duration::from_secs(30)); let url = reqwest_request.url().clone(); - let mut reqwest_response = globals.reqwest_client().execute(reqwest_request).await?; + let mut response = globals.reqwest_client().execute(reqwest_request).await?; - // Because reqwest::Response -> http::Response is complicated: - let status = reqwest_response.status(); - let mut http_response = http::Response::builder().status(status); - let headers = http_response.headers_mut().unwrap(); + // reqwest::Response -> http::Response conversion + let status = response.status(); + let mut http_response_builder = http::Response::builder() + .status(status) + .version(response.version()); + mem::swap( + response.headers_mut(), + http_response_builder + .headers_mut() + .expect("http::response::Builder is usable"), + ); - for (k, v) in reqwest_response.headers_mut().drain() { - if let Some(key) = k { - headers.insert(key, v); - } - } - - let status = reqwest_response.status(); - - let body = reqwest_response.bytes().await.unwrap_or_else(|e| { + let body = response.bytes().await.unwrap_or_else(|e| { warn!("server error: {}", e); Vec::new().into() }); // TODO: handle timeout @@ -76,7 +76,7 @@ where } let response = T::IncomingResponse::try_from_http_response( - http_response + http_response_builder .body(body) .expect("reqwest body is valid http body"), ); diff --git a/src/database/pusher.rs b/src/database/pusher.rs index 7c7abb3b..75c2efb6 100644 --- a/src/database/pusher.rs +++ b/src/database/pusher.rs @@ -16,7 +16,7 @@ use ruma::{ }; use sled::IVec; -use std::{convert::TryFrom, fmt::Debug}; +use std::{convert::TryFrom, fmt::Debug, mem}; #[derive(Debug, Clone)] pub struct PushData { @@ -114,24 +114,23 @@ where //*reqwest_request.timeout_mut() = Some(Duration::from_secs(5)); let url = reqwest_request.url().clone(); - let reqwest_response = globals.reqwest_client().execute(reqwest_request).await; + let response = globals.reqwest_client().execute(reqwest_request).await; - // Because reqwest::Response -> http::Response is complicated: - match reqwest_response { - Ok(mut reqwest_response) => { - let status = reqwest_response.status(); - let mut http_response = http::Response::builder().status(status); - let headers = http_response.headers_mut().unwrap(); + match response { + Ok(mut response) => { + // reqwest::Response -> http::Response conversion + let status = response.status(); + let mut http_response_builder = http::Response::builder() + .status(status) + .version(response.version()); + mem::swap( + response.headers_mut(), + http_response_builder + .headers_mut() + .expect("http::response::Builder is usable"), + ); - for (k, v) in reqwest_response.headers_mut().drain() { - if let Some(key) = k { - headers.insert(key, v); - } - } - - let status = reqwest_response.status(); - - let body = reqwest_response.bytes().await.unwrap_or_else(|e| { + let body = response.bytes().await.unwrap_or_else(|e| { warn!("server error {}", e); Vec::new().into() }); // TODO: handle timeout @@ -147,7 +146,7 @@ where } let response = T::IncomingResponse::try_from_http_response( - http_response + http_response_builder .body(body) .expect("reqwest body is valid http body"), ); diff --git a/src/server_server.rs b/src/server_server.rs index 1e58067e..908a54e6 100644 --- a/src/server_server.rs +++ b/src/server_server.rs @@ -43,6 +43,7 @@ use std::{ convert::{TryFrom, TryInto}, fmt::Debug, future::Future, + mem, net::{IpAddr, SocketAddr}, pin::Pin, result::Result as StdResult, @@ -219,24 +220,23 @@ where *reqwest_request.timeout_mut() = Some(Duration::from_secs(30)); let url = reqwest_request.url().clone(); - let reqwest_response = globals.reqwest_client().execute(reqwest_request).await; + let response = globals.reqwest_client().execute(reqwest_request).await; - // Because reqwest::Response -> http::Response is complicated: - match reqwest_response { - Ok(mut reqwest_response) => { - let status = reqwest_response.status(); - let mut http_response = http::Response::builder().status(status); - let headers = http_response.headers_mut().unwrap(); + match response { + Ok(mut response) => { + // reqwest::Response -> http::Response conversion + let status = response.status(); + let mut http_response_builder = http::Response::builder() + .status(status) + .version(response.version()); + mem::swap( + response.headers_mut(), + http_response_builder + .headers_mut() + .expect("http::response::Builder is usable"), + ); - for (k, v) in reqwest_response.headers_mut().drain() { - if let Some(key) = k { - headers.insert(key, v); - } - } - - let status = reqwest_response.status(); - - let body = reqwest_response.bytes().await.unwrap_or_else(|e| { + let body = response.bytes().await.unwrap_or_else(|e| { warn!("server error {}", e); Vec::new().into() }); // TODO: handle timeout @@ -254,7 +254,7 @@ where } let response = T::IncomingResponse::try_from_http_response( - http_response + http_response_builder .body(body) .expect("reqwest body is valid http body"), ); From e1c4e5c73ebde9451cc947254cbe58c92ee0a42a Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Thu, 29 Apr 2021 21:06:15 +0200 Subject: [PATCH 6/6] Return only event content in account_data endpoints, not the entire event --- src/client_server/config.rs | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/src/client_server/config.rs b/src/client_server/config.rs index b6f272d1..07a9bc96 100644 --- a/src/client_server/config.rs +++ b/src/client_server/config.rs @@ -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 { let sender_user = body.sender_user.as_ref().expect("user is authenticated"); - let account_data = db + let event = db .account_data - .get::>(None, sender_user, body.event_type.clone().into())? + .get::>(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::(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 { let sender_user = body.sender_user.as_ref().expect("user is authenticated"); - let account_data = db + let event = db .account_data - .get::>( + .get::>( 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::(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, +}