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.2KB

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