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

actions.js 4.2KB

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