jumbo emoji-only message with whitespace
This commit is contained in:
parent
b6c395fac1
commit
8b5fa7039d
5 changed files with 9 additions and 57 deletions
|
@ -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<Props, State> {
|
|||
|
||||
return Boolean(
|
||||
text &&
|
||||
isEmojiOnlyText(text) &&
|
||||
!hasNonEmojiText(text) &&
|
||||
getEmojiCount(text) < 6 &&
|
||||
!quote &&
|
||||
!storyReplyContext &&
|
||||
|
|
|
@ -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 '';
|
||||
}
|
||||
|
||||
|
|
|
@ -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('😎👍😀😮💨'));
|
||||
});
|
||||
});
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
Loading…
Reference in a new issue