Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

actions.js 5.8KB

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