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