Commit e53abd2732

e53abd2732652290b28a39428bc6438ac3945e02

parent: 7a5291f65d

Unsigned

Damir Jelić <poljar@termina.org.uk> · 2020-09-06 09:08 UTC

connection: Allow setting a transaction id when sending events.

Layout: unified · split

src/connection.rs +9 −1
@@ -98,10 +98,14 @@ impl Connection {
98 /// 98 ///
99 /// * `content` - The content of the message that will be sent to the 99 /// * `content` - The content of the message that will be sent to the
100 /// server. 100 /// server.
101 ///
102 /// * `transaction_id` - Attach an unique id to this message, later on the
103 /// event will contain the same id in the unsigned part of the event.
101 pub async fn send_message( 104 pub async fn send_message(
102 &self, 105 &self,
103 room_id: &RoomId, 106 room_id: &RoomId,
104 content: AnyMessageEventContent, 107 content: AnyMessageEventContent,
108 transaction_id: Option<Uuid>,
105 ) -> MatrixResult<RoomSendResponse> { 109 ) -> MatrixResult<RoomSendResponse> {
106 let room_id = room_id.to_owned(); 110 let room_id = room_id.to_owned();
107 let client = self.client.clone(); 111 let client = self.client.clone();
@@ -110,7 +114,11 @@ impl Connection {
110 .runtime 114 .runtime
111 .spawn(async move { 115 .spawn(async move {
112 client 116 client
113 .room_send(&room_id, content, Some(Uuid::new_v4())) 117 .room_send(
118 &room_id,
119 content,
120 Some(transaction_id.unwrap_or_else(Uuid::new_v4)),
121 )
114 .await 122 .await
115 }) 123 })
116 .await; 124 .await;
src/room_buffer.rs +1 −1
@@ -119,7 +119,7 @@ impl BufferInputCallbackAsync for MatrixRoom {
119 119
120 let content = AnyMessageEventContent::RoomMessage(content); 120 let content = AnyMessageEventContent::RoomMessage(content);
121 121
122 match c.send_message(&self.room_id, content).await { 122 match c.send_message(&self.room_id, content, None).await {
123 Ok(_r) => (), 123 Ok(_r) => (),
124 Err(_e) => (), 124 Err(_e) => (),
125 } 125 }