diff --git a/CHANGELOG.md b/CHANGELOG.md index 30481dbdd9..0ed1ba5b24 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,10 @@ * Allow JPEG and GIF files as profile photos ([#2332](https://github.com/TryQuiet/quiet/issues/2332)) +# New features + +* Add utilities for emoji detection in messages and make all-emoji message larger font size ([#519](https://github.com/TryQuiet/quiet/issues/519)) + [2.1.2] # Refactorings: diff --git a/packages/common/src/emojis.test.ts b/packages/common/src/emojis.test.ts new file mode 100644 index 0000000000..17337f8147 --- /dev/null +++ b/packages/common/src/emojis.test.ts @@ -0,0 +1,22 @@ +import { hasEmoji, isAllEmoji } from './emojis' + +describe('Emoji Utilities', () => { + it('Should detect an emoji in a string', () => { + expect(hasEmoji('❤️‍🔥')).toBeTruthy() + expect(hasEmoji('Hello ❤️‍🔥 Emoji')).toBeTruthy() + expect(hasEmoji('No emoji :-(')).toBeFalsy() + }) + + it('Should detect when a string is all emojis (or spaces)', () => { + expect(isAllEmoji('🙂🙂🙂🙂🙂🙂🙂🙂')).toBeTruthy() + expect(isAllEmoji('🐈‍⬛❤️‍🔥🏴')).toBeTruthy() + expect(isAllEmoji('🐈‍⬛ ❤️‍🔥 🏴')).toBeTruthy() + expect(isAllEmoji('❤️‍🔥')).toBeTruthy() + expect(isAllEmoji('🐈‍⬛')).toBeTruthy() + expect(isAllEmoji('❤️‍🔥 Emoji')).toBeFalsy() + expect(isAllEmoji('Hello ❤️‍🔥')).toBeFalsy() + expect(isAllEmoji('Hello ❤️‍🔥 Emoji')).toBeFalsy() + expect(isAllEmoji('🐈‍⬛ (Not emoji) 🏴')).toBeFalsy() + expect(isAllEmoji('No emoji :-(')).toBeFalsy() + }) +}) diff --git a/packages/common/src/emojis.ts b/packages/common/src/emojis.ts new file mode 100644 index 0000000000..ac5a7486da --- /dev/null +++ b/packages/common/src/emojis.ts @@ -0,0 +1,12 @@ +export const hasEmoji = (testString: string) => { + // All strings with at least one emoji character should match this + const regExp = /\p{Emoji}/gu + return regExp.test(testString) +} + +export const isAllEmoji = (testString: string) => { + // Detect whether a string is entirely emojis (and whitespace and zero-width-joins, region indicators, etc) + // This may need to be updated as Unicode's Emoji spec is a moving target + const emojiOrWhitespaceRegExp = /^(\p{Emoji}|\p{Emoji_Modifier}|\uFE0F|\u200D|\p{RI}|\uE007F|\s)+$/gu + return emojiOrWhitespaceRegExp.test(testString) +} diff --git a/packages/desktop/src/renderer/components/MathMessage/MathMessageComponent.test.tsx b/packages/desktop/src/renderer/components/MathMessage/MathMessageComponent.test.tsx index f0610a8787..3a4a5afeb4 100644 --- a/packages/desktop/src/renderer/components/MathMessage/MathMessageComponent.test.tsx +++ b/packages/desktop/src/renderer/components/MathMessage/MathMessageComponent.test.tsx @@ -107,7 +107,7 @@ describe('MathMessageComponent', () => {
It is @@ -187,7 +187,7 @@ describe('MathMessageComponent', () => { and @@ -484,7 +484,7 @@ describe('MathMessageComponent', () => {