You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

actions.js 2.5KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. import jitsiLocalStorage from '../../../modules/util/JitsiLocalStorage';
  2. import {
  3. HIDE_NOTIFICATION,
  4. SET_NOTIFICATIONS_ENABLED,
  5. SHOW_NOTIFICATION
  6. } from './actionTypes';
  7. import { NotificationWithToggle } from './components';
  8. /**
  9. * Removes the notification with the passed in id.
  10. *
  11. * @param {string} uid - The unique identifier for the notification to be
  12. * removed.
  13. * @returns {{
  14. * type: HIDE_NOTIFICATION,
  15. * uid: number
  16. * }}
  17. */
  18. export function hideNotification(uid) {
  19. return {
  20. type: HIDE_NOTIFICATION,
  21. uid
  22. };
  23. }
  24. /**
  25. * Stops notifications from being displayed.
  26. *
  27. * @param {boolean} enabled - Whether or not notifications should display.
  28. * @returns {{
  29. * type: SET_NOTIFICATIONS_ENABLED,
  30. * enabled: boolean
  31. * }}
  32. */
  33. export function setNotificationsEnabled(enabled) {
  34. return {
  35. type: SET_NOTIFICATIONS_ENABLED,
  36. enabled
  37. };
  38. }
  39. /**
  40. * Queues a notification for display.
  41. *
  42. * @param {ReactComponent} component - The notification component to be
  43. * displayed.
  44. * @param {Object} props - The props needed to show the notification component.
  45. * @param {number} timeout - How long the notification should display before
  46. * automatically being hidden.
  47. * @returns {{
  48. * type: SHOW_NOTIFICATION,
  49. * component: ReactComponent,
  50. * props: Object,
  51. * timeout: number,
  52. * uid: number
  53. * }}
  54. */
  55. export function showNotification(component, props = {}, timeout) {
  56. return {
  57. type: SHOW_NOTIFICATION,
  58. component,
  59. props,
  60. timeout,
  61. uid: window.Date.now()
  62. };
  63. }
  64. /**
  65. * Displays a notification unless the passed in persistenceKey value exists in
  66. * local storage and has been set to "true".
  67. *
  68. * @param {string} persistenceKey - The local storage key to look up for whether
  69. * or not the notification should display.
  70. * @param {Object} props - The props needed to show the notification component.
  71. * @returns {Function}
  72. */
  73. export function maybeShowNotificationWithDoNotDisplay(persistenceKey, props) {
  74. return dispatch => {
  75. if (jitsiLocalStorage.getItem(persistenceKey) === 'true') {
  76. return;
  77. }
  78. const newProps = Object.assign({}, props, {
  79. onToggleSubmit: isToggled => {
  80. jitsiLocalStorage.setItem(persistenceKey, isToggled);
  81. }
  82. });
  83. dispatch({
  84. type: SHOW_NOTIFICATION,
  85. component: NotificationWithToggle,
  86. props: newProps,
  87. uid: window.Date.now()
  88. });
  89. };
  90. }