mirror of
https://github.com/vector-im/element-web.git
synced 2024-11-16 13:14:58 +08:00
Merge pull request #1394 from matrix-org/dbkr/emoji_more_fast_path
Don't check for only-emoji if there were none
This commit is contained in:
commit
5bf8c1e95f
@ -58,10 +58,7 @@ export function containsEmoji(str) {
|
|||||||
/* modified from https://github.com/Ranks/emojione/blob/master/lib/js/emojione.js
|
/* modified from https://github.com/Ranks/emojione/blob/master/lib/js/emojione.js
|
||||||
* because we want to include emoji shortnames in title text
|
* because we want to include emoji shortnames in title text
|
||||||
*/
|
*/
|
||||||
export function unicodeToImage(str) {
|
function unicodeToImage(str) {
|
||||||
// fast path
|
|
||||||
if (!containsEmoji(str)) return str;
|
|
||||||
|
|
||||||
let replaceWith, unicode, alt, short, fname;
|
let replaceWith, unicode, alt, short, fname;
|
||||||
const mappedUnicode = emojione.mapUnicodeToShort();
|
const mappedUnicode = emojione.mapUnicodeToShort();
|
||||||
|
|
||||||
@ -399,6 +396,8 @@ export function bodyToHtml(content, highlights, opts) {
|
|||||||
var isHtml = (content.format === "org.matrix.custom.html");
|
var isHtml = (content.format === "org.matrix.custom.html");
|
||||||
let body = isHtml ? content.formatted_body : escape(content.body);
|
let body = isHtml ? content.formatted_body : escape(content.body);
|
||||||
|
|
||||||
|
let bodyHasEmoji = false;
|
||||||
|
|
||||||
var safeBody;
|
var safeBody;
|
||||||
// XXX: We sanitize the HTML whilst also highlighting its text nodes, to avoid accidentally trying
|
// XXX: We sanitize the HTML whilst also highlighting its text nodes, to avoid accidentally trying
|
||||||
// to highlight HTML tags themselves. However, this does mean that we don't highlight textnodes which
|
// to highlight HTML tags themselves. However, this does mean that we don't highlight textnodes which
|
||||||
@ -416,16 +415,20 @@ export function bodyToHtml(content, highlights, opts) {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
safeBody = sanitizeHtml(body, sanitizeHtmlParams);
|
safeBody = sanitizeHtml(body, sanitizeHtmlParams);
|
||||||
safeBody = unicodeToImage(safeBody);
|
bodyHasEmoji = containsEmoji(body);
|
||||||
|
if (bodyHasEmoji) safeBody = unicodeToImage(safeBody);
|
||||||
}
|
}
|
||||||
finally {
|
finally {
|
||||||
delete sanitizeHtmlParams.textFilter;
|
delete sanitizeHtmlParams.textFilter;
|
||||||
}
|
}
|
||||||
|
|
||||||
EMOJI_REGEX.lastIndex = 0;
|
let emojiBody = false;
|
||||||
let contentBodyTrimmed = content.body !== undefined ? content.body.trim() : '';
|
if (bodyHasEmoji) {
|
||||||
let match = EMOJI_REGEX.exec(contentBodyTrimmed);
|
EMOJI_REGEX.lastIndex = 0;
|
||||||
let emojiBody = match && match[0] && match[0].length === contentBodyTrimmed.length;
|
let contentBodyTrimmed = content.body !== undefined ? content.body.trim() : '';
|
||||||
|
let match = EMOJI_REGEX.exec(contentBodyTrimmed);
|
||||||
|
emojiBody = match && match[0] && match[0].length === contentBodyTrimmed.length;
|
||||||
|
}
|
||||||
|
|
||||||
const className = classNames({
|
const className = classNames({
|
||||||
'mx_EventTile_body': true,
|
'mx_EventTile_body': true,
|
||||||
|
Loading…
Reference in New Issue
Block a user