fix(transcribing) refactor notification handling

The current notification system allows us to replce notifications easily
as long as we use a consistent UID.
This commit is contained in:
Saúl Ibarra Corretgé
2024-01-11 17:15:04 +01:00
committed by Saúl Ibarra Corretgé
parent b56073ea68
commit 6cd876078e
5 changed files with 23 additions and 80 deletions

View File

@@ -112,3 +112,10 @@ export const SILENT_JOIN_THRESHOLD = 30;
* Amount of participants beyond which no left notification will be emitted.
*/
export const SILENT_LEFT_THRESHOLD = 30;
/**
* The identifier for the transcriber notifications.
*
* @type {string}
*/
export const TRANSCRIBING_NOTIFICATION_ID = 'TRANSCRIBING_NOTIFICATION';

View File

@@ -32,17 +32,3 @@ export const _TRANSCRIBER_LEFT = 'TRANSCRIBER_LEFT';
*/
export const _POTENTIAL_TRANSCRIBER_JOINED
= 'POTENTIAL_TRANSCRIBER_JOINED';
/**
* The type of Redux action which sets the pending transcribing notification UID
* to use it for when hiding the notification is necessary, or unsets it when
* undefined (or no param) is passed.
*
* {
* type: SET_PENDING_TRANSCRIBING_NOTIFICATION_UID,
* uid: ?number
* }
* @public
*/
export const SET_PENDING_TRANSCRIBING_NOTIFICATION_UID
= 'SET_PENDING_TRANSCRIBING_NOTIFICATION_UID';

View File

@@ -1,9 +1,10 @@
import { IStore } from '../app/types';
import { hideNotification, showErrorNotification, showNotification } from '../notifications/actions';
import { NOTIFICATION_TIMEOUT_TYPE } from '../notifications/constants';
import { showErrorNotification, showNotification } from '../notifications/actions';
import {
NOTIFICATION_TIMEOUT_TYPE,
TRANSCRIBING_NOTIFICATION_ID
} from '../notifications/constants';
import {
SET_PENDING_TRANSCRIBING_NOTIFICATION_UID,
_POTENTIAL_TRANSCRIBER_JOINED,
_TRANSCRIBER_JOINED,
_TRANSCRIBER_LEFT
@@ -61,54 +62,14 @@ export function potentialTranscriberJoined(participantId: string) {
* Signals that the pending transcribing notification should be shown on the
* screen.
*
* @returns {Function}
* @returns {showNotification}
*/
export function showPendingTranscribingNotification() {
return async (dispatch: IStore['dispatch']) => {
const notification = await dispatch(showNotification({
descriptionKey: 'transcribing.pending',
titleKey: 'dialog.transcribing'
}, NOTIFICATION_TIMEOUT_TYPE.LONG));
if (notification) {
dispatch(setPendingTranscribingNotificationUid(notification.uid));
}
};
}
/**
* Sets UID of the the pending transcribing notification to use it when hiding
* the notification is necessary, or unsets it when undefined (or no param) is
* passed.
*
* @param {?number} uid - The UID of the notification.
* @returns {{
* type: SET_PENDING_TRANSCRIBING_NOTIFICATION_UID,
* uid: number
* }}
*/
export function setPendingTranscribingNotificationUid(uid?: string) {
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() {
return (dispatch: IStore['dispatch'], getState: IStore['getState']) => {
const { pendingNotificationUid } = getState()['features/transcribing'];
if (pendingNotificationUid) {
dispatch(hideNotification(pendingNotificationUid));
dispatch(setPendingTranscribingNotificationUid());
}
};
return showNotification({
descriptionKey: 'transcribing.pending',
titleKey: 'dialog.transcribing',
uid: TRANSCRIBING_NOTIFICATION_ID
}, NOTIFICATION_TIMEOUT_TYPE.LONG);
}
/**
@@ -120,7 +81,8 @@ export function hidePendingTranscribingNotification() {
export function showStoppedTranscribingNotification() {
return showNotification({
descriptionKey: 'transcribing.off',
titleKey: 'dialog.transcribing'
titleKey: 'dialog.transcribing',
uid: TRANSCRIBING_NOTIFICATION_ID
}, NOTIFICATION_TIMEOUT_TYPE.SHORT);
}
@@ -133,6 +95,7 @@ export function showStoppedTranscribingNotification() {
export function showTranscribingError() {
return showErrorNotification({
descriptionKey: 'transcribing.error',
titleKey: 'transcribing.failedToStart'
titleKey: 'transcribing.failedToStart',
uid: TRANSCRIBING_NOTIFICATION_ID
}, NOTIFICATION_TIMEOUT_TYPE.LONG);
}

View File

@@ -1,5 +1,3 @@
import { batch } from 'react-redux';
import {
HIDDEN_PARTICIPANT_JOINED,
HIDDEN_PARTICIPANT_LEFT,
@@ -14,7 +12,6 @@ import {
_TRANSCRIBER_LEFT
} from './actionTypes';
import {
hidePendingTranscribingNotification,
potentialTranscriberJoined,
showPendingTranscribingNotification,
showStoppedTranscribingNotification,
@@ -78,10 +75,7 @@ MiddlewareRegistry.register(({ dispatch, getState }) => next => action => {
const { participant } = action;
if (potentialTranscriberJIDs.includes(participant.id) && participant.name === TRANSCRIBER_DISPLAY_NAME) {
batch(() => {
dispatch(transcriberJoined(participant.id));
dispatch(hidePendingTranscribingNotification());
});
dispatch(transcriberJoined(participant.id));
}
break;

View File

@@ -1,7 +1,6 @@
import ReducerRegistry from '../base/redux/ReducerRegistry';
import {
SET_PENDING_TRANSCRIBING_NOTIFICATION_UID,
_POTENTIAL_TRANSCRIBER_JOINED,
_TRANSCRIBER_JOINED,
_TRANSCRIBER_LEFT
@@ -45,7 +44,6 @@ function _getInitialState() {
export interface ITranscribingState {
isTranscribing: boolean;
pendingNotificationUid?: string;
potentialTranscriberJIDs: string[];
transcriberJID?: string | null;
}
@@ -74,11 +72,6 @@ ReducerRegistry.register<ITranscribingState>('features/transcribing',
...state,
potentialTranscriberJIDs: [ action.transcriberJID, ...state.potentialTranscriberJIDs ]
};
case SET_PENDING_TRANSCRIBING_NOTIFICATION_UID:
return {
...state,
pendingNotificationUid: action.uid
};
default:
return state;
}