From 8b5fa7039dac63e9776c007e08cb2e4bd929deef Mon Sep 17 00:00:00 2001 From: Jamie Kyle <113370520+jamiebuilds-signal@users.noreply.github.com> Date: Mon, 6 Feb 2023 13:40:49 -0800 Subject: [PATCH] jumbo emoji-only message with whitespace --- ts/components/conversation/Message.tsx | 5 ++-- ts/components/emoji/lib.ts | 6 ++++- ts/test-both/util/isEmojiOnlyText_test.ts | 28 ----------------------- ts/util/avatarTextSizeCalculator.ts | 5 ++-- ts/util/isEmojiOnlyText.tsx | 22 ------------------ 5 files changed, 9 insertions(+), 57 deletions(-) delete mode 100644 ts/test-both/util/isEmojiOnlyText_test.ts delete mode 100644 ts/util/isEmojiOnlyText.tsx diff --git a/ts/components/conversation/Message.tsx b/ts/components/conversation/Message.tsx index 43a29a3e1c2..8d223297148 100644 --- a/ts/components/conversation/Message.tsx +++ b/ts/components/conversation/Message.tsx @@ -80,8 +80,7 @@ import type { CustomColorType, } from '../../types/Colors'; import { createRefMerger } from '../../util/refMerger'; -import { emojiToData, getEmojiCount } from '../emoji/lib'; -import { isEmojiOnlyText } from '../../util/isEmojiOnlyText'; +import { emojiToData, getEmojiCount, hasNonEmojiText } from '../emoji/lib'; import { getCustomColorStyle } from '../../util/getCustomColorStyle'; import type { UUIDStringType } from '../../types/UUID'; import { DAY, HOUR, MINUTE, SECOND } from '../../util/durations'; @@ -715,7 +714,7 @@ export class Message extends React.PureComponent { return Boolean( text && - isEmojiOnlyText(text) && + !hasNonEmojiText(text) && getEmojiCount(text) < 6 && !quote && !storyReplyContext && diff --git a/ts/components/emoji/lib.ts b/ts/components/emoji/lib.ts index 6364e1c5024..9f7de8b33c6 100644 --- a/ts/components/emoji/lib.ts +++ b/ts/components/emoji/lib.ts @@ -328,9 +328,13 @@ export function getEmojiCount(str: string): number { return count; } +export function hasNonEmojiText(str: string): boolean { + return str.replace(emojiRegex(), '').trim().length > 0; +} + export function getSizeClass(str: string): SizeClassType { // Do we have non-emoji characters? - if (str.replace(emojiRegex(), '').trim().length > 0) { + if (hasNonEmojiText(str)) { return ''; } diff --git a/ts/test-both/util/isEmojiOnlyText_test.ts b/ts/test-both/util/isEmojiOnlyText_test.ts deleted file mode 100644 index ca7e129944a..00000000000 --- a/ts/test-both/util/isEmojiOnlyText_test.ts +++ /dev/null @@ -1,28 +0,0 @@ -// Copyright 2022 Signal Messenger, LLC -// SPDX-License-Identifier: AGPL-3.0-only - -import { assert } from 'chai'; - -import { isEmojiOnlyText } from '../../util/isEmojiOnlyText'; - -describe('isEmojiOnlyText', () => { - it('returns false on empty string', () => { - assert.isFalse(isEmojiOnlyText('')); - }); - - it('returns false on non-emoji string', () => { - assert.isFalse(isEmojiOnlyText('123')); - }); - - it('returns false on mixed emoji/text string', () => { - assert.isFalse(isEmojiOnlyText('12😎3')); - }); - - it('returns false on mixed emoji/text string starting with emoji', () => { - assert.isFalse(isEmojiOnlyText('😎12😎3')); - }); - - it('returns true on all emoji string', () => { - assert.isTrue(isEmojiOnlyText('😎👍😀😮‍💨')); - }); -}); diff --git a/ts/util/avatarTextSizeCalculator.ts b/ts/util/avatarTextSizeCalculator.ts index aaae81488b6..d942a15b8a6 100644 --- a/ts/util/avatarTextSizeCalculator.ts +++ b/ts/util/avatarTextSizeCalculator.ts @@ -1,8 +1,7 @@ // Copyright 2021 Signal Messenger, LLC // SPDX-License-Identifier: AGPL-3.0-only -import { getEmojiCount } from '../components/emoji/lib'; -import { isEmojiOnlyText } from './isEmojiOnlyText'; +import { getEmojiCount, hasNonEmojiText } from '../components/emoji/lib'; type FontSizes = { diameter: number; @@ -33,7 +32,7 @@ export function getFittedFontSize( const sizes = getFontSizes(bubbleSize); let candidateFontSize = sizes.text; - if (isEmojiOnlyText(text) && getEmojiCount(text) === 1) { + if (!hasNonEmojiText(text) && getEmojiCount(text) === 1) { candidateFontSize = sizes.singleEmoji; } diff --git a/ts/util/isEmojiOnlyText.tsx b/ts/util/isEmojiOnlyText.tsx deleted file mode 100644 index 64a9ea381f7..00000000000 --- a/ts/util/isEmojiOnlyText.tsx +++ /dev/null @@ -1,22 +0,0 @@ -// Copyright 2021 Signal Messenger, LLC -// SPDX-License-Identifier: AGPL-3.0-only - -import emojiRegex from 'emoji-regex'; - -export function isEmojiOnlyText(text: string): boolean { - if (text.length === 0) { - return false; - } - - const regex = emojiRegex(); - let len = 0; - for (const match of text.matchAll(regex)) { - // Skipped some non-emoji text, return early - if (match.index !== len) { - return false; - } - - len += match[0].length; - } - return len === text.length; -}