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

actions.js 4.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. // @flow
  2. import type { Dispatch } from 'redux';
  3. import { FEEDBACK_REQUEST_IN_PROGRESS } from '../../../modules/UI/UIErrors';
  4. import { openDialog } from '../base/dialog';
  5. import {
  6. CANCEL_FEEDBACK,
  7. SUBMIT_FEEDBACK_ERROR,
  8. SUBMIT_FEEDBACK_SUCCESS
  9. } from './actionTypes';
  10. import { FeedbackDialog } from './components';
  11. declare var config: Object;
  12. declare var interfaceConfig: Object;
  13. /**
  14. * Caches the passed in feedback in the redux store.
  15. *
  16. * @param {number} score - The quality score given to the conference.
  17. * @param {string} message - A description entered by the participant that
  18. * explains the rating.
  19. * @returns {{
  20. * type: CANCEL_FEEDBACK,
  21. * message: string,
  22. * score: number
  23. * }}
  24. */
  25. export function cancelFeedback(score: number, message: string) {
  26. return {
  27. type: CANCEL_FEEDBACK,
  28. message,
  29. score
  30. };
  31. }
  32. /**
  33. * Potentially open the {@code FeedbackDialog}. It will not be opened if it is
  34. * already open or feedback has already been submitted.
  35. *
  36. * @param {JistiConference} conference - The conference for which the feedback
  37. * would be about. The conference is passed in because feedback can occur after
  38. * a conference has been left, so references to it may no longer exist in redux.
  39. * @returns {Promise} Resolved with value - false if the dialog is enabled and
  40. * resolved with true if the dialog is disabled or the feedback was already
  41. * submitted. Rejected if another dialog is already displayed.
  42. */
  43. export function maybeOpenFeedbackDialog(conference: Object) {
  44. type R = {
  45. feedbackSubmitted: boolean,
  46. showThankYou: boolean
  47. };
  48. return (dispatch: Dispatch<any>, getState: Function): Promise<R> => {
  49. const state = getState();
  50. const { feedbackPercentage = 100 } = state['features/base/config'];
  51. if (config.iAmRecorder) {
  52. // Intentionally fall through the if chain to prevent further action
  53. // from being taken with regards to showing feedback.
  54. } else if (state['features/base/dialog'].component === FeedbackDialog) {
  55. // Feedback is currently being displayed.
  56. return Promise.reject(FEEDBACK_REQUEST_IN_PROGRESS);
  57. } else if (state['features/feedback'].submitted) {
  58. // Feedback has been submitted already.
  59. return Promise.resolve({
  60. feedbackSubmitted: true,
  61. showThankYou: true
  62. });
  63. } else if (conference.isCallstatsEnabled() && feedbackPercentage > Math.random() * 100) {
  64. return new Promise(resolve => {
  65. dispatch(openFeedbackDialog(conference, () => {
  66. const { submitted } = getState()['features/feedback'];
  67. resolve({
  68. feedbackSubmitted: submitted,
  69. showThankYou: false
  70. });
  71. }));
  72. });
  73. }
  74. // If the feedback functionality isn't enabled we show a "thank you"
  75. // message. Signaling it (true), so the caller of requestFeedback can
  76. // act on it.
  77. return Promise.resolve({
  78. feedbackSubmitted: false,
  79. showThankYou: true
  80. });
  81. };
  82. }
  83. /**
  84. * Opens {@code FeedbackDialog}.
  85. *
  86. * @param {JitsiConference} conference - The JitsiConference that is being
  87. * rated. The conference is passed in because feedback can occur after a
  88. * conference has been left, so references to it may no longer exist in redux.
  89. * @param {Function} [onClose] - An optional callback to invoke when the dialog
  90. * is closed.
  91. * @returns {Object}
  92. */
  93. export function openFeedbackDialog(conference: Object, onClose: ?Function) {
  94. return openDialog(FeedbackDialog, {
  95. conference,
  96. onClose
  97. });
  98. }
  99. /**
  100. * Send the passed in feedback.
  101. *
  102. * @param {number} score - An integer between 1 and 5 indicating the user
  103. * feedback. The negative integer -1 is used to denote no score was selected.
  104. * @param {string} message - Detailed feedback from the user to explain the
  105. * rating.
  106. * @param {JitsiConference} conference - The JitsiConference for which the
  107. * feedback is being left.
  108. * @returns {Function}
  109. */
  110. export function submitFeedback(
  111. score: number,
  112. message: string,
  113. conference: Object) {
  114. return (dispatch: Dispatch<any>) => conference.sendFeedback(score, message)
  115. .then(
  116. () => dispatch({ type: SUBMIT_FEEDBACK_SUCCESS }),
  117. error => {
  118. dispatch({
  119. type: SUBMIT_FEEDBACK_ERROR,
  120. error
  121. });
  122. return Promise.reject(error);
  123. }
  124. );
  125. }