From db567e06973803004a5fe55c2458b2d5980585da Mon Sep 17 00:00:00 2001 From: Chris Hogan Date: Mon, 6 Nov 2023 19:51:58 -0700 Subject: [PATCH 1/7] chore(emoji): fix for big numbers in messages --- kit/src/components/message/mod.rs | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/kit/src/components/message/mod.rs b/kit/src/components/message/mod.rs index e09a2c843dd..2cea6d7ea38 100644 --- a/kit/src/components/message/mod.rs +++ b/kit/src/components/message/mod.rs @@ -445,14 +445,23 @@ pub fn replace_emojis(input: &str) -> String { fn markdown(text: &str, emojis: bool) -> String { let txt = text.trim(); + let string_to_exclude = "0123456789#*".to_string(); if emojis { let r = replace_emojis(text); - if is_only_emojis(&r) { + // TODO: Watch this issue for a fix: https://github.com/open-i18n/rust-unic/issues/280 + // This is a temporary workaround for some characters rust-unic thinks are emojis + if !string_to_exclude.contains(&r) + && !r.to_string().contains("#") // for multiple # + && !r.to_string().contains("*") // for multiple # + && is_only_emojis(&r) + { return format!("{r}"); + } else { + return format!("{r}"); } - } else if is_only_emojis(txt) { - return format!("{txt}"); + // } else if is_only_emojis(txt) { + // return format!("{txt}"); } let mut options = Options::empty(); From 9f0665fbc4ff45cb8b2f6c1d26fd5af0948482a2 Mon Sep 17 00:00:00 2001 From: Chris Hogan Date: Mon, 6 Nov 2023 19:58:15 -0700 Subject: [PATCH 2/7] fix for multi digit numbers --- kit/src/components/message/mod.rs | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/kit/src/components/message/mod.rs b/kit/src/components/message/mod.rs index 2cea6d7ea38..dd39bcd1562 100644 --- a/kit/src/components/message/mod.rs +++ b/kit/src/components/message/mod.rs @@ -445,16 +445,15 @@ pub fn replace_emojis(input: &str) -> String { fn markdown(text: &str, emojis: bool) -> String { let txt = text.trim(); - let string_to_exclude = "0123456789#*".to_string(); if emojis { let r = replace_emojis(text); // TODO: Watch this issue for a fix: https://github.com/open-i18n/rust-unic/issues/280 - // This is a temporary workaround for some characters rust-unic thinks are emojis - if !string_to_exclude.contains(&r) - && !r.to_string().contains("#") // for multiple # - && !r.to_string().contains("*") // for multiple # - && is_only_emojis(&r) + // This is a temporary workaround for some characters unic-emoji-char thinks are emojis + if !r.to_string().contains("#") // for multiple # + && !r.to_string().contains("*") // for multiple # + && !r.chars().all(char::is_alphanumeric) // for any numbers, eg 1, 11, 111 + && is_only_emojis(&r) { return format!("{r}"); } else { From b164cb5e715f21a1d2a245a4a295586c16870346 Mon Sep 17 00:00:00 2001 From: Chris Hogan Date: Mon, 6 Nov 2023 20:02:14 -0700 Subject: [PATCH 3/7] cleanup --- kit/src/components/message/mod.rs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/kit/src/components/message/mod.rs b/kit/src/components/message/mod.rs index dd39bcd1562..b71465c6d66 100644 --- a/kit/src/components/message/mod.rs +++ b/kit/src/components/message/mod.rs @@ -447,7 +447,7 @@ fn markdown(text: &str, emojis: bool) -> String { let txt = text.trim(); if emojis { - let r = replace_emojis(text); + let r = replace_emojis(txt); // TODO: Watch this issue for a fix: https://github.com/open-i18n/rust-unic/issues/280 // This is a temporary workaround for some characters unic-emoji-char thinks are emojis if !r.to_string().contains("#") // for multiple # @@ -459,8 +459,6 @@ fn markdown(text: &str, emojis: bool) -> String { } else { return format!("{r}"); } - // } else if is_only_emojis(txt) { - // return format!("{txt}"); } let mut options = Options::empty(); From e56882d3f05a4a0d60901967c3ea1bb21aae2cae Mon Sep 17 00:00:00 2001 From: Chris Hogan Date: Mon, 6 Nov 2023 20:26:08 -0700 Subject: [PATCH 4/7] attempt to make clippy and sara ai happy --- kit/src/components/message/mod.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/kit/src/components/message/mod.rs b/kit/src/components/message/mod.rs index b71465c6d66..d6fb597e45d 100644 --- a/kit/src/components/message/mod.rs +++ b/kit/src/components/message/mod.rs @@ -447,11 +447,11 @@ fn markdown(text: &str, emojis: bool) -> String { let txt = text.trim(); if emojis { - let r = replace_emojis(txt); + let r = replace_emojis(txt).to_string(); // TODO: Watch this issue for a fix: https://github.com/open-i18n/rust-unic/issues/280 // This is a temporary workaround for some characters unic-emoji-char thinks are emojis - if !r.to_string().contains("#") // for multiple # - && !r.to_string().contains("*") // for multiple # + if !r.contains('#') // for multiple # + && !r.contains('*') // for multiple # && !r.chars().all(char::is_alphanumeric) // for any numbers, eg 1, 11, 111 && is_only_emojis(&r) { From 00f46491a6c05fa53197ab5be43f0c6a47c55b53 Mon Sep 17 00:00:00 2001 From: Chris Hogan Date: Mon, 6 Nov 2023 22:21:40 -0700 Subject: [PATCH 5/7] change from span to p tag to match other places --- kit/src/components/message/mod.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/kit/src/components/message/mod.rs b/kit/src/components/message/mod.rs index d6fb597e45d..c2b34caed6a 100644 --- a/kit/src/components/message/mod.rs +++ b/kit/src/components/message/mod.rs @@ -451,13 +451,13 @@ fn markdown(text: &str, emojis: bool) -> String { // TODO: Watch this issue for a fix: https://github.com/open-i18n/rust-unic/issues/280 // This is a temporary workaround for some characters unic-emoji-char thinks are emojis if !r.contains('#') // for multiple # - && !r.contains('*') // for multiple # + && !r.contains('*') // for multiple * && !r.chars().all(char::is_alphanumeric) // for any numbers, eg 1, 11, 111 && is_only_emojis(&r) { return format!("{r}"); } else { - return format!("{r}"); + return format!("

{r}

"); } } From 540b420608ca70316019e410e0511b651848d12e Mon Sep 17 00:00:00 2001 From: Chris Hogan Date: Tue, 7 Nov 2023 08:50:23 -0700 Subject: [PATCH 6/7] remove unecessary conversion --- kit/src/components/message/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kit/src/components/message/mod.rs b/kit/src/components/message/mod.rs index c2b34caed6a..ec3c71c0162 100644 --- a/kit/src/components/message/mod.rs +++ b/kit/src/components/message/mod.rs @@ -447,7 +447,7 @@ fn markdown(text: &str, emojis: bool) -> String { let txt = text.trim(); if emojis { - let r = replace_emojis(txt).to_string(); + let r = replace_emojis(txt); // TODO: Watch this issue for a fix: https://github.com/open-i18n/rust-unic/issues/280 // This is a temporary workaround for some characters unic-emoji-char thinks are emojis if !r.contains('#') // for multiple # From 285b4376e19307a6101884d5afd3697f4cd086f5 Mon Sep 17 00:00:00 2001 From: Chris Hogan Date: Wed, 8 Nov 2023 12:40:38 -0700 Subject: [PATCH 7/7] unbreak markdown --- kit/src/components/message/mod.rs | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/kit/src/components/message/mod.rs b/kit/src/components/message/mod.rs index ec3c71c0162..7862d7e0b51 100644 --- a/kit/src/components/message/mod.rs +++ b/kit/src/components/message/mod.rs @@ -450,14 +450,17 @@ fn markdown(text: &str, emojis: bool) -> String { let r = replace_emojis(txt); // TODO: Watch this issue for a fix: https://github.com/open-i18n/rust-unic/issues/280 // This is a temporary workaround for some characters unic-emoji-char thinks are emojis - if !r.contains('#') // for multiple # - && !r.contains('*') // for multiple * - && !r.chars().all(char::is_alphanumeric) // for any numbers, eg 1, 11, 111 + if !r.chars().all(char::is_alphanumeric) // for any numbers, eg 1, 11, 111 + && r != "#" + && r != "*" + && r != "##" + && r != "**" + && r != "-" && is_only_emojis(&r) { return format!("{r}"); - } else { - return format!("

{r}

"); + } else if is_only_emojis(txt) || r == "-" { + return format!("

{txt}

"); } }