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.ts 5.9KB

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