Commit 56ec90523c
Unregistered key
Layout: unified · split
README.md +1 −1
| @@ -69,7 +69,7 @@ two other TUI clients and Element Web: | ||
| 69 | 69 | | Send formatted messages (markdown) | :x: ([#10]) | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | |
| 70 | 70 | | Rich Text Editor for formatted messages | :x: | :x: | :x: | :heavy_check_mark: | |
| 71 | 71 | | Display formatted messages | :x: ([#10]) | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | |
| 72 | | Redacting | :x: ([#5]) | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | | |
| 72 | | Redacting | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | | |
| 73 | 73 | | Multiple Matrix Accounts | :heavy_check_mark: | :x: | :heavy_check_mark: | :x: | |
| 74 | 74 | | New user registration | :x: | :x: | :x: | :heavy_check_mark: | |
| 75 | 75 | | VOIP | :x: | :x: | :x: | :heavy_check_mark: | |
src/base.rs +1
| @@ -63,6 +63,7 @@ pub enum VerifyAction { | ||
| 63 | 63 | pub enum MessageAction { |
| 64 | 64 | Cancel, |
| 65 | 65 | Download(Option<String>, bool), |
| 66 | Redact(Option<String>), | |
| 66 | 67 | Reply, |
| 67 | 68 | } |
| 68 | 69 | |
src/commands.rs +35
| @@ -144,6 +144,19 @@ fn iamb_cancel(desc: CommandDescription, ctx: &mut ProgContext) -> ProgResult { | ||
| 144 | 144 | return Ok(step); |
| 145 | 145 | } |
| 146 | 146 | |
| 147 | fn iamb_redact(desc: CommandDescription, ctx: &mut ProgContext) -> ProgResult { | |
| 148 | let args = desc.arg.strings()?; | |
| 149 | ||
| 150 | if args.len() > 1 { | |
| 151 | return Result::Err(CommandError::InvalidArgument); | |
| 152 | } | |
| 153 | ||
| 154 | let ract = IambAction::from(MessageAction::Redact(args.into_iter().next())); | |
| 155 | let step = CommandStep::Continue(ract.into(), ctx.context.take()); | |
| 156 | ||
| 157 | return Ok(step); | |
| 158 | } | |
| 159 | ||
| 147 | 160 | fn iamb_reply(desc: CommandDescription, ctx: &mut ProgContext) -> ProgResult { |
| 148 | 161 | if !desc.arg.text.is_empty() { |
| 149 | 162 | return Result::Err(CommandError::InvalidArgument); |
| @@ -259,6 +272,7 @@ fn add_iamb_commands(cmds: &mut ProgramCommands) { | ||
| 259 | 272 | cmds.add_command(ProgramCommand { names: vec!["invite".into()], f: iamb_invite }); |
| 260 | 273 | cmds.add_command(ProgramCommand { names: vec!["join".into()], f: iamb_join }); |
| 261 | 274 | cmds.add_command(ProgramCommand { names: vec!["members".into()], f: iamb_members }); |
| 275 | cmds.add_command(ProgramCommand { names: vec!["redact".into()], f: iamb_redact }); | |
| 262 | 276 | cmds.add_command(ProgramCommand { names: vec!["reply".into()], f: iamb_reply }); |
| 263 | 277 | cmds.add_command(ProgramCommand { names: vec!["rooms".into()], f: iamb_rooms }); |
| 264 | 278 | cmds.add_command(ProgramCommand { names: vec!["set".into()], f: iamb_set }); |
| @@ -429,4 +443,25 @@ mod tests { | ||
| 429 | 443 | let res = cmds.input_cmd("invite @user:example.com", ctx.clone()); |
| 430 | 444 | assert_eq!(res, Err(CommandError::InvalidArgument)); |
| 431 | 445 | } |
| 446 | ||
| 447 | #[test] | |
| 448 | fn test_cmd_redact() { | |
| 449 | let mut cmds = setup_commands(); | |
| 450 | let ctx = ProgramContext::default(); | |
| 451 | ||
| 452 | let res = cmds.input_cmd("redact", ctx.clone()).unwrap(); | |
| 453 | let act = IambAction::Message(MessageAction::Redact(None)); | |
| 454 | assert_eq!(res, vec![(act.into(), ctx.clone())]); | |
| 455 | ||
| 456 | let res = cmds.input_cmd("redact Removed", ctx.clone()).unwrap(); | |
| 457 | let act = IambAction::Message(MessageAction::Redact(Some("Removed".into()))); | |
| 458 | assert_eq!(res, vec![(act.into(), ctx.clone())]); | |
| 459 | ||
| 460 | let res = cmds.input_cmd("redact \"Removed\"", ctx.clone()).unwrap(); | |
| 461 | let act = IambAction::Message(MessageAction::Redact(Some("Removed".into()))); | |
| 462 | assert_eq!(res, vec![(act.into(), ctx.clone())]); | |
| 463 | ||
| 464 | let res = cmds.input_cmd("redact Removed Removed", ctx.clone()); | |
| 465 | assert_eq!(res, Err(CommandError::InvalidArgument)); | |
| 466 | } | |
| 432 | 467 | } |
src/message.rs +38 −7
| @@ -11,16 +11,23 @@ use unicode_segmentation::UnicodeSegmentation; | ||
| 11 | 11 | use unicode_width::UnicodeWidthStr; |
| 12 | 12 | |
| 13 | 13 | use matrix_sdk::ruma::{ |
| 14 | events::room::message::{ | |
| 15 | MessageType, | |
| 16 | OriginalRoomMessageEvent, | |
| 17 | RedactedRoomMessageEvent, | |
| 18 | RoomMessageEvent, | |
| 19 | RoomMessageEventContent, | |
| 14 | events::{ | |
| 15 | room::{ | |
| 16 | message::{ | |
| 17 | MessageType, | |
| 18 | OriginalRoomMessageEvent, | |
| 19 | RedactedRoomMessageEvent, | |
| 20 | RoomMessageEvent, | |
| 21 | RoomMessageEventContent, | |
| 22 | }, | |
| 23 | redaction::SyncRoomRedactionEvent, | |
| 24 | }, | |
| 25 | Redact, | |
| 20 | 26 | }, |
| 21 | 27 | MilliSecondsSinceUnixEpoch, |
| 22 | 28 | OwnedEventId, |
| 23 | 29 | OwnedUserId, |
| 30 | RoomVersionId, | |
| 24 | 31 | UInt, |
| 25 | 32 | }; |
| 26 | 33 | |
| @@ -323,10 +330,34 @@ impl MessageEvent { | ||
| 323 | 330 | pub fn show(&self) -> Cow<'_, str> { |
| 324 | 331 | match self { |
| 325 | 332 | MessageEvent::Original(ev) => show_room_content(&ev.content), |
| 326 | MessageEvent::Redacted(_) => Cow::Borrowed("[redacted]"), | |
| 333 | MessageEvent::Redacted(ev) => { | |
| 334 | let reason = ev | |
| 335 | .unsigned | |
| 336 | .redacted_because | |
| 337 | .as_ref() | |
| 338 | .and_then(|e| e.as_original()) | |
| 339 | .and_then(|r| r.content.reason.as_ref()); | |
| 340 | ||
| 341 | if let Some(r) = reason { | |
| 342 | Cow::Owned(format!("[Redacted: {:?}]", r)) | |
| 343 | } else { | |
| 344 | Cow::Borrowed("[Redacted]") | |
| 345 | } | |
| 346 | }, | |
| 327 | 347 | MessageEvent::Local(content) => show_room_content(content), |
| 328 | 348 | } |
| 329 | 349 | } |
| 350 | ||
| 351 | pub fn redact(&mut self, redaction: SyncRoomRedactionEvent, version: &RoomVersionId) { | |
| 352 | match self { | |
| 353 | MessageEvent::Redacted(_) => return, | |
| 354 | MessageEvent::Local(_) => return, | |
| 355 | MessageEvent::Original(ev) => { | |
| 356 | let redacted = ev.clone().redact(redaction, version); | |
| 357 | *self = MessageEvent::Redacted(Box::new(redacted)); | |
| 358 | }, | |
| 359 | } | |
| 360 | } | |
| 330 | 361 | } |
| 331 | 362 | |
| 332 | 363 | fn show_room_content(content: &RoomMessageEventContent) -> Cow<'_, str> { |
src/windows/room/chat.rs +27
| @@ -224,6 +224,33 @@ impl ChatState { | ||
| 224 | 224 | |
| 225 | 225 | Err(IambError::NoAttachment.into()) |
| 226 | 226 | }, |
| 227 | MessageAction::Redact(reason) => { | |
| 228 | let room = store | |
| 229 | .application | |
| 230 | .worker | |
| 231 | .client | |
| 232 | .get_joined_room(self.id()) | |
| 233 | .ok_or(IambError::NotJoined)?; | |
| 234 | ||
| 235 | let event_id = match &msg.event { | |
| 236 | MessageEvent::Original(ev) => ev.event_id.clone(), | |
| 237 | MessageEvent::Local(_) => { | |
| 238 | self.scrollback.get_key(info).ok_or(IambError::NoSelectedMessage)?.1 | |
| 239 | }, | |
| 240 | MessageEvent::Redacted(_) => { | |
| 241 | let msg = ""; | |
| 242 | let err = UIError::Failure(msg.into()); | |
| 243 | ||
| 244 | return Err(err); | |
| 245 | }, | |
| 246 | }; | |
| 247 | ||
| 248 | let event_id = event_id.as_ref(); | |
| 249 | let reason = reason.as_deref(); | |
| 250 | let _ = room.redact(event_id, reason, None).await.map_err(IambError::from)?; | |
| 251 | ||
| 252 | Ok(None) | |
| 253 | }, | |
| 227 | 254 | MessageAction::Reply => { |
| 228 | 255 | self.reply_to = self.scrollback.get_key(info); |
| 229 | 256 | self.focus = RoomFocus::MessageBar; |
src/worker.rs +30
| @@ -35,6 +35,7 @@ use matrix_sdk::{ | ||
| 35 | 35 | room::{ |
| 36 | 36 | message::{MessageType, RoomMessageEventContent}, |
| 37 | 37 | name::RoomNameEventContent, |
| 38 | redaction::{OriginalSyncRoomRedactionEvent, SyncRoomRedactionEvent}, | |
| 38 | 39 | topic::RoomTopicEventContent, |
| 39 | 40 | }, |
| 40 | 41 | typing::SyncTypingEvent, |
| @@ -46,6 +47,7 @@ use matrix_sdk::{ | ||
| 46 | 47 | OwnedRoomId, |
| 47 | 48 | OwnedRoomOrAliasId, |
| 48 | 49 | OwnedUserId, |
| 50 | RoomVersionId, | |
| 49 | 51 | }, |
| 50 | 52 | Client, |
| 51 | 53 | DisplayName, |
| @@ -547,6 +549,34 @@ impl ClientWorker { | ||
| 547 | 549 | }, |
| 548 | 550 | ); |
| 549 | 551 | |
| 552 | let _ = self.client.add_event_handler( | |
| 553 | |ev: OriginalSyncRoomRedactionEvent, | |
| 554 | room: MatrixRoom, | |
| 555 | store: Ctx<AsyncProgramStore>| { | |
| 556 | async move { | |
| 557 | let room_id = room.room_id(); | |
| 558 | let room_info = room.clone_info(); | |
| 559 | let room_version = room_info.room_version().unwrap_or(&RoomVersionId::V1); | |
| 560 | ||
| 561 | let mut locked = store.lock().await; | |
| 562 | let info = locked.application.get_room_info(room_id.to_owned()); | |
| 563 | ||
| 564 | // XXX: need to store a mapping of EventId -> MessageKey somewhere | |
| 565 | // to avoid having to iterate over the messages here. | |
| 566 | for ((_, id), msg) in info.messages.iter_mut().rev() { | |
| 567 | if id != &ev.redacts { | |
| 568 | continue; | |
| 569 | } | |
| 570 | ||
| 571 | let ev = SyncRoomRedactionEvent::Original(ev); | |
| 572 | msg.event.redact(ev, room_version); | |
| 573 | ||
| 574 | break; | |
| 575 | } | |
| 576 | } | |
| 577 | }, | |
| 578 | ); | |
| 579 | ||
| 550 | 580 | let _ = self.client.add_event_handler( |
| 551 | 581 | |ev: OriginalSyncKeyVerificationStartEvent, |
| 552 | 582 | client: Client, |