|
|
|
@ -14,7 +14,8 @@ use ruma_client_api::{ |
|
|
|
}, |
|
|
|
}, |
|
|
|
unversioned::get_supported_versions, |
|
|
|
unversioned::get_supported_versions, |
|
|
|
}; |
|
|
|
}; |
|
|
|
use ruma_events::{room::message::MessageEvent, EventResult}; |
|
|
|
use ruma_events::collections::all::Event; |
|
|
|
|
|
|
|
use ruma_events::room::message::MessageEvent; |
|
|
|
use ruma_identifiers::{EventId, UserId}; |
|
|
|
use ruma_identifiers::{EventId, UserId}; |
|
|
|
use ruma_wrapper::{MatrixResult, Ruma}; |
|
|
|
use ruma_wrapper::{MatrixResult, Ruma}; |
|
|
|
use serde_json::map::Map; |
|
|
|
use serde_json::map::Map; |
|
|
|
@ -213,31 +214,19 @@ fn create_message_event_route( |
|
|
|
_txn_id: String, |
|
|
|
_txn_id: String, |
|
|
|
body: Ruma<create_message_event::Request>, |
|
|
|
body: Ruma<create_message_event::Request>, |
|
|
|
) -> MatrixResult<create_message_event::Response> { |
|
|
|
) -> MatrixResult<create_message_event::Response> { |
|
|
|
// Check if content is valid
|
|
|
|
// Generate event id
|
|
|
|
let content = match body.data.clone() { |
|
|
|
|
|
|
|
EventResult::Ok(content) => content, |
|
|
|
|
|
|
|
EventResult::Err(_) => { |
|
|
|
|
|
|
|
debug!("No content."); |
|
|
|
|
|
|
|
return MatrixResult(Err(Error { |
|
|
|
|
|
|
|
kind: ErrorKind::NotFound, |
|
|
|
|
|
|
|
message: "No content.".to_owned(), |
|
|
|
|
|
|
|
status_code: http::StatusCode::BAD_REQUEST, |
|
|
|
|
|
|
|
})); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let event_id = EventId::try_from("$TODOrandomeventid:localhost").unwrap(); |
|
|
|
let event_id = EventId::try_from("$TODOrandomeventid:localhost").unwrap(); |
|
|
|
|
|
|
|
data.event_add( |
|
|
|
data.room_event_add( |
|
|
|
&Event::RoomMessage(MessageEvent { |
|
|
|
&MessageEvent { |
|
|
|
content: body.data.clone().into_result().unwrap(), |
|
|
|
content, |
|
|
|
|
|
|
|
event_id: event_id.clone(), |
|
|
|
event_id: event_id.clone(), |
|
|
|
origin_server_ts: utils::millis_since_unix_epoch(), |
|
|
|
origin_server_ts: utils::millis_since_unix_epoch(), |
|
|
|
room_id: Some(body.room_id.clone()), |
|
|
|
room_id: Some(body.room_id.clone()), |
|
|
|
sender: body.user_id.expect("user is authenticated"), |
|
|
|
sender: body.user_id.clone().expect("user is authenticated"), |
|
|
|
unsigned: Map::default(), |
|
|
|
unsigned: Map::default(), |
|
|
|
} |
|
|
|
}), |
|
|
|
.into(), |
|
|
|
&body.room_id, |
|
|
|
|
|
|
|
&event_id, |
|
|
|
); |
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
MatrixResult(Ok(create_message_event::Response { event_id })) |
|
|
|
MatrixResult(Ok(create_message_event::Response { event_id })) |
|
|
|
|