From eaa2f681ac3820786e194e2f1b43d1500e056091 Mon Sep 17 00:00:00 2001 From: DianaXWiki <139217939+DianaXWiki@users.noreply.github.com> Date: Fri, 16 Aug 2024 15:25:17 +0300 Subject: [PATCH 01/10] Modify avatar generation function #1593 --- www/common/inner/common-mediatag.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/www/common/inner/common-mediatag.js b/www/common/inner/common-mediatag.js index 5c059aae5..c2f1d7756 100644 --- a/www/common/inner/common-mediatag.js +++ b/www/common/inner/common-mediatag.js @@ -124,8 +124,17 @@ define([ return ANIMALS[seed % ANIMALS.length] || ''; }; + const emojiRegex = /\p{Extended_Pictographic}/gu; // 'g' flag for global match var getPrettyInitials = MT.getPrettyInitials = function (name) { - var parts = name.split(/\s+/); + const match = name.match(emojiRegex); + //if the emoji is the first character, it will become the avatar + if (match && name.indexOf(match) === 0) { + return match[0]; + } + else { + name = name.replace(emojiRegex, ''); + } + var parts = name.trim().split(/\s+/); var text; if (parts.length > 1) { text = parts.slice(0, 2).map(Util.getFirstCharacter).join(''); From 855065c201adca686e4227fb1963a0fc165f2102 Mon Sep 17 00:00:00 2001 From: DianaXWiki <139217939+DianaXWiki@users.noreply.github.com> Date: Fri, 16 Aug 2024 15:35:05 +0300 Subject: [PATCH 02/10] Fix matching of multiple emojis #1593 --- www/common/inner/common-mediatag.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/www/common/inner/common-mediatag.js b/www/common/inner/common-mediatag.js index c2f1d7756..e39893ab8 100644 --- a/www/common/inner/common-mediatag.js +++ b/www/common/inner/common-mediatag.js @@ -128,13 +128,14 @@ define([ var getPrettyInitials = MT.getPrettyInitials = function (name) { const match = name.match(emojiRegex); //if the emoji is the first character, it will become the avatar - if (match && name.indexOf(match) === 0) { + if (match && name.startsWith(match[0])) { return match[0]; } else { name = name.replace(emojiRegex, ''); + name = name.trim(); } - var parts = name.trim().split(/\s+/); + var parts = name.split(/\s+/); var text; if (parts.length > 1) { text = parts.slice(0, 2).map(Util.getFirstCharacter).join(''); From 1c96a2496762663947e80a7ca7615ae8e3b6dcb3 Mon Sep 17 00:00:00 2001 From: DianaXWiki <139217939+DianaXWiki@users.noreply.github.com> Date: Fri, 16 Aug 2024 16:30:37 +0300 Subject: [PATCH 03/10] Fix team name overflowing in sidebar #1596 --- www/teams/app-team.less | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/www/teams/app-team.less b/www/teams/app-team.less index db1efa29b..352f7cfaa 100644 --- a/www/teams/app-team.less +++ b/www/teams/app-team.less @@ -96,7 +96,7 @@ } } .cp-team-cat-header { - justify-content: center; + justify-content: left; background-color: transparent !important; box-shadow: none !important; .avatar_main(30px); @@ -106,6 +106,7 @@ } media-tag, .cp-avatar-default { margin-right: 3px; + flex-shrink: 0; } media-tag { order: -1; @@ -113,7 +114,12 @@ cursor: default !important; font-size: 18px; span.cp-sidebarlayout-category-name { + max-width: 12rem; padding-left: 5px; + white-space: nowrap; + overflow: hidden; + text-overflow: ellipsis; + min-width: 0; } } .cp-team-cat-chat { From baea7343cda63068f73fbbc48832f016039fa01d Mon Sep 17 00:00:00 2001 From: DianaXWiki <139217939+DianaXWiki@users.noreply.github.com> Date: Fri, 23 Aug 2024 17:27:34 +0300 Subject: [PATCH 04/10] Recognize zwj in regex matches #1593 --- www/common/inner/common-mediatag.js | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/www/common/inner/common-mediatag.js b/www/common/inner/common-mediatag.js index e39893ab8..a0669d3f7 100644 --- a/www/common/inner/common-mediatag.js +++ b/www/common/inner/common-mediatag.js @@ -124,15 +124,25 @@ define([ return ANIMALS[seed % ANIMALS.length] || ''; }; - const emojiRegex = /\p{Extended_Pictographic}/gu; // 'g' flag for global match + const emojiWithZWJRegex = /(?:\p{Emoji_Presentation}|\p{Emoji_Modifier_Base}|\p{Emoji_Modifier}|\p{Emoji_Component})(?:\u200D(?:\p{Emoji_Presentation}|\p{Emoji_Modifier_Base}|\p{Emoji_Modifier}|\p{Emoji_Component}))*\p{Emoji_Presentation}?|\p{Emoji_Presentation}/gu; + const ZWJ = '\u200D'; var getPrettyInitials = MT.getPrettyInitials = function (name) { - const match = name.match(emojiRegex); - //if the emoji is the first character, it will become the avatar - if (match && name.startsWith(match[0])) { - return match[0]; + let matches = name.match(emojiWithZWJRegex); + console.log(matches) + if (matches) { + // Check if any of the matched sequences include ZWJ + let zwjInMatches = matches.some(match => match.includes(ZWJ)); + console.log(zwjInMatches) + if (zwjInMatches) { + // Combine the matched emojis using ZWJ + return matches.join(ZWJ); + } + else if(name.startsWith(matches[0])) { + return matches[0]; + } } else { - name = name.replace(emojiRegex, ''); + name = name.replace(emojiWithZWJRegex, ''); name = name.trim(); } var parts = name.split(/\s+/); From 777c443475f8335fa35052405e171878eae38460 Mon Sep 17 00:00:00 2001 From: DianaXWiki <139217939+DianaXWiki@users.noreply.github.com> Date: Tue, 27 Aug 2024 14:06:03 +0300 Subject: [PATCH 05/10] Modify regex to also detect composite emojis #1593 --- www/common/inner/common-mediatag.js | 17 +++-------------- 1 file changed, 3 insertions(+), 14 deletions(-) diff --git a/www/common/inner/common-mediatag.js b/www/common/inner/common-mediatag.js index a0669d3f7..fad12e68b 100644 --- a/www/common/inner/common-mediatag.js +++ b/www/common/inner/common-mediatag.js @@ -124,22 +124,11 @@ define([ return ANIMALS[seed % ANIMALS.length] || ''; }; - const emojiWithZWJRegex = /(?:\p{Emoji_Presentation}|\p{Emoji_Modifier_Base}|\p{Emoji_Modifier}|\p{Emoji_Component})(?:\u200D(?:\p{Emoji_Presentation}|\p{Emoji_Modifier_Base}|\p{Emoji_Modifier}|\p{Emoji_Component}))*\p{Emoji_Presentation}?|\p{Emoji_Presentation}/gu; - const ZWJ = '\u200D'; + const emojiWithZWJRegex = /(\p{Emoji_Presentation}|\p{Emoji_Modifier_Base})(\p{Emoji_Modifier})?(?:\u200D(\p{Emoji_Presentation}|\p{Emoji_Modifier_Base})(\p{Emoji_Modifier})?)*/gu; var getPrettyInitials = MT.getPrettyInitials = function (name) { let matches = name.match(emojiWithZWJRegex); - console.log(matches) - if (matches) { - // Check if any of the matched sequences include ZWJ - let zwjInMatches = matches.some(match => match.includes(ZWJ)); - console.log(zwjInMatches) - if (zwjInMatches) { - // Combine the matched emojis using ZWJ - return matches.join(ZWJ); - } - else if(name.startsWith(matches[0])) { - return matches[0]; - } + if (matches && name.startsWith(matches[0])) { + return matches[0]; } else { name = name.replace(emojiWithZWJRegex, ''); From a4d24dfb43351c3ad6e8b99462071e432aafe8d9 Mon Sep 17 00:00:00 2001 From: DianaXWiki <139217939+DianaXWiki@users.noreply.github.com> Date: Tue, 27 Aug 2024 14:13:36 +0300 Subject: [PATCH 06/10] Remove invisible characters from the name #1593 --- www/common/inner/common-mediatag.js | 1 + 1 file changed, 1 insertion(+) diff --git a/www/common/inner/common-mediatag.js b/www/common/inner/common-mediatag.js index fad12e68b..5d880774b 100644 --- a/www/common/inner/common-mediatag.js +++ b/www/common/inner/common-mediatag.js @@ -132,6 +132,7 @@ define([ } else { name = name.replace(emojiWithZWJRegex, ''); + name = name.replace(/[\uFE0F\u200D\u2060]/g, ''); name = name.trim(); } var parts = name.split(/\s+/); From d167c703fc69b82b179786ee3499d2dfd77d26bc Mon Sep 17 00:00:00 2001 From: DianaXWiki <139217939+DianaXWiki@users.noreply.github.com> Date: Wed, 4 Sep 2024 14:38:35 +0300 Subject: [PATCH 07/10] Add comments +modify regex #1593 --- www/common/inner/common-mediatag.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/www/common/inner/common-mediatag.js b/www/common/inner/common-mediatag.js index 5d880774b..4d6e29bce 100644 --- a/www/common/inner/common-mediatag.js +++ b/www/common/inner/common-mediatag.js @@ -123,14 +123,16 @@ define([ if (!seed) { return; } return ANIMALS[seed % ANIMALS.length] || ''; }; - - const emojiWithZWJRegex = /(\p{Emoji_Presentation}|\p{Emoji_Modifier_Base})(\p{Emoji_Modifier})?(?:\u200D(\p{Emoji_Presentation}|\p{Emoji_Modifier_Base})(\p{Emoji_Modifier})?)*/gu; + //this regex identifies both discord and unicode emojis (with optional skin tone modifiers) and some zwj composite emojis + const emojiWithZWJRegex = /|(?:\p{Extended_Pictographic}\p{Emoji_Modifier}?)(?:\u200D(?:\p{Extended_Pictographic}\p{Emoji_Modifier}?))*/gu; var getPrettyInitials = MT.getPrettyInitials = function (name) { let matches = name.match(emojiWithZWJRegex); if (matches && name.startsWith(matches[0])) { + console.log(matches) return matches[0]; } else { + //this is for removing all trailing white characters and unnecessary/redundant emojis name = name.replace(emojiWithZWJRegex, ''); name = name.replace(/[\uFE0F\u200D\u2060]/g, ''); name = name.trim(); From b780a8eab9f899252b5e40c9b1aec76d2d66b759 Mon Sep 17 00:00:00 2001 From: DianaXWiki <139217939+DianaXWiki@users.noreply.github.com> Date: Wed, 4 Sep 2024 14:47:07 +0300 Subject: [PATCH 08/10] Fix regex #1593 --- www/common/inner/common-mediatag.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/www/common/inner/common-mediatag.js b/www/common/inner/common-mediatag.js index 4d6e29bce..febaa3b41 100644 --- a/www/common/inner/common-mediatag.js +++ b/www/common/inner/common-mediatag.js @@ -123,8 +123,8 @@ define([ if (!seed) { return; } return ANIMALS[seed % ANIMALS.length] || ''; }; - //this regex identifies both discord and unicode emojis (with optional skin tone modifiers) and some zwj composite emojis - const emojiWithZWJRegex = /|(?:\p{Extended_Pictographic}\p{Emoji_Modifier}?)(?:\u200D(?:\p{Extended_Pictographic}\p{Emoji_Modifier}?))*/gu; + //this regex identifies both discord and unicode emojis (with optional skin tone modifiers) and complex zwj emoji sequences + const emojiWithZWJRegex = /(?:\p{Extended_Pictographic}(?:\p{Emoji_Modifier}|\uFE0F)?(?:\u200D\p{Extended_Pictographic}(?:\p{Emoji_Modifier}|\uFE0F)?)*|\p{Extended_Pictographic})/gu; var getPrettyInitials = MT.getPrettyInitials = function (name) { let matches = name.match(emojiWithZWJRegex); if (matches && name.startsWith(matches[0])) { From 0eb5f6d49f5f2ce4eae9d1406ed8057b947619dd Mon Sep 17 00:00:00 2001 From: yflory Date: Wed, 4 Sep 2024 15:35:42 +0200 Subject: [PATCH 09/10] Remove debugging console.log --- www/common/inner/common-mediatag.js | 1 - 1 file changed, 1 deletion(-) diff --git a/www/common/inner/common-mediatag.js b/www/common/inner/common-mediatag.js index febaa3b41..82ec8092f 100644 --- a/www/common/inner/common-mediatag.js +++ b/www/common/inner/common-mediatag.js @@ -128,7 +128,6 @@ define([ var getPrettyInitials = MT.getPrettyInitials = function (name) { let matches = name.match(emojiWithZWJRegex); if (matches && name.startsWith(matches[0])) { - console.log(matches) return matches[0]; } else { From e866ebb17ee59fdbea32219907188ceb81ea8a53 Mon Sep 17 00:00:00 2001 From: DianaXWiki <139217939+DianaXWiki@users.noreply.github.com> Date: Fri, 6 Sep 2024 13:21:18 +0300 Subject: [PATCH 10/10] lint compliance --- www/common/inner/common-mediatag.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/www/common/inner/common-mediatag.js b/www/common/inner/common-mediatag.js index febaa3b41..3115eb66b 100644 --- a/www/common/inner/common-mediatag.js +++ b/www/common/inner/common-mediatag.js @@ -134,7 +134,7 @@ define([ else { //this is for removing all trailing white characters and unnecessary/redundant emojis name = name.replace(emojiWithZWJRegex, ''); - name = name.replace(/[\uFE0F\u200D\u2060]/g, ''); + name = name.replace(/\uFE0F/g, '').replace(/\u200D/g, '').replace(/\u2060/g, ''); name = name.trim(); } var parts = name.split(/\s+/);