2022-10-26 06:59:21 +00:00
|
|
|
import { IStore } from '../app/types';
|
|
|
|
import { hideNotification, showErrorNotification, showNotification } from '../notifications/actions';
|
|
|
|
import { NOTIFICATION_TIMEOUT_TYPE } from '../notifications/constants';
|
2018-07-26 16:33:40 +00:00
|
|
|
|
2020-05-20 10:57:03 +00:00
|
|
|
import {
|
2022-09-27 07:10:28 +00:00
|
|
|
SET_PENDING_TRANSCRIBING_NOTIFICATION_UID,
|
2020-05-20 10:57:03 +00:00
|
|
|
_POTENTIAL_TRANSCRIBER_JOINED,
|
|
|
|
_TRANSCRIBER_JOINED,
|
2022-09-27 07:10:28 +00:00
|
|
|
_TRANSCRIBER_LEFT
|
2020-05-20 10:57:03 +00:00
|
|
|
} from './actionTypes';
|
|
|
|
|
2018-07-26 16:33:40 +00:00
|
|
|
/**
|
|
|
|
* Notify that the transcriber, with a unique ID, has joined.
|
|
|
|
*
|
|
|
|
* @param {string} participantId - The participant id of the transcriber.
|
|
|
|
* @returns {{
|
|
|
|
* type: _TRANSCRIBER_JOINED,
|
|
|
|
* participantId: string
|
|
|
|
* }}
|
|
|
|
*/
|
|
|
|
export function transcriberJoined(participantId: string) {
|
|
|
|
return {
|
|
|
|
type: _TRANSCRIBER_JOINED,
|
|
|
|
transcriberJID: participantId
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Notify that the transcriber, with a unique ID, has left.
|
|
|
|
*
|
|
|
|
* @param {string} participantId - The participant id of the transcriber.
|
|
|
|
* @returns {{
|
|
|
|
* type: _TRANSCRIBER_LEFT,
|
|
|
|
* participantId: string
|
|
|
|
* }}
|
|
|
|
*/
|
|
|
|
export function transcriberLeft(participantId: string) {
|
|
|
|
return {
|
|
|
|
type: _TRANSCRIBER_LEFT,
|
|
|
|
transcriberJID: participantId
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Notify that a potential transcriber, with a unique ID, has joined.
|
|
|
|
*
|
|
|
|
* @param {string} participantId - The participant id of the transcriber.
|
|
|
|
* @returns {{
|
|
|
|
* type: _POTENTIAL_TRANSCRIBER_JOINED,
|
|
|
|
* participantId: string
|
|
|
|
* }}
|
|
|
|
*/
|
|
|
|
export function potentialTranscriberJoined(participantId: string) {
|
|
|
|
return {
|
|
|
|
type: _POTENTIAL_TRANSCRIBER_JOINED,
|
|
|
|
transcriberJID: participantId
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Signals that the pending transcribing notification should be shown on the
|
|
|
|
* screen.
|
|
|
|
*
|
|
|
|
* @returns {Function}
|
|
|
|
*/
|
|
|
|
export function showPendingTranscribingNotification() {
|
2022-10-26 06:59:21 +00:00
|
|
|
return async (dispatch: IStore['dispatch']) => {
|
2021-01-11 10:52:52 +00:00
|
|
|
const notification = await dispatch(showNotification({
|
2018-07-26 16:33:40 +00:00
|
|
|
descriptionKey: 'transcribing.pending',
|
|
|
|
titleKey: 'dialog.transcribing'
|
2021-11-24 11:05:27 +00:00
|
|
|
}, NOTIFICATION_TIMEOUT_TYPE.LONG));
|
2018-07-26 16:33:40 +00:00
|
|
|
|
2021-01-11 10:52:52 +00:00
|
|
|
if (notification) {
|
|
|
|
dispatch(setPendingTranscribingNotificationUid(notification.uid));
|
|
|
|
}
|
2018-07-26 16:33:40 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets UID of the the pending transcribing notification to use it when hiding
|
2018-11-08 12:25:02 +00:00
|
|
|
* the notification is necessary, or unsets it when undefined (or no param) is
|
|
|
|
* passed.
|
2018-07-26 16:33:40 +00:00
|
|
|
*
|
|
|
|
* @param {?number} uid - The UID of the notification.
|
|
|
|
* @returns {{
|
|
|
|
* type: SET_PENDING_TRANSCRIBING_NOTIFICATION_UID,
|
|
|
|
* uid: number
|
|
|
|
* }}
|
|
|
|
*/
|
2022-10-26 06:59:21 +00:00
|
|
|
export function setPendingTranscribingNotificationUid(uid?: string) {
|
2018-07-26 16:33:40 +00:00
|
|
|
return {
|
|
|
|
type: SET_PENDING_TRANSCRIBING_NOTIFICATION_UID,
|
|
|
|
uid
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Signals that the pending transcribing notification should be removed from the
|
|
|
|
* screen.
|
|
|
|
*
|
|
|
|
* @returns {Function}
|
|
|
|
*/
|
|
|
|
export function hidePendingTranscribingNotification() {
|
2022-10-26 06:59:21 +00:00
|
|
|
return (dispatch: IStore['dispatch'], getState: IStore['getState']) => {
|
2018-07-26 16:33:40 +00:00
|
|
|
const { pendingNotificationUid } = getState()['features/transcribing'];
|
|
|
|
|
|
|
|
if (pendingNotificationUid) {
|
|
|
|
dispatch(hideNotification(pendingNotificationUid));
|
|
|
|
dispatch(setPendingTranscribingNotificationUid());
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Signals that the stopped transcribing notification should be shown on the
|
2019-03-29 13:37:50 +00:00
|
|
|
* screen.
|
2018-07-26 16:33:40 +00:00
|
|
|
*
|
|
|
|
* @returns {showNotification}
|
|
|
|
*/
|
|
|
|
export function showStoppedTranscribingNotification() {
|
|
|
|
return showNotification({
|
|
|
|
descriptionKey: 'transcribing.off',
|
|
|
|
titleKey: 'dialog.transcribing'
|
2021-11-24 11:05:27 +00:00
|
|
|
}, NOTIFICATION_TIMEOUT_TYPE.SHORT);
|
2018-07-26 16:33:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Signals that the transcribing error notification should be shown.
|
|
|
|
*
|
|
|
|
* @returns {showErrorNotification}
|
|
|
|
*/
|
|
|
|
export function showTranscribingError() {
|
|
|
|
return showErrorNotification({
|
|
|
|
descriptionKey: 'transcribing.error',
|
|
|
|
titleKey: 'transcribing.failedToStart'
|
2021-11-24 11:05:27 +00:00
|
|
|
}, NOTIFICATION_TIMEOUT_TYPE.LONG);
|
2018-07-26 16:33:40 +00:00
|
|
|
}
|