pub mod v3 {
use ruma_common::{
api::{request, response, Metadata},
events::{AnyMessageLikeEventContent, MessageLikeEventContent, MessageLikeEventType},
metadata,
serde::Raw,
MilliSecondsSinceUnixEpoch, OwnedEventId, OwnedRoomId, OwnedTransactionId,
};
use serde_json::value::to_raw_value as to_raw_json_value;
const METADATA: Metadata = metadata! {
method: PUT,
rate_limited: false,
authentication: AccessToken,
history: {
1.0 => "/_matrix/client/r0/rooms/:room_id/send/:event_type/:txn_id",
1.1 => "/_matrix/client/v3/rooms/:room_id/send/:event_type/:txn_id",
}
};
#[request(error = crate::Error)]
pub struct Request {
#[ruma_api(path)]
pub room_id: OwnedRoomId,
#[ruma_api(path)]
pub event_type: MessageLikeEventType,
#[ruma_api(path)]
pub txn_id: OwnedTransactionId,
#[ruma_api(body)]
pub body: Raw<AnyMessageLikeEventContent>,
#[ruma_api(query)]
#[serde(skip_serializing_if = "Option::is_none", rename = "ts")]
pub timestamp: Option<MilliSecondsSinceUnixEpoch>,
}
#[response(error = crate::Error)]
pub struct Response {
pub event_id: OwnedEventId,
}
impl Request {
pub fn new<T>(
room_id: OwnedRoomId,
txn_id: OwnedTransactionId,
content: &T,
) -> serde_json::Result<Self>
where
T: MessageLikeEventContent,
{
Ok(Self {
room_id,
txn_id,
event_type: content.event_type(),
body: Raw::from_json(to_raw_json_value(content)?),
timestamp: None,
})
}
pub fn new_raw(
room_id: OwnedRoomId,
txn_id: OwnedTransactionId,
event_type: MessageLikeEventType,
body: Raw<AnyMessageLikeEventContent>,
) -> Self {
Self { room_id, event_type, txn_id, body, timestamp: None }
}
}
impl Response {
pub fn new(event_id: OwnedEventId) -> Self {
Self { event_id }
}
}
}