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

actions.ts 3.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. import { IStore } from '../app/types';
  2. import { hideNotification, showErrorNotification, showNotification } from '../notifications/actions';
  3. import { NOTIFICATION_TIMEOUT_TYPE } from '../notifications/constants';
  4. import {
  5. SET_PENDING_TRANSCRIBING_NOTIFICATION_UID,
  6. _POTENTIAL_TRANSCRIBER_JOINED,
  7. _TRANSCRIBER_JOINED,
  8. _TRANSCRIBER_LEFT
  9. } from './actionTypes';
  10. /**
  11. * Notify that the transcriber, with a unique ID, has joined.
  12. *
  13. * @param {string} participantId - The participant id of the transcriber.
  14. * @returns {{
  15. * type: _TRANSCRIBER_JOINED,
  16. * participantId: string
  17. * }}
  18. */
  19. export function transcriberJoined(participantId: string) {
  20. return {
  21. type: _TRANSCRIBER_JOINED,
  22. transcriberJID: participantId
  23. };
  24. }
  25. /**
  26. * Notify that the transcriber, with a unique ID, has left.
  27. *
  28. * @param {string} participantId - The participant id of the transcriber.
  29. * @returns {{
  30. * type: _TRANSCRIBER_LEFT,
  31. * participantId: string
  32. * }}
  33. */
  34. export function transcriberLeft(participantId: string) {
  35. return {
  36. type: _TRANSCRIBER_LEFT,
  37. transcriberJID: participantId
  38. };
  39. }
  40. /**
  41. * Notify that a potential transcriber, with a unique ID, has joined.
  42. *
  43. * @param {string} participantId - The participant id of the transcriber.
  44. * @returns {{
  45. * type: _POTENTIAL_TRANSCRIBER_JOINED,
  46. * participantId: string
  47. * }}
  48. */
  49. export function potentialTranscriberJoined(participantId: string) {
  50. return {
  51. type: _POTENTIAL_TRANSCRIBER_JOINED,
  52. transcriberJID: participantId
  53. };
  54. }
  55. /**
  56. * Signals that the pending transcribing notification should be shown on the
  57. * screen.
  58. *
  59. * @returns {Function}
  60. */
  61. export function showPendingTranscribingNotification() {
  62. return async (dispatch: IStore['dispatch']) => {
  63. const notification = await dispatch(showNotification({
  64. descriptionKey: 'transcribing.pending',
  65. titleKey: 'dialog.transcribing'
  66. }, NOTIFICATION_TIMEOUT_TYPE.LONG));
  67. if (notification) {
  68. dispatch(setPendingTranscribingNotificationUid(notification.uid));
  69. }
  70. };
  71. }
  72. /**
  73. * Sets UID of the the pending transcribing notification to use it when hiding
  74. * the notification is necessary, or unsets it when undefined (or no param) is
  75. * passed.
  76. *
  77. * @param {?number} uid - The UID of the notification.
  78. * @returns {{
  79. * type: SET_PENDING_TRANSCRIBING_NOTIFICATION_UID,
  80. * uid: number
  81. * }}
  82. */
  83. export function setPendingTranscribingNotificationUid(uid?: string) {
  84. return {
  85. type: SET_PENDING_TRANSCRIBING_NOTIFICATION_UID,
  86. uid
  87. };
  88. }
  89. /**
  90. * Signals that the pending transcribing notification should be removed from the
  91. * screen.
  92. *
  93. * @returns {Function}
  94. */
  95. export function hidePendingTranscribingNotification() {
  96. return (dispatch: IStore['dispatch'], getState: IStore['getState']) => {
  97. const { pendingNotificationUid } = getState()['features/transcribing'];
  98. if (pendingNotificationUid) {
  99. dispatch(hideNotification(pendingNotificationUid));
  100. dispatch(setPendingTranscribingNotificationUid());
  101. }
  102. };
  103. }
  104. /**
  105. * Signals that the stopped transcribing notification should be shown on the
  106. * screen.
  107. *
  108. * @returns {showNotification}
  109. */
  110. export function showStoppedTranscribingNotification() {
  111. return showNotification({
  112. descriptionKey: 'transcribing.off',
  113. titleKey: 'dialog.transcribing'
  114. }, NOTIFICATION_TIMEOUT_TYPE.SHORT);
  115. }
  116. /**
  117. * Signals that the transcribing error notification should be shown.
  118. *
  119. * @returns {showErrorNotification}
  120. */
  121. export function showTranscribingError() {
  122. return showErrorNotification({
  123. descriptionKey: 'transcribing.error',
  124. titleKey: 'transcribing.failedToStart'
  125. }, NOTIFICATION_TIMEOUT_TYPE.LONG);
  126. }