[IMPROVEMENT] Markdown performance when identifying emoji only content (#1422)
This commit is contained in:
parent
02c6a674fe
commit
4bb0bfa7eb
|
@ -6012,13 +6012,7 @@ exports[`Storyshots Message list 1`] = `
|
||||||
"fontWeight": "400",
|
"fontWeight": "400",
|
||||||
},
|
},
|
||||||
Array [
|
Array [
|
||||||
Object {
|
Object {},
|
||||||
"backgroundColor": "transparent",
|
|
||||||
"color": "#2F343D",
|
|
||||||
"fontFamily": "System",
|
|
||||||
"fontSize": 30,
|
|
||||||
"fontWeight": "400",
|
|
||||||
},
|
|
||||||
Object {
|
Object {
|
||||||
"alignItems": "flex-start",
|
"alignItems": "flex-start",
|
||||||
"flexDirection": "row",
|
"flexDirection": "row",
|
||||||
|
@ -6040,8 +6034,8 @@ exports[`Storyshots Message list 1`] = `
|
||||||
"overflow": "hidden",
|
"overflow": "hidden",
|
||||||
},
|
},
|
||||||
Object {
|
Object {
|
||||||
"height": 30,
|
"height": 20,
|
||||||
"width": 30,
|
"width": 20,
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
@ -6077,13 +6071,7 @@ exports[`Storyshots Message list 1`] = `
|
||||||
"fontWeight": "400",
|
"fontWeight": "400",
|
||||||
},
|
},
|
||||||
Array [
|
Array [
|
||||||
Object {
|
Object {},
|
||||||
"backgroundColor": "transparent",
|
|
||||||
"color": "#2F343D",
|
|
||||||
"fontFamily": "System",
|
|
||||||
"fontSize": 30,
|
|
||||||
"fontWeight": "400",
|
|
||||||
},
|
|
||||||
Object {
|
Object {
|
||||||
"alignItems": "flex-start",
|
"alignItems": "flex-start",
|
||||||
"flexDirection": "row",
|
"flexDirection": "row",
|
||||||
|
|
|
@ -3,7 +3,7 @@ import { Text, Image } from 'react-native';
|
||||||
import { Parser, Node } from 'commonmark';
|
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 { toShort, shortnameToUnicode } from 'emoji-toolkit';
|
import { shortnameToUnicode } from 'emoji-toolkit';
|
||||||
|
|
||||||
import I18n from '../../i18n';
|
import I18n from '../../i18n';
|
||||||
|
|
||||||
|
@ -32,13 +32,19 @@ const emojiRanges = [
|
||||||
' |\n' // allow spaces and line breaks
|
' |\n' // allow spaces and line breaks
|
||||||
].join('|');
|
].join('|');
|
||||||
|
|
||||||
|
const removeSpaces = str => str && str.replace(/\s/g, '');
|
||||||
|
|
||||||
const removeAllEmoji = str => str.replace(new RegExp(emojiRanges, 'g'), '');
|
const removeAllEmoji = str => str.replace(new RegExp(emojiRanges, 'g'), '');
|
||||||
|
|
||||||
const isOnlyEmoji = str => !removeAllEmoji(str).length;
|
const isOnlyEmoji = (str) => {
|
||||||
|
str = removeSpaces(str);
|
||||||
|
return !removeAllEmoji(str).length;
|
||||||
|
};
|
||||||
|
|
||||||
const removeOneEmoji = str => str.replace(new RegExp(emojiRanges), '');
|
const removeOneEmoji = str => str.replace(new RegExp(emojiRanges), '');
|
||||||
|
|
||||||
const emojiCount = (str) => {
|
const emojiCount = (str) => {
|
||||||
|
str = removeSpaces(str);
|
||||||
let oldLength = 0;
|
let oldLength = 0;
|
||||||
let counter = 0;
|
let counter = 0;
|
||||||
|
|
||||||
|
@ -322,6 +328,8 @@ export default class Markdown extends PureComponent {
|
||||||
|
|
||||||
if (preview) {
|
if (preview) {
|
||||||
m = m.split('\n').reduce((lines, line) => `${ lines } ${ line }`, '');
|
m = m.split('\n').reduce((lines, line) => `${ lines } ${ line }`, '');
|
||||||
|
const ast = this.parser.parse(m);
|
||||||
|
return this.renderer.render(ast);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!useMarkdown && !preview) {
|
if (!useMarkdown && !preview) {
|
||||||
|
@ -329,8 +337,7 @@ export default class Markdown extends PureComponent {
|
||||||
}
|
}
|
||||||
|
|
||||||
const ast = this.parser.parse(m);
|
const ast = this.parser.parse(m);
|
||||||
const encodedEmojis = toShort(m);
|
this.isMessageContainsOnlyEmoji = isOnlyEmoji(m) && emojiCount(m) <= 3;
|
||||||
this.isMessageContainsOnlyEmoji = isOnlyEmoji(encodedEmojis) && emojiCount(encodedEmojis) <= 3;
|
|
||||||
|
|
||||||
this.editedMessage(ast);
|
this.editedMessage(ast);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue