Commit 87ef9d3d59

87ef9d3d5972fef78a4e5bc1875a58d5b9a53f54

parent: e53abd2732

Unsigned

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

room: Move the sending logic out of the input callback.

Layout: unified · split

src/room_buffer.rs +15 −12
@@ -106,19 +106,22 @@ pub struct MatrixRoom {
106106#[async_trait(?Send)]
107107impl BufferInputCallbackAsync for MatrixRoom {
108108 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}
110120
111 // FIXME move this logic into the `MatrixRoom`
112 if let Some(c) = &*connection.borrow() {
121impl MatrixRoom {
122 pub async fn send_message(&self, buffer: BufferHandle, content: AnyMessageEventContent) {
123 if let Some(c) = &*self.connection.borrow() {
113124 // 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
122125 match c.send_message(&self.room_id, content, None).await {
123126 Ok(_r) => (),
124127 Err(_e) => (),
@@ -126,7 +129,7 @@ impl BufferInputCallbackAsync for MatrixRoom {
126129 } else {
127130 let buffer = buffer
128131 .upgrade()
129 .expect("Running input cb but buffer is closed");
132 .expect("Trying to send a message while the buffer is closed");
130133
131134 buffer.print("Error not connected");
132135 }