You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

actions.js 4.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. // @flow
  2. import { openDialog } from '../../features/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. return (dispatch: Dispatch<*>, getState: Function) => {
  40. const state = getState();
  41. if (interfaceConfig.filmStripOnly || config.iAmRecorder) {
  42. // Intentionally fall through the if chain to prevent further action
  43. // from being taken with regards to showing feedback.
  44. } else if (state['features/base/dialog'].component === FeedbackDialog) {
  45. // Feedback is currently being displayed.
  46. return Promise.reject(FEEDBACK_REQUEST_IN_PROGRESS);
  47. } else if (state['features/feedback'].submitted) {
  48. // Feedback has been submitted already.
  49. return Promise.resolve({
  50. thankYouDialogVisible: true,
  51. feedbackSubmitted: true
  52. });
  53. } else if (conference.isCallstatsEnabled()) {
  54. return new Promise(resolve => {
  55. dispatch(openFeedbackDialog(conference, () => {
  56. const { submitted } = getState()['features/feedback'];
  57. resolve({
  58. feedbackSubmitted: submitted,
  59. thankYouDialogVisible: false
  60. });
  61. }));
  62. });
  63. }
  64. // If the feedback functionality isn't enabled we show a thank
  65. // you dialog. Signaling it (true), so the caller
  66. // of requestFeedback can act on it
  67. return Promise.resolve({
  68. thankYouDialogVisible: true,
  69. feedbackSubmitted: false
  70. });
  71. };
  72. }
  73. /**
  74. * Opens {@code FeedbackDialog}.
  75. *
  76. * @param {JitsiConference} conference - The JitsiConference that is being
  77. * rated. The conference is passed in because feedback can occur after a
  78. * conference has been left, so references to it may no longer exist in redux.
  79. * @param {Function} [onClose] - An optional callback to invoke when the dialog
  80. * is closed.
  81. * @returns {Object}
  82. */
  83. export function openFeedbackDialog(conference: Object, onClose: ?Function) {
  84. return openDialog(FeedbackDialog, {
  85. conference,
  86. onClose
  87. });
  88. }
  89. /**
  90. * Send the passed in feedback.
  91. *
  92. * @param {number} score - An integer between 1 and 5 indicating the user
  93. * feedback. The negative integer -1 is used to denote no score was selected.
  94. * @param {string} message - Detailed feedback from the user to explain the
  95. * rating.
  96. * @param {JitsiConference} conference - The JitsiConference for which the
  97. * feedback is being left.
  98. * @returns {{
  99. * type: SUBMIT_FEEDBACK
  100. * }}
  101. */
  102. export function submitFeedback(
  103. score: number,
  104. message: string,
  105. conference: Object) {
  106. conference.sendFeedback(score, message);
  107. return {
  108. type: SUBMIT_FEEDBACK
  109. };
  110. }