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

actions.js 3.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. // @flow
  2. import {
  3. NOTIFICATION_TIMEOUT_TYPE,
  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. titleKey: 'dialog.transcribing'
  70. }, NOTIFICATION_TIMEOUT_TYPE.LONG));
  71. if (notification) {
  72. dispatch(setPendingTranscribingNotificationUid(notification.uid));
  73. }
  74. };
  75. }
  76. /**
  77. * Sets UID of the the pending transcribing notification to use it when hiding
  78. * the notification is necessary, or unsets it when undefined (or no param) is
  79. * passed.
  80. *
  81. * @param {?number} uid - The UID of the notification.
  82. * @returns {{
  83. * type: SET_PENDING_TRANSCRIBING_NOTIFICATION_UID,
  84. * uid: number
  85. * }}
  86. */
  87. export function setPendingTranscribingNotificationUid(uid: ?number) {
  88. return {
  89. type: SET_PENDING_TRANSCRIBING_NOTIFICATION_UID,
  90. uid
  91. };
  92. }
  93. /**
  94. * Signals that the pending transcribing notification should be removed from the
  95. * screen.
  96. *
  97. * @returns {Function}
  98. */
  99. export function hidePendingTranscribingNotification() {
  100. return (dispatch: Function, getState: Function) => {
  101. const { pendingNotificationUid } = getState()['features/transcribing'];
  102. if (pendingNotificationUid) {
  103. dispatch(hideNotification(pendingNotificationUid));
  104. dispatch(setPendingTranscribingNotificationUid());
  105. }
  106. };
  107. }
  108. /**
  109. * Signals that the stopped transcribing notification should be shown on the
  110. * screen.
  111. *
  112. * @returns {showNotification}
  113. */
  114. export function showStoppedTranscribingNotification() {
  115. return showNotification({
  116. descriptionKey: 'transcribing.off',
  117. titleKey: 'dialog.transcribing'
  118. }, NOTIFICATION_TIMEOUT_TYPE.SHORT);
  119. }
  120. /**
  121. * Signals that the transcribing error notification should be shown.
  122. *
  123. * @returns {showErrorNotification}
  124. */
  125. export function showTranscribingError() {
  126. return showErrorNotification({
  127. descriptionKey: 'transcribing.error',
  128. titleKey: 'transcribing.failedToStart'
  129. }, NOTIFICATION_TIMEOUT_TYPE.LONG);
  130. }