feat: hacky transactions
This commit is contained in:
parent
e6b1f54857
commit
1f28434988
1 changed files with 31 additions and 9 deletions
|
@ -1,7 +1,8 @@
|
|||
use crate::{client_server, ConduitResult, Database, Error, Result, Ruma};
|
||||
use http::header::{HeaderValue, AUTHORIZATION};
|
||||
use rocket::{get, post, put, response::content::Json, State};
|
||||
use ruma::api::{
|
||||
use ruma::{
|
||||
api::{
|
||||
client,
|
||||
federation::{
|
||||
directory::get_public_rooms,
|
||||
|
@ -11,6 +12,8 @@ use ruma::api::{
|
|||
transactions::send_transaction_message,
|
||||
},
|
||||
OutgoingRequest,
|
||||
},
|
||||
EventId,
|
||||
};
|
||||
use serde_json::json;
|
||||
use std::{
|
||||
|
@ -264,10 +267,29 @@ pub async fn get_public_rooms_route(
|
|||
put("/_matrix/federation/v1/send/<_>", data = "<body>")
|
||||
)]
|
||||
pub fn send_transaction_message_route<'a>(
|
||||
_db: State<'a, Database>,
|
||||
db: State<'a, Database>,
|
||||
body: Ruma<send_transaction_message::v1::Request<'_>>,
|
||||
) -> ConduitResult<send_transaction_message::v1::Response> {
|
||||
dbg!(&*body);
|
||||
for pdu in &body.pdus {
|
||||
let mut value = serde_json::to_value(pdu).expect("all ruma pdus are json values");
|
||||
let event_id = EventId::try_from(&*format!(
|
||||
"${}",
|
||||
ruma::signatures::reference_hash(&value).expect("ruma can calculate reference hashes")
|
||||
))
|
||||
.expect("ruma's reference hashes are valid event ids");
|
||||
|
||||
value
|
||||
.as_object_mut()
|
||||
.expect("ruma pdus are json objects")
|
||||
.insert("event_id".to_owned(), event_id.to_string().into());
|
||||
|
||||
db.rooms.append_pdu(
|
||||
serde_json::from_value(value).expect("all ruma pdus are conduit pdus"),
|
||||
&db.globals,
|
||||
&db.account_data,
|
||||
)?;
|
||||
}
|
||||
Ok(send_transaction_message::v1::Response {
|
||||
pdus: BTreeMap::new(),
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue