| 1 | pub fn mask_conversation_id(conversation_id: &str) -> String { |
| 2 | let Some((prefix, rest)) = conversation_id.split_once(':') else { |
| 3 | return "xxx".into(); |
| 4 | }; |
| 5 | if prefix == "48" { |
| 6 | return conversation_id.to_owned(); |
| 7 | } |
| 8 | let suffix = rest.find('@').map(|at| &rest[at..]).unwrap_or_default(); |
| 9 | format!("{prefix}:xxx{suffix}") |
| 10 | } |
| 11 | |
| 12 | #[cfg(test)] |
| 13 | mod tests { |
| 14 | use super::*; |
| 15 | |
| 16 | #[test] |
| 17 | fn keeps_kind_and_domain_only() { |
| 18 | assert_eq!( |
| 19 | mask_conversation_id("19:abc_def@unq.gbl.spaces"), |
| 20 | "19:xxx@unq.gbl.spaces" |
| 21 | ); |
| 22 | assert_eq!( |
| 23 | mask_conversation_id("19:meeting_abc@thread.v2"), |
| 24 | "19:xxx@thread.v2" |
| 25 | ); |
| 26 | assert_eq!(mask_conversation_id("19:abc"), "19:xxx"); |
| 27 | } |
| 28 | |
| 29 | #[test] |
| 30 | fn notes_chat_is_not_personal() { |
| 31 | assert_eq!(mask_conversation_id("48:notes"), "48:notes"); |
| 32 | } |
| 33 | |
| 34 | #[test] |
| 35 | fn unknown_shapes_are_fully_masked() { |
| 36 | assert_eq!(mask_conversation_id("opaque"), "xxx"); |
| 37 | } |
| 38 | } |