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