mirror of
https://gitcode.com/GitHub_Trending/ji/jitsi-meet.git
synced 2025-12-30 11:22:31 +00:00
fix(gifs): trim the message before extracting the URL.
This commit is contained in:
@@ -4,8 +4,7 @@ import { connect } from 'react-redux';
|
||||
|
||||
import { IReduxState } from '../../../../app/types';
|
||||
import GifMessage from '../../../../chat/components/web/GifMessage';
|
||||
import { GIF_PREFIX } from '../../../../gifs/constants';
|
||||
import { isGifEnabled, isGifMessage } from '../../../../gifs/functions.web';
|
||||
import { extractGifURL, isGifEnabled, isGifMessage } from '../../../../gifs/functions.web';
|
||||
|
||||
import Linkify from './Linkify';
|
||||
|
||||
@@ -55,7 +54,7 @@ class Message extends Component<IProps> {
|
||||
|
||||
// check if the message is a GIF
|
||||
if (gifEnabled && isGifMessage(text)) {
|
||||
const url = text.substring(GIF_PREFIX.length, text.length - 1);
|
||||
const url = extractGifURL(text);
|
||||
|
||||
content.push(<GifMessage
|
||||
key = { url }
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import React from 'react';
|
||||
import { Image, ImageStyle, View } from 'react-native';
|
||||
|
||||
import { GIF_PREFIX } from '../../../gifs/constants';
|
||||
import { extractGifURL } from '../../../gifs/function.any';
|
||||
|
||||
import styles from './styles';
|
||||
|
||||
@@ -14,7 +14,7 @@ interface IProps {
|
||||
}
|
||||
|
||||
const GifMessage = ({ message }: IProps) => {
|
||||
const url = message.substring(GIF_PREFIX.length, message.length - 1);
|
||||
const url = extractGifURL(message);
|
||||
|
||||
return (<View
|
||||
id = 'gif-message'
|
||||
|
||||
@@ -24,8 +24,7 @@ import MiddlewareRegistry from '../base/redux/MiddlewareRegistry';
|
||||
import StateListenerRegistry from '../base/redux/StateListenerRegistry';
|
||||
import { playSound, registerSound, unregisterSound } from '../base/sounds/actions';
|
||||
import { addGif } from '../gifs/actions';
|
||||
import { GIF_PREFIX } from '../gifs/constants';
|
||||
import { getGifDisplayMode, isGifEnabled, isGifMessage } from '../gifs/function.any';
|
||||
import { extractGifURL, getGifDisplayMode, isGifEnabled, isGifMessage } from '../gifs/function.any';
|
||||
import { showMessageNotification } from '../notifications/actions';
|
||||
import { NOTIFICATION_TIMEOUT_TYPE } from '../notifications/constants';
|
||||
import { resetNbUnreadPollsMessages } from '../polls/actions';
|
||||
@@ -351,7 +350,7 @@ function _onConferenceMessageReceived(store: IStore,
|
||||
* @returns {void}
|
||||
*/
|
||||
function _handleGifMessageReceived(store: IStore, participantId: string, message: string) {
|
||||
const url = message.substring(GIF_PREFIX.length, message.length - 1);
|
||||
const url = extractGifURL(message);
|
||||
|
||||
store.dispatch(addGif(participantId, url));
|
||||
}
|
||||
|
||||
@@ -71,11 +71,29 @@ export function isGifUrlAllowed(url: string) {
|
||||
* @param {string} message - Message to check.
|
||||
* @returns {boolean}
|
||||
*/
|
||||
export function isGifMessage(message: string) {
|
||||
const url = message.substring(GIF_PREFIX.length, message.length - 1);
|
||||
export function isGifMessage(message = '') {
|
||||
const trimmedMessage = message.trim();
|
||||
|
||||
if (!trimmedMessage.toLowerCase().startsWith(GIF_PREFIX)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const url = extractGifURL(trimmedMessage);
|
||||
|
||||
return isGifUrlAllowed(url);
|
||||
}
|
||||
|
||||
/**
|
||||
* Extracts the URL from a gif message.
|
||||
*
|
||||
* @param {string} message - The message.
|
||||
* @returns {string} - The URL.
|
||||
*/
|
||||
export function extractGifURL(message = '') {
|
||||
const trimmedMessage = message.trim();
|
||||
|
||||
return trimmedMessage.substring(GIF_PREFIX.length, trimmedMessage.length - 1);
|
||||
|
||||
return message.trim().toLowerCase()
|
||||
.startsWith(GIF_PREFIX) && isGifUrlAllowed(url);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user