Commit 8966644f6e
Unregistered key
Layout: unified · split
README.md +1 −1
| @@ -74,7 +74,7 @@ two other TUI clients and Element Web: | |||
| 74 | | New user registration | ❌ | ❌ | ❌ | ✔️ | | 74 | | New user registration | ❌ | ❌ | ❌ | ✔️ | |
| 75 | | VOIP | ❌ | ❌ | ❌ | ✔️ | | 75 | | VOIP | ❌ | ❌ | ❌ | ✔️ | |
| 76 | | Reactions | ❌ ([#2]) | ✔️ | ❌ | ✔️ | | 76 | | Reactions | ❌ ([#2]) | ✔️ | ❌ | ✔️ | |
| 77 | | Message editing | ❌ ([#4]) | ✔️ | ❌ | ✔️ | | 77 | | Message editing | ✔️ | ✔️ | ❌ | ✔️ | |
| 78 | | Room upgrades | ❌ | ✔️ | ❌ | ✔️ | | 78 | | Room upgrades | ❌ | ✔️ | ❌ | ✔️ | |
| 79 | | Localisations | ❌ | 1 | ❌ | 44 | | 79 | | Localisations | ❌ | 1 | ❌ | 44 | |
| 80 | | SSO Support | ❌ | ✔️ | ✔️ | ✔️ | | 80 | | SSO Support | ❌ | ✔️ | ✔️ | ✔️ | |
src/base.rs +88 −5
| @@ -8,7 +8,20 @@ use tracing::warn; | |||
| 8 | 8 | ||
| 9 | use matrix_sdk::{ | 9 | use matrix_sdk::{ |
| 10 | encryption::verification::SasVerification, | 10 | encryption::verification::SasVerification, |
| 11 | ruma::{OwnedRoomId, OwnedUserId, RoomId}, | 11 | ruma::{ |
| 12 | events::room::message::{ | ||
| 13 | OriginalRoomMessageEvent, | ||
| 14 | Relation, | ||
| 15 | Replacement, | ||
| 16 | RoomMessageEvent, | ||
| 17 | RoomMessageEventContent, | ||
| 18 | }, | ||
| 19 | EventId, | ||
| 20 | OwnedEventId, | ||
| 21 | OwnedRoomId, | ||
| 22 | OwnedUserId, | ||
| 23 | RoomId, | ||
| 24 | }, | ||
| 12 | }; | 25 | }; |
| 13 | 26 | ||
| 14 | use modalkit::{ | 27 | use modalkit::{ |
| @@ -41,7 +54,7 @@ use modalkit::{ | |||
| 41 | }; | 54 | }; |
| 42 | 55 | ||
| 43 | use crate::{ | 56 | use crate::{ |
| 44 | message::{Message, Messages}, | 57 | message::{Message, MessageEvent, MessageKey, MessageTimeStamp, Messages}, |
| 45 | worker::Requester, | 58 | worker::Requester, |
| 46 | ApplicationSettings, | 59 | ApplicationSettings, |
| 47 | }; | 60 | }; |
| @@ -61,9 +74,22 @@ pub enum VerifyAction { | |||
| 61 | 74 | ||
| 62 | #[derive(Clone, Debug, Eq, PartialEq)] | 75 | #[derive(Clone, Debug, Eq, PartialEq)] |
| 63 | pub enum MessageAction { | 76 | pub enum MessageAction { |
| 77 | /// Cance the current reply or edit. | ||
| 64 | Cancel, | 78 | Cancel, |
| 79 | |||
| 80 | /// Download an attachment to the given path. | ||
| 81 | /// | ||
| 82 | /// The [bool] argument controls whether to overwrite any already existing file at the | ||
| 83 | /// destination path. | ||
| 65 | Download(Option<String>, bool), | 84 | Download(Option<String>, bool), |
| 85 | |||
| 86 | /// Edit a sent message. | ||
| 87 | Edit, | ||
| 88 | |||
| 89 | /// Redact a message. | ||
| 66 | Redact(Option<String>), | 90 | Redact(Option<String>), |
| 91 | |||
| 92 | /// Reply to a message. | ||
| 67 | Reply, | 93 | Reply, |
| 68 | } | 94 | } |
| 69 | 95 | ||
| @@ -251,13 +277,72 @@ pub enum RoomFetchStatus { | |||
| 251 | #[derive(Default)] | 277 | #[derive(Default)] |
| 252 | pub struct RoomInfo { | 278 | pub struct RoomInfo { |
| 253 | pub name: Option<String>, | 279 | pub name: Option<String>, |
| 280 | |||
| 281 | pub keys: HashMap<OwnedEventId, MessageKey>, | ||
| 254 | pub messages: Messages, | 282 | pub messages: Messages, |
| 283 | |||
| 255 | pub fetch_id: RoomFetchStatus, | 284 | pub fetch_id: RoomFetchStatus, |
| 256 | pub fetch_last: Option<Instant>, | 285 | pub fetch_last: Option<Instant>, |
| 257 | pub users_typing: Option<(Instant, Vec<OwnedUserId>)>, | 286 | pub users_typing: Option<(Instant, Vec<OwnedUserId>)>, |
| 258 | } | 287 | } |
| 259 | 288 | ||
| 260 | impl RoomInfo { | 289 | impl RoomInfo { |
| 290 | pub fn get_event(&self, event_id: &EventId) -> Option<&Message> { | ||
| 291 | self.messages.get(self.keys.get(event_id)?) | ||
| 292 | } | ||
| 293 | |||
| 294 | pub fn insert_edit(&mut self, msg: Replacement) { | ||
| 295 | let event_id = msg.event_id; | ||
| 296 | let new_content = msg.new_content; | ||
| 297 | |||
| 298 | let key = if let Some(k) = self.keys.get(&event_id) { | ||
| 299 | k | ||
| 300 | } else { | ||
| 301 | return; | ||
| 302 | }; | ||
| 303 | |||
| 304 | let msg = if let Some(msg) = self.messages.get_mut(key) { | ||
| 305 | msg | ||
| 306 | } else { | ||
| 307 | return; | ||
| 308 | }; | ||
| 309 | |||
| 310 | match &mut msg.event { | ||
| 311 | MessageEvent::Original(orig) => { | ||
| 312 | orig.content = *new_content; | ||
| 313 | }, | ||
| 314 | MessageEvent::Local(content) => { | ||
| 315 | *content = new_content; | ||
| 316 | }, | ||
| 317 | MessageEvent::Redacted(_) => { | ||
| 318 | return; | ||
| 319 | }, | ||
| 320 | } | ||
| 321 | } | ||
| 322 | |||
| 323 | pub fn insert_message(&mut self, msg: RoomMessageEvent) { | ||
| 324 | let event_id = msg.event_id().to_owned(); | ||
| 325 | let key = (msg.origin_server_ts().into(), event_id.clone()); | ||
| 326 | |||
| 327 | self.keys.insert(event_id.clone(), key.clone()); | ||
| 328 | self.messages.insert(key, msg.into()); | ||
| 329 | |||
| 330 | // Remove any echo. | ||
| 331 | let key = (MessageTimeStamp::LocalEcho, event_id); | ||
| 332 | let _ = self.messages.remove(&key); | ||
| 333 | } | ||
| 334 | |||
| 335 | pub fn insert(&mut self, msg: RoomMessageEvent) { | ||
| 336 | match msg { | ||
| 337 | RoomMessageEvent::Original(OriginalRoomMessageEvent { | ||
| 338 | content: | ||
| 339 | RoomMessageEventContent { relates_to: Some(Relation::Replacement(repl)), .. }, | ||
| 340 | .. | ||
| 341 | }) => self.insert_edit(repl), | ||
| 342 | _ => self.insert_message(msg), | ||
| 343 | } | ||
| 344 | } | ||
| 345 | |||
| 261 | fn recently_fetched(&self) -> bool { | 346 | fn recently_fetched(&self) -> bool { |
| 262 | self.fetch_last.map_or(false, |i| i.elapsed() < ROOM_FETCH_DEBOUNCE) | 347 | self.fetch_last.map_or(false, |i| i.elapsed() < ROOM_FETCH_DEBOUNCE) |
| 263 | } | 348 | } |
| @@ -388,9 +473,7 @@ impl ChatStore { | |||
| 388 | match res { | 473 | match res { |
| 389 | Ok((fetch_id, msgs)) => { | 474 | Ok((fetch_id, msgs)) => { |
| 390 | for msg in msgs.into_iter() { | 475 | for msg in msgs.into_iter() { |
| 391 | let key = (msg.origin_server_ts().into(), msg.event_id().to_owned()); | 476 | info.insert(msg); |
| 392 | |||
| 393 | info.messages.insert(key, Message::from(msg)); | ||
| 394 | } | 477 | } |
| 395 | 478 | ||
| 396 | info.fetch_id = | 479 | info.fetch_id = |
src/commands.rs +12
| @@ -144,6 +144,17 @@ fn iamb_cancel(desc: CommandDescription, ctx: &mut ProgContext) -> ProgResult { | |||
| 144 | return Ok(step); | 144 | return Ok(step); |
| 145 | } | 145 | } |
| 146 | 146 | ||
| 147 | fn iamb_edit(desc: CommandDescription, ctx: &mut ProgContext) -> ProgResult { | ||
| 148 | if !desc.arg.text.is_empty() { | ||
| 149 | return Result::Err(CommandError::InvalidArgument); | ||
| 150 | } | ||
| 151 | |||
| 152 | let ract = IambAction::from(MessageAction::Edit); | ||
| 153 | let step = CommandStep::Continue(ract.into(), ctx.context.take()); | ||
| 154 | |||
| 155 | return Ok(step); | ||
| 156 | } | ||
| 157 | |||
| 147 | fn iamb_redact(desc: CommandDescription, ctx: &mut ProgContext) -> ProgResult { | 158 | fn iamb_redact(desc: CommandDescription, ctx: &mut ProgContext) -> ProgResult { |
| 148 | let args = desc.arg.strings()?; | 159 | let args = desc.arg.strings()?; |
| 149 | 160 | ||
| @@ -269,6 +280,7 @@ fn add_iamb_commands(cmds: &mut ProgramCommands) { | |||
| 269 | cmds.add_command(ProgramCommand { names: vec!["cancel".into()], f: iamb_cancel }); | 280 | cmds.add_command(ProgramCommand { names: vec!["cancel".into()], f: iamb_cancel }); |
| 270 | cmds.add_command(ProgramCommand { names: vec!["dms".into()], f: iamb_dms }); | 281 | cmds.add_command(ProgramCommand { names: vec!["dms".into()], f: iamb_dms }); |
| 271 | cmds.add_command(ProgramCommand { names: vec!["download".into()], f: iamb_download }); | 282 | cmds.add_command(ProgramCommand { names: vec!["download".into()], f: iamb_download }); |
| 283 | cmds.add_command(ProgramCommand { names: vec!["edit".into()], f: iamb_edit }); | ||
| 272 | cmds.add_command(ProgramCommand { names: vec!["invite".into()], f: iamb_invite }); | 284 | cmds.add_command(ProgramCommand { names: vec!["invite".into()], f: iamb_invite }); |
| 273 | cmds.add_command(ProgramCommand { names: vec!["join".into()], f: iamb_join }); | 285 | cmds.add_command(ProgramCommand { names: vec!["join".into()], f: iamb_join }); |
| 274 | cmds.add_command(ProgramCommand { names: vec!["members".into()], f: iamb_members }); | 286 | cmds.add_command(ProgramCommand { names: vec!["members".into()], f: iamb_members }); |
src/tests.rs +15
| @@ -111,6 +111,18 @@ pub fn mock_message5() -> Message { | |||
| 111 | mock_room1_message(content, TEST_USER2.clone(), MSG4_KEY.clone()) | 111 | mock_room1_message(content, TEST_USER2.clone(), MSG4_KEY.clone()) |
| 112 | } | 112 | } |
| 113 | 113 | ||
| 114 | pub fn mock_keys() -> HashMap<OwnedEventId, MessageKey> { | ||
| 115 | let mut keys = HashMap::new(); | ||
| 116 | |||
| 117 | keys.insert(MSG1_EVID.clone(), MSG1_KEY.clone()); | ||
| 118 | keys.insert(MSG2_EVID.clone(), MSG2_KEY.clone()); | ||
| 119 | keys.insert(MSG3_EVID.clone(), MSG3_KEY.clone()); | ||
| 120 | keys.insert(MSG4_EVID.clone(), MSG4_KEY.clone()); | ||
| 121 | keys.insert(MSG5_EVID.clone(), MSG5_KEY.clone()); | ||
| 122 | |||
| 123 | keys | ||
| 124 | } | ||
| 125 | |||
| 114 | pub fn mock_messages() -> Messages { | 126 | pub fn mock_messages() -> Messages { |
| 115 | let mut messages = BTreeMap::new(); | 127 | let mut messages = BTreeMap::new(); |
| 116 | 128 | ||
| @@ -126,7 +138,10 @@ pub fn mock_messages() -> Messages { | |||
| 126 | pub fn mock_room() -> RoomInfo { | 138 | pub fn mock_room() -> RoomInfo { |
| 127 | RoomInfo { | 139 | RoomInfo { |
| 128 | name: Some("Watercooler Discussion".into()), | 140 | name: Some("Watercooler Discussion".into()), |
| 141 | |||
| 142 | keys: mock_keys(), | ||
| 129 | messages: mock_messages(), | 143 | messages: mock_messages(), |
| 144 | |||
| 130 | fetch_id: RoomFetchStatus::NotStarted, | 145 | fetch_id: RoomFetchStatus::NotStarted, |
| 131 | fetch_last: None, | 146 | fetch_last: None, |
| 132 | users_typing: None, | 147 | users_typing: None, |
src/windows/room/chat.rs +72 −14
| @@ -1,6 +1,7 @@ | |||
| 1 | use std::borrow::Cow; | 1 | use std::borrow::Cow; |
| 2 | use std::ffi::OsStr; | 2 | use std::ffi::OsStr; |
| 3 | use std::fs; | 3 | use std::fs; |
| 4 | use std::ops::Deref; | ||
| 4 | use std::path::{Path, PathBuf}; | 5 | use std::path::{Path, PathBuf}; |
| 5 | 6 | ||
| 6 | use matrix_sdk::{ | 7 | use matrix_sdk::{ |
| @@ -11,6 +12,8 @@ use matrix_sdk::{ | |||
| 11 | events::room::message::{ | 12 | events::room::message::{ |
| 12 | MessageType, | 13 | MessageType, |
| 13 | OriginalRoomMessageEvent, | 14 | OriginalRoomMessageEvent, |
| 15 | Relation, | ||
| 16 | Replacement, | ||
| 14 | RoomMessageEventContent, | 17 | RoomMessageEventContent, |
| 15 | TextMessageEventContent, | 18 | TextMessageEventContent, |
| 16 | }, | 19 | }, |
| @@ -82,6 +85,7 @@ pub struct ChatState { | |||
| 82 | focus: RoomFocus, | 85 | focus: RoomFocus, |
| 83 | 86 | ||
| 84 | reply_to: Option<MessageKey>, | 87 | reply_to: Option<MessageKey>, |
| 88 | editing: Option<MessageKey>, | ||
| 85 | } | 89 | } |
| 86 | 90 | ||
| 87 | impl ChatState { | 91 | impl ChatState { |
| @@ -104,6 +108,7 @@ impl ChatState { | |||
| 104 | focus: RoomFocus::MessageBar, | 108 | focus: RoomFocus::MessageBar, |
| 105 | 109 | ||
| 106 | reply_to: None, | 110 | reply_to: None, |
| 111 | editing: None, | ||
| 107 | } | 112 | } |
| 108 | } | 113 | } |
| 109 | 114 | ||
| @@ -120,6 +125,7 @@ impl ChatState { | |||
| 120 | 125 | ||
| 121 | fn reset(&mut self) -> EditRope { | 126 | fn reset(&mut self) -> EditRope { |
| 122 | self.reply_to = None; | 127 | self.reply_to = None; |
| 128 | self.editing = None; | ||
| 123 | self.tbox.reset() | 129 | self.tbox.reset() |
| 124 | } | 130 | } |
| 125 | 131 | ||
| @@ -145,6 +151,7 @@ impl ChatState { | |||
| 145 | match act { | 151 | match act { |
| 146 | MessageAction::Cancel => { | 152 | MessageAction::Cancel => { |
| 147 | self.reply_to = None; | 153 | self.reply_to = None; |
| 154 | self.editing = None; | ||
| 148 | 155 | ||
| 149 | Ok(None) | 156 | Ok(None) |
| 150 | }, | 157 | }, |
| @@ -224,6 +231,40 @@ impl ChatState { | |||
| 224 | 231 | ||
| 225 | Err(IambError::NoAttachment.into()) | 232 | Err(IambError::NoAttachment.into()) |
| 226 | }, | 233 | }, |
| 234 | MessageAction::Edit => { | ||
| 235 | if msg.sender != settings.profile.user_id { | ||
| 236 | let msg = "Cannot edit messages sent by someone else"; | ||
| 237 | let err = UIError::Failure(msg.into()); | ||
| 238 | |||
| 239 | return Err(err); | ||
| 240 | } | ||
| 241 | |||
| 242 | let ev = match &msg.event { | ||
| 243 | MessageEvent::Original(ev) => &ev.content, | ||
| 244 | MessageEvent::Local(ev) => ev.deref(), | ||
| 245 | _ => { | ||
| 246 | let msg = "Cannot edit a redacted message"; | ||
| 247 | let err = UIError::Failure(msg.into()); | ||
| 248 | |||
| 249 | return Err(err); | ||
| 250 | }, | ||
| 251 | }; | ||
| 252 | |||
| 253 | let text = match &ev.msgtype { | ||
| 254 | MessageType::Text(msg) => msg.body.as_str(), | ||
| 255 | _ => { | ||
| 256 | let msg = "Cannot edit a non-text message"; | ||
| 257 | let err = UIError::Failure(msg.into()); | ||
| 258 | |||
| 259 | return Err(err); | ||
| 260 | }, | ||
| 261 | }; | ||
| 262 | |||
| 263 | self.tbox.set_text(text); | ||
| 264 | self.editing = self.scrollback.get_key(info); | ||
| 265 | |||
| 266 | Ok(None) | ||
| 267 | }, | ||
| 227 | MessageAction::Redact(reason) => { | 268 | MessageAction::Redact(reason) => { |
| 228 | let room = store | 269 | let room = store |
| 229 | .application | 270 | .application |
| @@ -273,6 +314,7 @@ impl ChatState { | |||
| 273 | .get_joined_room(self.id()) | 314 | .get_joined_room(self.id()) |
| 274 | .ok_or(IambError::NotJoined)?; | 315 | .ok_or(IambError::NotJoined)?; |
| 275 | let info = store.application.rooms.entry(self.id().to_owned()).or_default(); | 316 | let info = store.application.rooms.entry(self.id().to_owned()).or_default(); |
| 317 | let mut show_echo = true; | ||
| 276 | 318 | ||
| 277 | let (event_id, msg) = match act { | 319 | let (event_id, msg) = match act { |
| 278 | SendAction::Submit => { | 320 | SendAction::Submit => { |
| @@ -287,7 +329,14 @@ impl ChatState { | |||
| 287 | 329 | ||
| 288 | let mut msg = RoomMessageEventContent::new(msg); | 330 | let mut msg = RoomMessageEventContent::new(msg); |
| 289 | 331 | ||
| 290 | if let Some(m) = self.get_reply_to(info) { | 332 | if let Some((_, event_id)) = &self.editing { |
| 333 | msg.relates_to = Some(Relation::Replacement(Replacement::new( | ||
| 334 | event_id.clone(), | ||
| 335 | Box::new(msg.clone()), | ||
| 336 | ))); | ||
| 337 | |||
| 338 | show_echo = false; | ||
| 339 | } else if let Some(m) = self.get_reply_to(info) { | ||
| 291 | // XXX: Switch to RoomMessageEventContent::reply() once it's stable? | 340 | // XXX: Switch to RoomMessageEventContent::reply() once it's stable? |
| 292 | msg = msg.make_reply_to(m); | 341 | msg = msg.make_reply_to(m); |
| 293 | } | 342 | } |
| @@ -327,11 +376,13 @@ impl ChatState { | |||
| 327 | }, | 376 | }, |
| 328 | }; | 377 | }; |
| 329 | 378 | ||
| 330 | let user = store.application.settings.profile.user_id.clone(); | 379 | if show_echo { |
| 331 | let key = (MessageTimeStamp::LocalEcho, event_id); | 380 | let user = store.application.settings.profile.user_id.clone(); |
| 332 | let msg = MessageEvent::Local(msg.into()); | 381 | let key = (MessageTimeStamp::LocalEcho, event_id); |
| 333 | let msg = Message::new(msg, user, MessageTimeStamp::LocalEcho); | 382 | let msg = MessageEvent::Local(msg.into()); |
| 334 | info.messages.insert(key, msg); | 383 | let msg = Message::new(msg, user, MessageTimeStamp::LocalEcho); |
| 384 | info.messages.insert(key, msg); | ||
| 385 | } | ||
| 335 | 386 | ||
| 336 | // Jump to the end of the scrollback to show the message. | 387 | // Jump to the end of the scrollback to show the message. |
| 337 | self.scrollback.goto_latest(); | 388 | self.scrollback.goto_latest(); |
| @@ -413,6 +464,7 @@ impl WindowOps<IambInfo> for ChatState { | |||
| 413 | focus: self.focus, | 464 | focus: self.focus, |
| 414 | 465 | ||
| 415 | reply_to: None, | 466 | reply_to: None, |
| 467 | editing: None, | ||
| 416 | } | 468 | } |
| 417 | } | 469 | } |
| 418 | 470 | ||
| @@ -601,14 +653,20 @@ impl<'a> StatefulWidget for Chat<'a> { | |||
| 601 | let scrollback = Scrollback::new(self.store).focus(scrollback_focused); | 653 | let scrollback = Scrollback::new(self.store).focus(scrollback_focused); |
| 602 | scrollback.render(scrollarea, buf, &mut state.scrollback); | 654 | scrollback.render(scrollarea, buf, &mut state.scrollback); |
| 603 | 655 | ||
| 604 | let desc_spans = state.reply_to.as_ref().and_then(|k| { | 656 | let desc_spans = match (&state.editing, &state.reply_to) { |
| 605 | let room = self.store.application.rooms.get(state.id())?; | 657 | (None, None) => None, |
| 606 | let msg = room.messages.get(k)?; | 658 | (Some(_), _) => Some(Spans::from("Editing message")), |
| 607 | let user = self.store.application.settings.get_user_span(msg.sender.as_ref()); | 659 | (_, Some(_)) => { |
| 608 | let spans = Spans(vec![Span::from("Replying to "), user]); | 660 | state.reply_to.as_ref().and_then(|k| { |
| 609 | 661 | let room = self.store.application.rooms.get(state.id())?; | |
| 610 | spans.into() | 662 | let msg = room.messages.get(k)?; |
| 611 | }); | 663 | let user = self.store.application.settings.get_user_span(msg.sender.as_ref()); |
| 664 | let spans = Spans(vec![Span::from("Replying to "), user]); | ||
| 665 | |||
| 666 | spans.into() | ||
| 667 | }) | ||
| 668 | }, | ||
| 669 | }; | ||
| 612 | 670 | ||
| 613 | if let Some(desc_spans) = desc_spans { | 671 | if let Some(desc_spans) = desc_spans { |
| 614 | Paragraph::new(desc_spans).render(descarea, buf); | 672 | Paragraph::new(desc_spans).render(descarea, buf); |
src/worker.rs +8 −18
| @@ -58,7 +58,7 @@ use modalkit::editing::action::{EditInfo, InfoMessage, UIError}; | |||
| 58 | 58 | ||
| 59 | use crate::{ | 59 | use crate::{ |
| 60 | base::{AsyncProgramStore, IambError, IambResult, SetRoomField, VerifyAction}, | 60 | base::{AsyncProgramStore, IambError, IambResult, SetRoomField, VerifyAction}, |
| 61 | message::{Message, MessageFetchResult, MessageTimeStamp}, | 61 | message::MessageFetchResult, |
| 62 | ApplicationSettings, | 62 | ApplicationSettings, |
| 63 | }; | 63 | }; |
| 64 | 64 | ||
| @@ -536,15 +536,7 @@ impl ClientWorker { | |||
| 536 | let mut locked = store.lock().await; | 536 | let mut locked = store.lock().await; |
| 537 | let mut info = locked.application.get_room_info(room_id.to_owned()); | 537 | let mut info = locked.application.get_room_info(room_id.to_owned()); |
| 538 | info.name = room_name; | 538 | info.name = room_name; |
| 539 | 539 | info.insert(ev.into_full_event(room_id.to_owned())); | |
| 540 | let event_id = ev.event_id().to_owned(); | ||
| 541 | let key = (ev.origin_server_ts().into(), event_id.clone()); | ||
| 542 | let msg = Message::from(ev.into_full_event(room_id.to_owned())); | ||
| 543 | info.messages.insert(key, msg); | ||
| 544 | |||
| 545 | // Remove the echo. | ||
| 546 | let key = (MessageTimeStamp::LocalEcho, event_id); | ||
| 547 | let _ = info.messages.remove(&key); | ||
| 548 | } | 540 | } |
| 549 | }, | 541 | }, |
| 550 | ); | 542 | ); |
| @@ -561,17 +553,15 @@ impl ClientWorker { | |||
| 561 | let mut locked = store.lock().await; | 553 | let mut locked = store.lock().await; |
| 562 | let info = locked.application.get_room_info(room_id.to_owned()); | 554 | let info = locked.application.get_room_info(room_id.to_owned()); |
| 563 | 555 | ||
| 564 | // XXX: need to store a mapping of EventId -> MessageKey somewhere | 556 | let key = if let Some(k) = info.keys.get(&ev.redacts) { |
| 565 | // to avoid having to iterate over the messages here. | 557 | k |
| 566 | for ((_, id), msg) in info.messages.iter_mut().rev() { | 558 | } else { |
| 567 | if id != &ev.redacts { | 559 | return; |
| 568 | continue; | 560 | }; |
| 569 | } | ||
| 570 | 561 | ||
| 562 | if let Some(msg) = info.messages.get_mut(key) { | ||
| 571 | let ev = SyncRoomRedactionEvent::Original(ev); | 563 | let ev = SyncRoomRedactionEvent::Original(ev); |
| 572 | msg.event.redact(ev, room_version); | 564 | msg.event.redact(ev, room_version); |
| 573 | |||
| 574 | break; | ||
| 575 | } | 565 | } |
| 576 | } | 566 | } |
| 577 | }, | 567 | }, |