Commit 87ef9d3d59
Unsigned
Layout: unified · split
src/room_buffer.rs +15 −12
| @@ -106,19 +106,22 @@ pub struct MatrixRoom { | ||
| 106 | 106 | #[async_trait(?Send)] |
| 107 | 107 | impl BufferInputCallbackAsync for MatrixRoom { |
| 108 | 108 | async fn callback(&mut self, buffer: BufferHandle, input: String) { |
| 109 | let connection = &self.connection; | |
| 109 | // TODO parse the input here and produce a formatted body. | |
| 110 | let content = MessageEventContent::Text(TextMessageEventContent { | |
| 111 | body: input, | |
| 112 | formatted: None, | |
| 113 | relates_to: None, | |
| 114 | }); | |
| 115 | let content = AnyMessageEventContent::RoomMessage(content); | |
| 116 | ||
| 117 | self.send_message(buffer, content).await; | |
| 118 | } | |
| 119 | } | |
| 110 | 120 | |
| 111 | // FIXME move this logic into the `MatrixRoom` | |
| 112 | if let Some(c) = &*connection.borrow() { | |
| 121 | impl MatrixRoom { | |
| 122 | pub async fn send_message(&self, buffer: BufferHandle, content: AnyMessageEventContent) { | |
| 123 | if let Some(c) = &*self.connection.borrow() { | |
| 113 | 124 | // TODO check for errors and print them out. |
| 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 | 125 | match c.send_message(&self.room_id, content, None).await { |
| 123 | 126 | Ok(_r) => (), |
| 124 | 127 | Err(_e) => (), |
| @@ -126,7 +129,7 @@ impl BufferInputCallbackAsync for MatrixRoom { | ||
| 126 | 129 | } else { |
| 127 | 130 | let buffer = buffer |
| 128 | 131 | .upgrade() |
| 129 | .expect("Running input cb but buffer is closed"); | |
| 132 | .expect("Trying to send a message while the buffer is closed"); | |
| 130 | 133 | |
| 131 | 134 | buffer.print("Error not connected"); |
| 132 | 135 | } |