Commit 7a5291f65d

7a5291f65d6308f9793a2196a9b2935f74494ba6

parent: 9651c4c2dd

Unsigned

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

connection: Allow any message event content to be sent out.

Layout: unified · split

src/connection.rs +4 −15
@@ -96,32 +96,21 @@ impl Connection {
96 /// 96 ///
97 /// * `room_id` - The id of the room which the message should be sent to. 97 /// * `room_id` - The id of the room which the message should be sent to.
98 /// 98 ///
99 /// * `message` - The message that should be sent to the room. 99 /// * `content` - The content of the message that will be sent to the
100 /// server.
100 pub async fn send_message( 101 pub async fn send_message(
101 &self, 102 &self,
102 room_id: &RoomId, 103 room_id: &RoomId,
103 message: String, 104 content: AnyMessageEventContent,
104 ) -> MatrixResult<RoomSendResponse> { 105 ) -> MatrixResult<RoomSendResponse> {
105 // FIXME accept AnyMessageEventContent here.
106 let room_id = room_id.to_owned(); 106 let room_id = room_id.to_owned();
107 let client = self.client.clone(); 107 let client = self.client.clone();
108 108
109 let handle = self 109 let handle = self
110 .runtime 110 .runtime
111 .spawn(async move { 111 .spawn(async move {
112 let content =
113 MessageEventContent::Text(TextMessageEventContent {
114 body: message,
115 formatted: None,
116 relates_to: None,
117 });
118
119 client 112 client
120 .room_send( 113 .room_send(&room_id, content, Some(Uuid::new_v4()))
121 &room_id,
122 AnyMessageEventContent::RoomMessage(content),
123 Some(Uuid::new_v4()),
124 )
125 .await 114 .await
126 }) 115 })
127 .await; 116 .await;
src/room_buffer.rs +13 −3
@@ -33,10 +33,12 @@ use matrix_sdk::{
33 }, 33 },
34 MembershipState, 34 MembershipState,
35 }, 35 },
36 message::{MessageEventContent, TextMessageEventContent},
36 name::NameEventContent, 37 name::NameEventContent,
37 }, 38 },
38 AnyPossiblyRedactedSyncMessageEvent, AnySyncMessageEvent, 39 AnyMessageEventContent, AnyPossiblyRedactedSyncMessageEvent,
39 AnySyncRoomEvent, AnySyncStateEvent, SyncStateEvent, 40 AnySyncMessageEvent, AnySyncRoomEvent, AnySyncStateEvent,
41 SyncStateEvent,
40 }, 42 },
41 identifiers::{RoomId, UserId}, 43 identifiers::{RoomId, UserId},
42 PossiblyRedactedExt, Room, 44 PossiblyRedactedExt, Room,
@@ -109,7 +111,15 @@ impl BufferInputCallbackAsync for MatrixRoom {
109 // FIXME move this logic into the `MatrixRoom` 111 // FIXME move this logic into the `MatrixRoom`
110 if let Some(c) = &*connection.borrow() { 112 if let Some(c) = &*connection.borrow() {
111 // TODO check for errors and print them out. 113 // TODO check for errors and print them out.
112 match c.send_message(&self.room_id, input).await { 114 let content = MessageEventContent::Text(TextMessageEventContent {
115 body: input,
116 formatted: None,
117 relates_to: None,
118 });
119
120 let content = AnyMessageEventContent::RoomMessage(content);
121
122 match c.send_message(&self.room_id, content).await {
113 Ok(_r) => (), 123 Ok(_r) => (),
114 Err(_e) => (), 124 Err(_e) => (),
115 } 125 }