2022-10-20 09:11:27 +00:00
|
|
|
import { IReduxState } from '../app/types';
|
2022-03-11 13:00:49 +00:00
|
|
|
import { showOverflowDrawer } from '../toolbox/functions.web';
|
|
|
|
|
|
|
|
import { GIF_PREFIX } from './constants';
|
2022-09-29 11:45:34 +00:00
|
|
|
import { IGif } from './reducer';
|
2022-03-11 13:00:49 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the URL of the GIF for the given participant or null if there's none.
|
|
|
|
*
|
2022-10-20 09:11:27 +00:00
|
|
|
* @param {IReduxState} state - Redux state.
|
2022-03-11 13:00:49 +00:00
|
|
|
* @param {string} participantId - Id of the participant for which to remove the GIF.
|
|
|
|
* @returns {Object}
|
|
|
|
*/
|
2022-10-20 09:11:27 +00:00
|
|
|
export function getGifForParticipant(state: IReduxState, participantId: string): IGif {
|
2022-03-30 13:54:03 +00:00
|
|
|
return isGifEnabled(state) ? state['features/gifs'].gifList.get(participantId) || {} : {};
|
2022-03-11 13:00:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Whether or not the message is a GIF message.
|
|
|
|
*
|
|
|
|
* @param {string} message - Message to check.
|
|
|
|
* @returns {boolean}
|
|
|
|
*/
|
2022-09-29 11:45:34 +00:00
|
|
|
export function isGifMessage(message: string) {
|
2022-03-30 13:54:03 +00:00
|
|
|
return message.trim().toLowerCase()
|
|
|
|
.startsWith(GIF_PREFIX);
|
2022-03-11 13:00:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the visibility state of the gifs menu.
|
|
|
|
*
|
2022-10-20 09:11:27 +00:00
|
|
|
* @param {IReduxState} state - The state of the application.
|
2022-03-11 13:00:49 +00:00
|
|
|
* @returns {boolean}
|
|
|
|
*/
|
2022-10-20 09:11:27 +00:00
|
|
|
export function isGifsMenuOpen(state: IReduxState) {
|
2022-03-11 13:00:49 +00:00
|
|
|
const overflowDrawer = showOverflowDrawer(state);
|
|
|
|
const { drawerVisible, menuOpen } = state['features/gifs'];
|
|
|
|
|
|
|
|
return overflowDrawer ? drawerVisible : menuOpen;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the url of the gif selected in the gifs menu.
|
|
|
|
*
|
|
|
|
* @param {Object} gif - The gif data.
|
|
|
|
* @returns {boolean}
|
|
|
|
*/
|
2022-09-29 11:45:34 +00:00
|
|
|
export function getGifUrl(gif?: { data?: { embed_url: string; }; embed_url?: string; }) {
|
2022-03-30 13:54:03 +00:00
|
|
|
const embedUrl = gif?.embed_url || gif?.data?.embed_url || '';
|
2022-03-11 13:00:49 +00:00
|
|
|
const idx = embedUrl.lastIndexOf('/');
|
|
|
|
const id = embedUrl.substr(idx + 1);
|
|
|
|
|
2022-03-30 13:54:03 +00:00
|
|
|
return `https://i.giphy.com/media/${id}/giphy.gif`;
|
2022-03-11 13:00:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Formats the gif message.
|
|
|
|
*
|
|
|
|
* @param {string} url - GIF url.
|
|
|
|
* @returns {string}
|
|
|
|
*/
|
2022-09-29 11:45:34 +00:00
|
|
|
export function formatGifUrlMessage(url: string) {
|
2022-03-11 13:00:49 +00:00
|
|
|
return `${GIF_PREFIX}${url}]`;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the Giphy API Key from config.
|
|
|
|
*
|
2022-10-20 09:11:27 +00:00
|
|
|
* @param {IReduxState} state - Redux state.
|
2022-03-11 13:00:49 +00:00
|
|
|
* @returns {string}
|
|
|
|
*/
|
2022-10-20 09:11:27 +00:00
|
|
|
export function getGifAPIKey(state: IReduxState) {
|
2022-09-29 11:45:34 +00:00
|
|
|
return state['features/base/config']?.giphy?.sdkKey ?? '';
|
2022-03-11 13:00:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns whether or not the feature is enabled.
|
|
|
|
*
|
2022-10-20 09:11:27 +00:00
|
|
|
* @param {IReduxState} state - Redux state.
|
2022-03-11 13:00:49 +00:00
|
|
|
* @returns {boolean}
|
|
|
|
*/
|
2022-10-20 09:11:27 +00:00
|
|
|
export function isGifEnabled(state: IReduxState) {
|
2022-03-11 13:00:49 +00:00
|
|
|
const { disableThirdPartyRequests } = state['features/base/config'];
|
|
|
|
const { giphy } = state['features/base/config'];
|
|
|
|
|
2022-08-01 15:15:59 +00:00
|
|
|
if (navigator.product === 'ReactNative' && window.JITSI_MEET_LITE_SDK) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2022-09-29 11:45:34 +00:00
|
|
|
return Boolean(!disableThirdPartyRequests && giphy?.enabled && Boolean(giphy?.sdkKey));
|
2022-03-11 13:00:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the GIF display mode.
|
|
|
|
*
|
2022-10-20 09:11:27 +00:00
|
|
|
* @param {IReduxState} state - Redux state.
|
2022-03-11 13:00:49 +00:00
|
|
|
* @returns {string}
|
|
|
|
*/
|
2022-10-20 09:11:27 +00:00
|
|
|
export function getGifDisplayMode(state: IReduxState) {
|
2022-03-11 13:00:49 +00:00
|
|
|
const { giphy } = state['features/base/config'];
|
|
|
|
|
|
|
|
return giphy?.displayMode || 'all';
|
|
|
|
}
|