Compare commits
2 Commits
develop
...
fix.emoji-
Author | SHA1 | Date |
---|---|---|
Djorkaeff Alexandre | 1239a28509 | |
Diego Mello | 5beec1cd65 |
|
@ -11188,6 +11188,104 @@ exports[`Storyshots Markdown list Markdown 1`] = `
|
||||||
/>
|
/>
|
||||||
</View>
|
</View>
|
||||||
</Text>
|
</Text>
|
||||||
|
<Text
|
||||||
|
style={
|
||||||
|
Array [
|
||||||
|
undefined,
|
||||||
|
Object {
|
||||||
|
"color": "#2f343d",
|
||||||
|
},
|
||||||
|
]
|
||||||
|
}
|
||||||
|
>
|
||||||
|
<Text
|
||||||
|
accessibilityLabel="🤙"
|
||||||
|
style={
|
||||||
|
Array [
|
||||||
|
Object {
|
||||||
|
"backgroundColor": "transparent",
|
||||||
|
"fontFamily": "System",
|
||||||
|
"fontSize": 16,
|
||||||
|
"fontWeight": "400",
|
||||||
|
},
|
||||||
|
Array [
|
||||||
|
Object {},
|
||||||
|
Object {
|
||||||
|
"alignItems": "flex-start",
|
||||||
|
"flexDirection": "row",
|
||||||
|
"flexWrap": "wrap",
|
||||||
|
"justifyContent": "flex-start",
|
||||||
|
"marginBottom": 0,
|
||||||
|
"marginTop": 0,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
]
|
||||||
|
}
|
||||||
|
>
|
||||||
|
🤙
|
||||||
|
</Text>
|
||||||
|
<View
|
||||||
|
style={
|
||||||
|
Array [
|
||||||
|
Object {
|
||||||
|
"overflow": "hidden",
|
||||||
|
},
|
||||||
|
Array [
|
||||||
|
Object {
|
||||||
|
"height": 20,
|
||||||
|
"width": 20,
|
||||||
|
},
|
||||||
|
Object {},
|
||||||
|
],
|
||||||
|
]
|
||||||
|
}
|
||||||
|
>
|
||||||
|
<FastImageView
|
||||||
|
resizeMode="contain"
|
||||||
|
source={
|
||||||
|
Object {
|
||||||
|
"priority": "high",
|
||||||
|
"uri": "https://open.rocket.chat/emoji-custom/react_rocket.png",
|
||||||
|
}
|
||||||
|
}
|
||||||
|
style={
|
||||||
|
Object {
|
||||||
|
"bottom": 0,
|
||||||
|
"left": 0,
|
||||||
|
"position": "absolute",
|
||||||
|
"right": 0,
|
||||||
|
"top": 0,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
</View>
|
||||||
|
<Text
|
||||||
|
accessibilityLabel="ひ"
|
||||||
|
style={
|
||||||
|
Array [
|
||||||
|
Object {
|
||||||
|
"backgroundColor": "transparent",
|
||||||
|
"fontFamily": "System",
|
||||||
|
"fontSize": 16,
|
||||||
|
"fontWeight": "400",
|
||||||
|
},
|
||||||
|
Array [
|
||||||
|
Object {},
|
||||||
|
Object {
|
||||||
|
"alignItems": "flex-start",
|
||||||
|
"flexDirection": "row",
|
||||||
|
"flexWrap": "wrap",
|
||||||
|
"justifyContent": "flex-start",
|
||||||
|
"marginBottom": 0,
|
||||||
|
"marginTop": 0,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
]
|
||||||
|
}
|
||||||
|
>
|
||||||
|
ひ
|
||||||
|
</Text>
|
||||||
|
</Text>
|
||||||
</View>
|
</View>
|
||||||
<Text
|
<Text
|
||||||
style={
|
style={
|
||||||
|
|
|
@ -4,6 +4,7 @@ import { Parser, Node } from 'commonmark';
|
||||||
import Renderer from 'commonmark-react-renderer';
|
import Renderer from 'commonmark-react-renderer';
|
||||||
import PropTypes from 'prop-types';
|
import PropTypes from 'prop-types';
|
||||||
import removeMarkdown from 'remove-markdown';
|
import removeMarkdown from 'remove-markdown';
|
||||||
|
import emojiRegex from 'emoji-regex/RGI_Emoji';
|
||||||
|
|
||||||
import shortnameToUnicode from '../../utils/shortnameToUnicode';
|
import shortnameToUnicode from '../../utils/shortnameToUnicode';
|
||||||
import I18n from '../../i18n';
|
import I18n from '../../i18n';
|
||||||
|
@ -31,36 +32,22 @@ const formatText = text => text.replace(
|
||||||
);
|
);
|
||||||
|
|
||||||
const emojiRanges = [
|
const emojiRanges = [
|
||||||
'\u00a9|\u00ae|[\u2000-\u3300]|\ud83c[\ud000-\udfff]|\ud83d[\ud000-\udfff]|\ud83e[\ud000-\udfff]', // unicode emoji from https://www.regextester.com/106421
|
emojiRegex(),
|
||||||
':.{1,40}:', // custom emoji
|
':.{1,40}:', // custom emoji
|
||||||
' |\n' // allow spaces and line breaks
|
' |\n' // allow spaces and line breaks
|
||||||
].join('|');
|
].join('|');
|
||||||
|
|
||||||
|
const emojisRegex = new RegExp(emojiRanges, 'g');
|
||||||
|
|
||||||
const removeSpaces = str => str && str.replace(/\s/g, '');
|
const removeSpaces = str => str && str.replace(/\s/g, '');
|
||||||
|
|
||||||
const removeAllEmoji = str => str.replace(new RegExp(emojiRanges, 'g'), '');
|
const removeAllEmoji = str => str.replace(emojisRegex, '');
|
||||||
|
|
||||||
|
const emojiCount = str => str?.match(emojisRegex, '')?.length;
|
||||||
|
|
||||||
const isOnlyEmoji = (str) => {
|
const isOnlyEmoji = (str) => {
|
||||||
str = removeSpaces(str);
|
str = removeSpaces(str);
|
||||||
return !removeAllEmoji(str).length;
|
return !removeAllEmoji(str).length && emojiCount(str) <= 3;
|
||||||
};
|
|
||||||
|
|
||||||
const removeOneEmoji = str => str.replace(new RegExp(emojiRanges), '');
|
|
||||||
|
|
||||||
const emojiCount = (str) => {
|
|
||||||
str = removeSpaces(str);
|
|
||||||
let oldLength = 0;
|
|
||||||
let counter = 0;
|
|
||||||
|
|
||||||
while (oldLength !== str.length) {
|
|
||||||
oldLength = str.length;
|
|
||||||
str = removeOneEmoji(str);
|
|
||||||
if (oldLength !== str.length) {
|
|
||||||
counter += 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return counter;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const parser = new Parser();
|
const parser = new Parser();
|
||||||
|
@ -395,7 +382,7 @@ class Markdown extends PureComponent {
|
||||||
|
|
||||||
let ast = parser.parse(m);
|
let ast = parser.parse(m);
|
||||||
ast = mergeTextNodes(ast);
|
ast = mergeTextNodes(ast);
|
||||||
this.isMessageContainsOnlyEmoji = isOnlyEmoji(m) && emojiCount(m) <= 3;
|
this.isMessageContainsOnlyEmoji = isOnlyEmoji(m);
|
||||||
this.editedMessage(ast);
|
this.editedMessage(ast);
|
||||||
return this.renderer.render(ast);
|
return this.renderer.render(ast);
|
||||||
}
|
}
|
||||||
|
|
|
@ -49,6 +49,7 @@
|
||||||
"commonmark-react-renderer": "git+https://github.com/RocketChat/commonmark-react-renderer.git",
|
"commonmark-react-renderer": "git+https://github.com/RocketChat/commonmark-react-renderer.git",
|
||||||
"deep-equal": "2.0.3",
|
"deep-equal": "2.0.3",
|
||||||
"ejson": "2.2.0",
|
"ejson": "2.2.0",
|
||||||
|
"emoji-regex": "^9.2.0",
|
||||||
"eslint-config-airbnb": "^18.1.0",
|
"eslint-config-airbnb": "^18.1.0",
|
||||||
"expo-apple-authentication": "^2.2.1",
|
"expo-apple-authentication": "^2.2.1",
|
||||||
"expo-av": "8.2.1",
|
"expo-av": "8.2.1",
|
||||||
|
|
|
@ -171,6 +171,13 @@ export default ({ theme }) => {
|
||||||
getCustomEmoji={getCustomEmoji}
|
getCustomEmoji={getCustomEmoji}
|
||||||
baseUrl={baseUrl}
|
baseUrl={baseUrl}
|
||||||
/>
|
/>
|
||||||
|
{/* Emojis + non-latin characters */}
|
||||||
|
<Markdown
|
||||||
|
msg='🤙:react_rocket:ひ'
|
||||||
|
theme={theme}
|
||||||
|
getCustomEmoji={getCustomEmoji}
|
||||||
|
baseUrl={baseUrl}
|
||||||
|
/>
|
||||||
</View>
|
</View>
|
||||||
|
|
||||||
<StoriesSeparator style={styles.separator} title='Block Quote' theme={theme} />
|
<StoriesSeparator style={styles.separator} title='Block Quote' theme={theme} />
|
||||||
|
|
|
@ -6105,6 +6105,11 @@ emoji-regex@^9.0.0:
|
||||||
resolved "https://registry.yarnpkg.com/emoji-regex/-/emoji-regex-9.0.0.tgz#48a2309cc8a1d2e9d23bc6a67c39b63032e76ea4"
|
resolved "https://registry.yarnpkg.com/emoji-regex/-/emoji-regex-9.0.0.tgz#48a2309cc8a1d2e9d23bc6a67c39b63032e76ea4"
|
||||||
integrity sha512-6p1NII1Vm62wni/VR/cUMauVQoxmLVb9csqQlvLz+hO2gk8U2UYDfXHQSUYIBKmZwAKz867IDqG7B+u0mj+M6w==
|
integrity sha512-6p1NII1Vm62wni/VR/cUMauVQoxmLVb9csqQlvLz+hO2gk8U2UYDfXHQSUYIBKmZwAKz867IDqG7B+u0mj+M6w==
|
||||||
|
|
||||||
|
emoji-regex@^9.2.0:
|
||||||
|
version "9.2.0"
|
||||||
|
resolved "https://registry.yarnpkg.com/emoji-regex/-/emoji-regex-9.2.0.tgz#a26da8e832b16a9753309f25e35e3c0efb9a066a"
|
||||||
|
integrity sha512-DNc3KFPK18bPdElMJnf/Pkv5TXhxFU3YFDEuGLDRtPmV4rkmCjBkCSEp22u6rBHdSN9Vlp/GK7k98prmE1Jgug==
|
||||||
|
|
||||||
emojis-list@^2.0.0:
|
emojis-list@^2.0.0:
|
||||||
version "2.1.0"
|
version "2.1.0"
|
||||||
resolved "https://registry.yarnpkg.com/emojis-list/-/emojis-list-2.1.0.tgz#4daa4d9db00f9819880c79fa457ae5b09a1fd389"
|
resolved "https://registry.yarnpkg.com/emojis-list/-/emojis-list-2.1.0.tgz#4daa4d9db00f9819880c79fa457ae5b09a1fd389"
|
||||||
|
|
Loading…
Reference in New Issue