Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

functions.js 2.3KB

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