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 {
9696 ///
9797 /// * `room_id` - The id of the room which the message should be sent to.
9898 ///
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.
100101 pub async fn send_message(
101102 &self,
102103 room_id: &RoomId,
103 message: String,
104 content: AnyMessageEventContent,
104105 ) -> MatrixResult<RoomSendResponse> {
105 // FIXME accept AnyMessageEventContent here.
106106 let room_id = room_id.to_owned();
107107 let client = self.client.clone();
108108
109109 let handle = self
110110 .runtime
111111 .spawn(async move {
112 let content =
113 MessageEventContent::Text(TextMessageEventContent {
114 body: message,
115 formatted: None,
116 relates_to: None,
117 });
118
119112 client
120 .room_send(
121 &room_id,
122 AnyMessageEventContent::RoomMessage(content),
123 Some(Uuid::new_v4()),
124 )
113 .room_send(&room_id, content, Some(Uuid::new_v4()))
125114 .await
126115 })
127116 .await;
src/room_buffer.rs +13 −3
@@ -33,10 +33,12 @@ use matrix_sdk::{
3333 },
3434 MembershipState,
3535 },
36 message::{MessageEventContent, TextMessageEventContent},
3637 name::NameEventContent,
3738 },
38 AnyPossiblyRedactedSyncMessageEvent, AnySyncMessageEvent,
39 AnySyncRoomEvent, AnySyncStateEvent, SyncStateEvent,
39 AnyMessageEventContent, AnyPossiblyRedactedSyncMessageEvent,
40 AnySyncMessageEvent, AnySyncRoomEvent, AnySyncStateEvent,
41 SyncStateEvent,
4042 },
4143 identifiers::{RoomId, UserId},
4244 PossiblyRedactedExt, Room,
@@ -109,7 +111,15 @@ impl BufferInputCallbackAsync for MatrixRoom {
109111 // FIXME move this logic into the `MatrixRoom`
110112 if let Some(c) = &*connection.borrow() {
111113 // 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 {
113123 Ok(_r) => (),
114124 Err(_e) => (),
115125 }