您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

actions.js 3.6KB

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