Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

function.any.ts 2.4KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. import { IReduxState } from '../app/types';
  2. import { GIF_PREFIX } from './constants';
  3. import { IGif } from './reducer';
  4. /**
  5. * Gets the URL of the GIF for the given participant or null if there's none.
  6. *
  7. * @param {IReduxState} state - Redux state.
  8. * @param {string} participantId - Id of the participant for which to remove the GIF.
  9. * @returns {Object}
  10. */
  11. export function getGifForParticipant(state: IReduxState, participantId: string): IGif {
  12. return isGifEnabled(state) ? state['features/gifs'].gifList.get(participantId) || {} : {};
  13. }
  14. /**
  15. * Whether or not the message is a GIF message.
  16. *
  17. * @param {string} message - Message to check.
  18. * @returns {boolean}
  19. */
  20. export function isGifMessage(message: string) {
  21. return message.trim().toLowerCase()
  22. .startsWith(GIF_PREFIX);
  23. }
  24. /**
  25. * Returns the url of the gif selected in the gifs menu.
  26. *
  27. * @param {Object} gif - The gif data.
  28. * @returns {boolean}
  29. */
  30. export function getGifUrl(gif?: { data?: { embed_url: string; }; embed_url?: string; }) {
  31. const embedUrl = gif?.embed_url || gif?.data?.embed_url || '';
  32. const idx = embedUrl.lastIndexOf('/');
  33. const id = embedUrl.substr(idx + 1);
  34. return `https://i.giphy.com/media/${id}/giphy.gif`;
  35. }
  36. /**
  37. * Formats the gif message.
  38. *
  39. * @param {string} url - GIF url.
  40. * @returns {string}
  41. */
  42. export function formatGifUrlMessage(url: string) {
  43. return `${GIF_PREFIX}${url}]`;
  44. }
  45. /**
  46. * Get the Giphy API Key from config.
  47. *
  48. * @param {IReduxState} state - Redux state.
  49. * @returns {string}
  50. */
  51. export function getGifAPIKey(state: IReduxState) {
  52. return state['features/base/config']?.giphy?.sdkKey ?? '';
  53. }
  54. /**
  55. * Returns whether or not the feature is enabled.
  56. *
  57. * @param {IReduxState} state - Redux state.
  58. * @returns {boolean}
  59. */
  60. export function isGifEnabled(state: IReduxState) {
  61. const { disableThirdPartyRequests } = state['features/base/config'];
  62. const { giphy } = state['features/base/config'];
  63. if (navigator.product === 'ReactNative' && window.JITSI_MEET_LITE_SDK) {
  64. return false;
  65. }
  66. return Boolean(!disableThirdPartyRequests && giphy?.enabled && Boolean(giphy?.sdkKey));
  67. }
  68. /**
  69. * Get the GIF display mode.
  70. *
  71. * @param {IReduxState} state - Redux state.
  72. * @returns {string}
  73. */
  74. export function getGifDisplayMode(state: IReduxState) {
  75. const { giphy } = state['features/base/config'];
  76. return giphy?.displayMode || 'all';
  77. }