| @@ -51,6 +51,7 @@ use futures::executor::block_on; |
| 51 | use tracing::{debug, error, trace}; |
51 | use tracing::{debug, error, trace}; |
| 52 | |
52 | |
| 53 | use crate::{ |
53 | use crate::{ |
| |
54 | config::Config, |
| 54 | connection::{Connection, TYPING_NOTICE_TIMEOUT}, |
55 | connection::{Connection, TYPING_NOTICE_TIMEOUT}, |
| 55 | render::{render_membership, Render, RenderedEvent}, |
56 | render::{render_membership, Render, RenderedEvent}, |
| 56 | }; |
57 | }; |
| @@ -117,6 +118,7 @@ struct MatrixRoom { |
| 117 | own_user_id: Rc<UserId>, |
118 | own_user_id: Rc<UserId>, |
| 118 | room: Arc<RwLock<Room>>, |
119 | room: Arc<RwLock<Room>>, |
| 119 | |
120 | |
| |
121 | config: Rc<RefCell<Config>>, |
| 120 | connection: Rc<RefCell<Option<Connection>>>, |
122 | connection: Rc<RefCell<Option<Connection>>>, |
| 121 | |
123 | |
| 122 | typing_notice_time: Rc<RefCell<Option<Instant>>>, |
124 | typing_notice_time: Rc<RefCell<Option<Instant>>>, |
| @@ -157,7 +159,9 @@ impl MatrixRoom { |
| 157 | match c.send_message(&self.room_id, content, Some(uuid)).await { |
159 | match c.send_message(&self.room_id, content, Some(uuid)).await { |
| 158 | // TODO the event id is in the response, this needs to end up in |
160 | // TODO the event id is in the response, this needs to end up in |
| 159 | // a tag. |
161 | // a tag. |
| 160 | Ok(_r) => self.replace_local_echo(buffer, uuid), |
162 | Ok(_r) => { |
| |
163 | self.replace_local_echo(buffer, uuid); |
| |
164 | } |
| 161 | Err(_e) => (), |
165 | Err(_e) => (), |
| 162 | } |
166 | } |
| 163 | } else { |
167 | } else { |
| @@ -175,7 +179,7 @@ impl MatrixRoom { |
| 175 | uuid: Uuid, |
179 | uuid: Uuid, |
| 176 | content: &AnyMessageEventContent, |
180 | content: &AnyMessageEventContent, |
| 177 | ) { |
181 | ) { |
| 178 | if true { |
182 | if self.config.borrow().look().local_echo() { |
| 179 | if let AnyMessageEventContent::RoomMessage( |
183 | if let AnyMessageEventContent::RoomMessage( |
| 180 | MessageEventContent::Text(c), |
184 | MessageEventContent::Text(c), |
| 181 | ) = content |
185 | ) = content |
| @@ -211,7 +215,17 @@ impl MatrixRoom { |
| 211 | } |
215 | } |
| 212 | } |
216 | } |
| 213 | |
217 | |
| 214 | pub fn replace_local_echo(&self, buffer_handle: BufferHandle, uuid: Uuid) { |
218 | /// Replace the local echo line with a normal line for the event content |
| |
219 | /// with the given UUID. |
| |
220 | /// |
| |
221 | /// If no content with the given UUID was found in the local echo queue |
| |
222 | /// false is returned, if the event was successfully found and replaced true |
| |
223 | /// is returned. |
| |
224 | pub fn replace_local_echo( |
| |
225 | &self, |
| |
226 | buffer_handle: BufferHandle, |
| |
227 | uuid: Uuid, |
| |
228 | ) -> bool { |
| 215 | let uuid_tag = Cow::from(format!("matrix_echo_{}", uuid.to_string())); |
229 | let uuid_tag = Cow::from(format!("matrix_echo_{}", uuid.to_string())); |
| 216 | |
230 | |
| 217 | let line_contains_uuid = |l: &BufferLine| l.tags().contains(&uuid_tag); |
231 | let line_contains_uuid = |l: &BufferLine| l.tags().contains(&uuid_tag); |
| @@ -220,7 +234,8 @@ impl MatrixRoom { |
| 220 | { |
234 | { |
| 221 | let content = match content { |
235 | let content = match content { |
| 222 | MessageEventContent::Text(c) => c.render(&()), |
236 | MessageEventContent::Text(c) => c.render(&()), |
| 223 | _ => return, |
237 | // TODO support more message types. |
| |
238 | _ => return false, |
| 224 | }; |
239 | }; |
| 225 | |
240 | |
| 226 | if let Ok(buffer) = buffer_handle.upgrade() { |
241 | if let Ok(buffer) = buffer_handle.upgrade() { |
| @@ -237,6 +252,10 @@ impl MatrixRoom { |
| 237 | first_line = lines.next_back().filter(line_contains_uuid); |
252 | first_line = lines.next_back().filter(line_contains_uuid); |
| 238 | } |
253 | } |
| 239 | } |
254 | } |
| |
255 | |
| |
256 | true |
| |
257 | } else { |
| |
258 | false |
| 240 | } |
259 | } |
| 241 | } |
260 | } |
| 242 | } |
261 | } |
| @@ -244,6 +263,7 @@ impl MatrixRoom { |
| 244 | impl RoomBuffer { |
263 | impl RoomBuffer { |
| 245 | pub fn new( |
264 | pub fn new( |
| 246 | connection: &Rc<RefCell<Option<Connection>>>, |
265 | connection: &Rc<RefCell<Option<Connection>>>, |
| |
266 | config: Rc<RefCell<Config>>, |
| 247 | room: Arc<RwLock<Room>>, |
267 | room: Arc<RwLock<Room>>, |
| 248 | homeserver: &Url, |
268 | homeserver: &Url, |
| 249 | room_id: RoomId, |
269 | room_id: RoomId, |
| @@ -255,6 +275,7 @@ impl RoomBuffer { |
| 255 | connection: connection.clone(), |
275 | connection: connection.clone(), |
| 256 | typing_notice_time: Rc::new(RefCell::new(None)), |
276 | typing_notice_time: Rc::new(RefCell::new(None)), |
| 257 | typing_in_flight: Rc::new(Mutex::new(())), |
277 | typing_in_flight: Rc::new(Mutex::new(())), |
| |
278 | config, |
| 258 | room, |
279 | room, |
| 259 | own_user_id: Rc::new(own_user_id.to_owned()), |
280 | own_user_id: Rc::new(own_user_id.to_owned()), |
| 260 | members: Rc::new(RefCell::new(HashMap::new())), |
281 | members: Rc::new(RefCell::new(HashMap::new())), |
| @@ -286,6 +307,7 @@ impl RoomBuffer { |
| 286 | pub fn restore( |
307 | pub fn restore( |
| 287 | room: Arc<RwLock<Room>>, |
308 | room: Arc<RwLock<Room>>, |
| 288 | connection: &Rc<RefCell<Option<Connection>>>, |
309 | connection: &Rc<RefCell<Option<Connection>>>, |
| |
310 | config: Rc<RefCell<Config>>, |
| 289 | homeserver: &Url, |
311 | homeserver: &Url, |
| 290 | ) -> Self { |
312 | ) -> Self { |
| 291 | let room_clone = room.clone(); |
313 | let room_clone = room.clone(); |
| @@ -295,6 +317,7 @@ impl RoomBuffer { |
| 295 | |
317 | |
| 296 | let room_buffer = RoomBuffer::new( |
318 | let room_buffer = RoomBuffer::new( |
| 297 | connection, |
319 | connection, |
| |
320 | config, |
| 298 | room_clone, |
321 | room_clone, |
| 299 | homeserver, |
322 | homeserver, |
| 300 | room_id, |
323 | room_id, |
| @@ -862,9 +885,12 @@ impl RoomBuffer { |
| 862 | pub fn handle_room_message(&self, event: &AnySyncMessageEvent) { |
885 | pub fn handle_room_message(&self, event: &AnySyncMessageEvent) { |
| 863 | if let Some(id) = &event.unsigned().transaction_id { |
886 | if let Some(id) = &event.unsigned().transaction_id { |
| 864 | if let Ok(id) = Uuid::parse_str(id) { |
887 | if let Ok(id) = Uuid::parse_str(id) { |
| 865 | self.inner |
888 | if self |
| 866 | .replace_local_echo(self.buffer_handle.clone(), id); |
889 | .inner |
| 867 | return; |
890 | .replace_local_echo(self.buffer_handle.clone(), id) |
| |
891 | { |
| |
892 | return; |
| |
893 | } |
| 868 | } |
894 | } |
| 869 | } |
895 | } |
| 870 | |
896 | |