mirror of
https://github.com/vector-im/element-web.git
synced 2024-11-16 21:24:59 +08:00
Merge pull request #3069 from matrix-org/jryans/single-emoji
Restrict reactions to a single emoji
This commit is contained in:
commit
8d79c73019
@ -51,6 +51,7 @@ const ZWJ_REGEX = new RegExp("\u200D|\u2003", "g");
|
|||||||
const WHITESPACE_REGEX = new RegExp("\\s", "g");
|
const WHITESPACE_REGEX = new RegExp("\\s", "g");
|
||||||
|
|
||||||
const BIGEMOJI_REGEX = new RegExp(`^(${EMOJIBASE_REGEX.source})+$`, 'i');
|
const BIGEMOJI_REGEX = new RegExp(`^(${EMOJIBASE_REGEX.source})+$`, 'i');
|
||||||
|
const SINGLE_EMOJI_REGEX = new RegExp(`^(${EMOJIBASE_REGEX.source})$`, 'i');
|
||||||
|
|
||||||
const COLOR_REGEX = /^#[0-9a-fA-F]{6}$/;
|
const COLOR_REGEX = /^#[0-9a-fA-F]{6}$/;
|
||||||
|
|
||||||
@ -63,10 +64,19 @@ const PERMITTED_URL_SCHEMES = ['http', 'https', 'ftp', 'mailto', 'magnet'];
|
|||||||
* need emojification.
|
* need emojification.
|
||||||
* unicodeToImage uses this function.
|
* unicodeToImage uses this function.
|
||||||
*/
|
*/
|
||||||
export function containsEmoji(str) {
|
export function mightContainEmoji(str) {
|
||||||
return SURROGATE_PAIR_PATTERN.test(str) || SYMBOL_PATTERN.test(str);
|
return SURROGATE_PAIR_PATTERN.test(str) || SYMBOL_PATTERN.test(str);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns true if the string definitely contains a single emoji.
|
||||||
|
* @param {String} str String to test
|
||||||
|
* @return {Boolean}
|
||||||
|
*/
|
||||||
|
export function isSingleEmoji(str) {
|
||||||
|
return mightContainEmoji(str) && SINGLE_EMOJI_REGEX.test(str);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the shortcode for an emoji character.
|
* Returns the shortcode for an emoji character.
|
||||||
*
|
*
|
||||||
@ -428,7 +438,7 @@ export function bodyToHtml(content, highlights, opts={}) {
|
|||||||
if (opts.stripReplyFallback && formattedBody) formattedBody = ReplyThread.stripHTMLReply(formattedBody);
|
if (opts.stripReplyFallback && formattedBody) formattedBody = ReplyThread.stripHTMLReply(formattedBody);
|
||||||
strippedBody = opts.stripReplyFallback ? ReplyThread.stripPlainReply(content.body) : content.body;
|
strippedBody = opts.stripReplyFallback ? ReplyThread.stripPlainReply(content.body) : content.body;
|
||||||
|
|
||||||
bodyHasEmoji = containsEmoji(isHtmlMessage ? formattedBody : content.body);
|
bodyHasEmoji = mightContainEmoji(isHtmlMessage ? formattedBody : content.body);
|
||||||
|
|
||||||
// Only generate safeBody if the message was sent as org.matrix.custom.html
|
// Only generate safeBody if the message was sent as org.matrix.custom.html
|
||||||
if (isHtmlMessage) {
|
if (isHtmlMessage) {
|
||||||
|
@ -19,6 +19,7 @@ import PropTypes from 'prop-types';
|
|||||||
|
|
||||||
import sdk from '../../../index';
|
import sdk from '../../../index';
|
||||||
import { isContentActionable } from '../../../utils/EventUtils';
|
import { isContentActionable } from '../../../utils/EventUtils';
|
||||||
|
import { isSingleEmoji } from '../../../HtmlUtils';
|
||||||
import MatrixClientPeg from '../../../MatrixClientPeg';
|
import MatrixClientPeg from '../../../MatrixClientPeg';
|
||||||
|
|
||||||
export default class ReactionsRow extends React.PureComponent {
|
export default class ReactionsRow extends React.PureComponent {
|
||||||
@ -103,6 +104,9 @@ export default class ReactionsRow extends React.PureComponent {
|
|||||||
|
|
||||||
const ReactionsRowButton = sdk.getComponent('messages.ReactionsRowButton');
|
const ReactionsRowButton = sdk.getComponent('messages.ReactionsRowButton');
|
||||||
const items = reactions.getSortedAnnotationsByKey().map(([content, events]) => {
|
const items = reactions.getSortedAnnotationsByKey().map(([content, events]) => {
|
||||||
|
if (!isSingleEmoji(content)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
const count = events.size;
|
const count = events.size;
|
||||||
if (!count) {
|
if (!count) {
|
||||||
return null;
|
return null;
|
||||||
|
Loading…
Reference in New Issue
Block a user