| @@ -71,7 +71,7 @@ use weechat::{ |
| 71 | 71 | }; |
| 72 | 72 | |
| 73 | 73 | use crate::{ |
| 74 | | config::Config, |
| 74 | config::{Config, RedactionStyle}, |
| 75 | 75 | connection::{Connection, TYPING_NOTICE_TIMEOUT}, |
| 76 | 76 | render::{Render, RenderedEvent}, |
| 77 | 77 | PLUGIN_NAME, |
| @@ -319,16 +319,6 @@ impl MatrixRoom { |
| 319 | 319 | |
| 320 | 320 | let event_id_tag = |
| 321 | 321 | Cow::from(format!("{}_id_{}", PLUGIN_NAME, event.redacts)); |
| 322 | | let event_type_tag = Cow::from("matrix_redacted"); |
| 323 | | |
| 324 | | let predicate = |l: &BufferLine| { |
| 325 | | let tags = l.tags(); |
| 326 | | tags.contains(&event_id_tag) && !tags.contains(&event_type_tag) |
| 327 | | }; |
| 328 | | |
| 329 | | let mut lines = buffer.lines(); |
| 330 | | let first_line = lines.rfind(predicate); |
| 331 | | |
| 332 | 322 | let tag = Cow::from("matrix_redacted"); |
| 333 | 323 | |
| 334 | 324 | let reason = if let Some(r) = &event.content.reason { |
| @@ -336,7 +326,6 @@ impl MatrixRoom { |
| 336 | 326 | } else { |
| 337 | 327 | "".to_owned() |
| 338 | 328 | }; |
| 339 | | |
| 340 | 329 | let redaction_message = format!( |
| 341 | 330 | "{}<{}Message redacted by: {}{}{}>{}", |
| 342 | 331 | Weechat::color("chat_delimiters"), |
| @@ -347,6 +336,14 @@ impl MatrixRoom { |
| 347 | 336 | Weechat::color("reset"), |
| 348 | 337 | ); |
| 349 | 338 | |
| 339 | let redaction_style = self.config.borrow().look().redaction_style(); |
| 340 | |
| 341 | let predicate = |l: &BufferLine| { |
| 342 | let tags = l.tags(); |
| 343 | tags.contains(&event_id_tag) |
| 344 | && !tags.contains(&Cow::from("matrix_redacted")) |
| 345 | }; |
| 346 | |
| 350 | 347 | let strike_through = |string: Cow<str>| { |
| 351 | 348 | Weechat::remove_color(&string) |
| 352 | 349 | .graphemes(true) |
| @@ -355,24 +352,22 @@ impl MatrixRoom { |
| 355 | 352 | .join("") |
| 356 | 353 | }; |
| 357 | 354 | |
| 358 | | let redact_first_line = |message: Cow<str>| { |
| 359 | | if false { |
| 360 | | redaction_message.clone() |
| 361 | | } else if false { |
| 355 | let redact_first_line = |message: Cow<str>| match redaction_style { |
| 356 | RedactionStyle::Delete => redaction_message.clone(), |
| 357 | RedactionStyle::Notice => { |
| 362 | 358 | format!("{} {}", message, redaction_message) |
| 363 | | } else { |
| 359 | } |
| 360 | RedactionStyle::StrikeThrough => { |
| 364 | 361 | format!("{} {}", strike_through(message), redaction_message) |
| 365 | 362 | } |
| 366 | 363 | }; |
| 367 | 364 | |
| 368 | | let redact_string = |message: Cow<str>| { |
| 369 | | if false { |
| 370 | | redaction_message.clone() |
| 371 | | } else if false { |
| 365 | let redact_string = |message: Cow<str>| match redaction_style { |
| 366 | RedactionStyle::Delete => redaction_message.clone(), |
| 367 | RedactionStyle::Notice => { |
| 372 | 368 | format!("{} {}", message, redaction_message) |
| 373 | | } else { |
| 374 | | strike_through(message) |
| 375 | 369 | } |
| 370 | RedactionStyle::StrikeThrough => strike_through(message), |
| 376 | 371 | }; |
| 377 | 372 | |
| 378 | 373 | fn modify_line<F>(line: BufferLine, tag: Cow<str>, redaction_func: F) |
| @@ -390,6 +385,9 @@ impl MatrixRoom { |
| 390 | 385 | line.set_tags(&tags); |
| 391 | 386 | }; |
| 392 | 387 | |
| 388 | let mut lines = buffer.lines(); |
| 389 | let first_line = lines.rfind(predicate); |
| 390 | |
| 393 | 391 | if let Some(line) = first_line { |
| 394 | 392 | modify_line(line, tag.clone(), redact_first_line); |
| 395 | 393 | } else { |