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

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