2017-10-03 19:24:00 +00:00
|
|
|
// @flow
|
2017-08-07 16:20:44 +00:00
|
|
|
|
2019-03-19 15:42:25 +00:00
|
|
|
import type { Dispatch } from 'redux';
|
|
|
|
|
2017-10-03 19:24:00 +00:00
|
|
|
import { FEEDBACK_REQUEST_IN_PROGRESS } from '../../../modules/UI/UIErrors';
|
2020-05-20 10:57:03 +00:00
|
|
|
import { openDialog } from '../base/dialog';
|
2017-08-07 16:20:44 +00:00
|
|
|
|
2019-07-31 17:59:22 +00:00
|
|
|
import {
|
|
|
|
CANCEL_FEEDBACK,
|
|
|
|
SUBMIT_FEEDBACK_ERROR,
|
|
|
|
SUBMIT_FEEDBACK_SUCCESS
|
|
|
|
} from './actionTypes';
|
2017-08-07 16:20:44 +00:00
|
|
|
import { FeedbackDialog } from './components';
|
|
|
|
|
|
|
|
declare var config: Object;
|
|
|
|
declare var interfaceConfig: Object;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Caches the passed in feedback in the redux store.
|
|
|
|
*
|
|
|
|
* @param {number} score - The quality score given to the conference.
|
|
|
|
* @param {string} message - A description entered by the participant that
|
|
|
|
* explains the rating.
|
|
|
|
* @returns {{
|
|
|
|
* type: CANCEL_FEEDBACK,
|
|
|
|
* message: string,
|
|
|
|
* score: number
|
|
|
|
* }}
|
|
|
|
*/
|
2017-10-03 19:24:00 +00:00
|
|
|
export function cancelFeedback(score: number, message: string) {
|
2017-08-07 16:20:44 +00:00
|
|
|
return {
|
|
|
|
type: CANCEL_FEEDBACK,
|
|
|
|
message,
|
|
|
|
score
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Potentially open the {@code FeedbackDialog}. It will not be opened if it is
|
|
|
|
* already open or feedback has already been submitted.
|
|
|
|
*
|
|
|
|
* @param {JistiConference} conference - The conference for which the feedback
|
|
|
|
* would be about. The conference is passed in because feedback can occur after
|
|
|
|
* a conference has been left, so references to it may no longer exist in redux.
|
|
|
|
* @returns {Promise} Resolved with value - false if the dialog is enabled and
|
|
|
|
* resolved with true if the dialog is disabled or the feedback was already
|
|
|
|
* submitted. Rejected if another dialog is already displayed.
|
|
|
|
*/
|
2017-10-03 19:24:00 +00:00
|
|
|
export function maybeOpenFeedbackDialog(conference: Object) {
|
2017-12-01 21:07:58 +00:00
|
|
|
type R = {
|
|
|
|
feedbackSubmitted: boolean,
|
2017-12-11 18:44:38 +00:00
|
|
|
showThankYou: boolean
|
2017-12-01 21:07:58 +00:00
|
|
|
};
|
|
|
|
|
2019-03-19 15:42:25 +00:00
|
|
|
return (dispatch: Dispatch<any>, getState: Function): Promise<R> => {
|
2017-08-07 16:20:44 +00:00
|
|
|
const state = getState();
|
2020-02-12 09:20:59 +00:00
|
|
|
const { feedbackPercentage = 100 } = state['features/base/config'];
|
2017-08-07 16:20:44 +00:00
|
|
|
|
|
|
|
if (interfaceConfig.filmStripOnly || config.iAmRecorder) {
|
|
|
|
// Intentionally fall through the if chain to prevent further action
|
|
|
|
// from being taken with regards to showing feedback.
|
|
|
|
} else if (state['features/base/dialog'].component === FeedbackDialog) {
|
|
|
|
// Feedback is currently being displayed.
|
|
|
|
|
|
|
|
return Promise.reject(FEEDBACK_REQUEST_IN_PROGRESS);
|
|
|
|
} else if (state['features/feedback'].submitted) {
|
|
|
|
// Feedback has been submitted already.
|
|
|
|
|
|
|
|
return Promise.resolve({
|
2017-10-13 19:31:05 +00:00
|
|
|
feedbackSubmitted: true,
|
2017-12-11 18:44:38 +00:00
|
|
|
showThankYou: true
|
2017-08-07 16:20:44 +00:00
|
|
|
});
|
2020-02-12 09:20:59 +00:00
|
|
|
} else if (conference.isCallstatsEnabled() && feedbackPercentage > Math.random() * 100) {
|
2017-08-07 16:20:44 +00:00
|
|
|
return new Promise(resolve => {
|
|
|
|
dispatch(openFeedbackDialog(conference, () => {
|
|
|
|
const { submitted } = getState()['features/feedback'];
|
|
|
|
|
|
|
|
resolve({
|
|
|
|
feedbackSubmitted: submitted,
|
2017-12-11 18:44:38 +00:00
|
|
|
showThankYou: false
|
2017-08-07 16:20:44 +00:00
|
|
|
});
|
|
|
|
}));
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2017-10-13 19:31:05 +00:00
|
|
|
// If the feedback functionality isn't enabled we show a "thank you"
|
2017-12-11 18:44:38 +00:00
|
|
|
// message. Signaling it (true), so the caller of requestFeedback can
|
|
|
|
// act on it.
|
2017-08-07 16:20:44 +00:00
|
|
|
return Promise.resolve({
|
2017-10-13 19:31:05 +00:00
|
|
|
feedbackSubmitted: false,
|
2017-12-11 18:44:38 +00:00
|
|
|
showThankYou: true
|
2017-08-07 16:20:44 +00:00
|
|
|
});
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Opens {@code FeedbackDialog}.
|
|
|
|
*
|
|
|
|
* @param {JitsiConference} conference - The JitsiConference that is being
|
|
|
|
* rated. The conference is passed in because feedback can occur after a
|
|
|
|
* conference has been left, so references to it may no longer exist in redux.
|
|
|
|
* @param {Function} [onClose] - An optional callback to invoke when the dialog
|
|
|
|
* is closed.
|
|
|
|
* @returns {Object}
|
|
|
|
*/
|
2017-10-03 19:24:00 +00:00
|
|
|
export function openFeedbackDialog(conference: Object, onClose: ?Function) {
|
2017-08-07 16:20:44 +00:00
|
|
|
return openDialog(FeedbackDialog, {
|
|
|
|
conference,
|
|
|
|
onClose
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Send the passed in feedback.
|
|
|
|
*
|
|
|
|
* @param {number} score - An integer between 1 and 5 indicating the user
|
|
|
|
* feedback. The negative integer -1 is used to denote no score was selected.
|
|
|
|
* @param {string} message - Detailed feedback from the user to explain the
|
|
|
|
* rating.
|
|
|
|
* @param {JitsiConference} conference - The JitsiConference for which the
|
|
|
|
* feedback is being left.
|
2019-07-31 17:59:22 +00:00
|
|
|
* @returns {Function}
|
2017-08-07 16:20:44 +00:00
|
|
|
*/
|
2017-10-03 19:24:00 +00:00
|
|
|
export function submitFeedback(
|
|
|
|
score: number,
|
|
|
|
message: string,
|
|
|
|
conference: Object) {
|
2019-07-31 17:59:22 +00:00
|
|
|
return (dispatch: Dispatch<any>) => conference.sendFeedback(score, message)
|
|
|
|
.then(
|
|
|
|
() => dispatch({ type: SUBMIT_FEEDBACK_SUCCESS }),
|
|
|
|
error => {
|
|
|
|
dispatch({
|
|
|
|
type: SUBMIT_FEEDBACK_ERROR,
|
|
|
|
error
|
|
|
|
});
|
2017-08-07 16:20:44 +00:00
|
|
|
|
2019-07-31 17:59:22 +00:00
|
|
|
return Promise.reject(error);
|
|
|
|
}
|
|
|
|
);
|
2017-08-07 16:20:44 +00:00
|
|
|
}
|