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