ruma_federation_api/transactions/send_transaction_message.rs
1//! `PUT /_matrix/federation/*/send/{txnId}`
2//!
3//! Send live activity messages to another server.
4
5pub mod v1 {
6 //! `/v1/` ([spec])
7 //!
8 //! [spec]: https://spec.matrix.org/latest/server-server-api/#put_matrixfederationv1sendtxnid
9
10 use std::collections::BTreeMap;
11
12 use ruma_common::{
13 api::{request, response},
14 metadata,
15 serde::Raw,
16 MilliSecondsSinceUnixEpoch, OwnedEventId, OwnedServerName, OwnedTransactionId,
17 };
18 use serde_json::value::RawValue as RawJsonValue;
19
20 use crate::{authentication::ServerSignatures, transactions::edu::Edu};
21
22 metadata! {
23 method: PUT,
24 rate_limited: false,
25 authentication: ServerSignatures,
26 path: "/_matrix/federation/v1/send/{transaction_id}",
27 }
28
29 /// Request type for the `send_transaction_message` endpoint.
30 #[request]
31 pub struct Request {
32 /// A transaction ID unique between sending and receiving homeservers.
33 #[ruma_api(path)]
34 pub transaction_id: OwnedTransactionId,
35
36 /// The server_name of the homeserver sending this transaction.
37 pub origin: OwnedServerName,
38
39 /// POSIX timestamp in milliseconds on the originating homeserver when this transaction
40 /// started.
41 pub origin_server_ts: MilliSecondsSinceUnixEpoch,
42
43 /// List of persistent updates to rooms.
44 ///
45 /// Must not be more than 50 items.
46 ///
47 /// With the `compat-optional-pdus` feature, this field is optional in deserialization,
48 /// defaulting to an empty `Vec`.
49 #[cfg_attr(feature = "compat-optional-txn-pdus", serde(default))]
50 pub pdus: Vec<Box<RawJsonValue>>,
51
52 /// List of ephemeral messages.
53 ///
54 /// Must not be more than 100 items.
55 #[serde(default, skip_serializing_if = "<[_]>::is_empty")]
56 pub edus: Vec<Raw<Edu>>,
57 }
58
59 /// Response type for the `send_transaction_message` endpoint.
60 #[response]
61 #[derive(Default)]
62 pub struct Response {
63 /// Map of event IDs and response for each PDU given in the request.
64 ///
65 /// With the `unstable-msc3618` feature, returning `pdus` is optional.
66 /// See [MSC3618](https://github.com/matrix-org/matrix-spec-proposals/pull/3618).
67 #[cfg_attr(feature = "unstable-msc3618", serde(default))]
68 #[serde(with = "crate::serde::pdu_process_response")]
69 pub pdus: BTreeMap<OwnedEventId, Result<(), String>>,
70 }
71
72 impl Request {
73 /// Creates a new `Request` with the given transaction ID, origin, timestamp.
74 ///
75 /// The PDU and EDU lists will start off empty.
76 pub fn new(
77 transaction_id: OwnedTransactionId,
78 origin: OwnedServerName,
79 origin_server_ts: MilliSecondsSinceUnixEpoch,
80 ) -> Self {
81 Self { transaction_id, origin, origin_server_ts, pdus: vec![], edus: vec![] }
82 }
83 }
84
85 impl Response {
86 /// Creates a new `Response` with the given PDUs.
87 pub fn new(pdus: BTreeMap<OwnedEventId, Result<(), String>>) -> Self {
88 Self { pdus }
89 }
90 }
91}