Skip to content

Commit 82c5817

Browse files
authored
feat(visitors): Adds notification for promotion requests. (#14316)
* feat(visitors): Adds notification for promotion requests. * squash: fixes lint.
1 parent 46d15a9 commit 82c5817

File tree

3 files changed

+96
-5
lines changed

3 files changed

+96
-5
lines changed

react/features/notifications/constants.ts

+7
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,13 @@ export const RAISE_HAND_NOTIFICATION_ID = 'RAISE_HAND_NOTIFICATION';
103103
*/
104104
export const SALESFORCE_LINK_NOTIFICATION_ID = 'SALESFORCE_LINK_NOTIFICATION';
105105

106+
/**
107+
* The identifier of the lobby notification.
108+
*
109+
* @type {string}
110+
*/
111+
export const VISITORS_PROMOTION_NOTIFICATION_ID = 'VISITORS_PROMOTION_NOTIFICATION';
112+
106113
/**
107114
* Amount of participants beyond which no join notification will be emitted.
108115
*/

react/features/visitors/actions.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ export function admitMultiple(requests: Array<IPromotionRequest>): Function {
3636
* @param {IPromotionRequest} request - The request from the visitor.
3737
* @returns {Function}
3838
*/
39-
export function approveRequest(request: IPromotionRequest): Function {
39+
export function approveRequest(request: IPromotionRequest) {
4040
return (dispatch: IStore['dispatch'], getState: IStore['getState']) => {
4141
const conference = getCurrentConference(getState);
4242

@@ -57,7 +57,7 @@ export function approveRequest(request: IPromotionRequest): Function {
5757
* @param {IPromotionRequest} request - The request from the visitor.
5858
* @returns {Function}
5959
*/
60-
export function denyRequest(request: IPromotionRequest): Function {
60+
export function denyRequest(request: IPromotionRequest) {
6161
return (dispatch: IStore['dispatch'], getState: IStore['getState']) => {
6262
const conference = getCurrentConference(getState);
6363

react/features/visitors/middleware.ts

+87-3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,27 @@
1+
import i18n from 'i18next';
2+
import { batch } from 'react-redux';
3+
4+
import { IStore } from '../app/types';
15
import { CONFERENCE_JOINED, CONFERENCE_JOIN_IN_PROGRESS } from '../base/conference/actionTypes';
26
import { JitsiConferenceEvents } from '../base/lib-jitsi-meet';
37
import { raiseHand } from '../base/participants/actions';
48
import MiddlewareRegistry from '../base/redux/MiddlewareRegistry';
5-
import { showNotification } from '../notifications/actions';
6-
import { NOTIFICATION_TIMEOUT_TYPE } from '../notifications/constants';
9+
import { BUTTON_TYPES } from '../base/ui/constants.any';
10+
import { hideNotification, showNotification } from '../notifications/actions';
11+
import {
12+
NOTIFICATION_ICON,
13+
NOTIFICATION_TIMEOUT_TYPE,
14+
VISITORS_PROMOTION_NOTIFICATION_ID
15+
} from '../notifications/constants';
16+
import { open as openParticipantsPane } from '../participants-pane/actions';
717

8-
import { clearPromotionRequest, promotionRequestReceived, updateVisitorsCount } from './actions';
18+
import {
19+
approveRequest,
20+
clearPromotionRequest,
21+
denyRequest,
22+
promotionRequestReceived,
23+
updateVisitorsCount
24+
} from './actions';
925
import { getPromotionRequests } from './functions';
1026

1127
MiddlewareRegistry.register(({ dispatch, getState }) => next => action => {
@@ -44,6 +60,10 @@ MiddlewareRegistry.register(({ dispatch, getState }) => next => action => {
4460
} else {
4561
dispatch(clearPromotionRequest(request));
4662
}
63+
_handlePromotionNotification({
64+
dispatch,
65+
getState
66+
});
4767
});
4868

4969
conference.on(JitsiConferenceEvents.VISITORS_REJECTION, () => {
@@ -66,3 +86,67 @@ MiddlewareRegistry.register(({ dispatch, getState }) => next => action => {
6686

6787
return next(action);
6888
});
89+
90+
/**
91+
* Function to handle the promotion notification.
92+
*
93+
* @param {Object} store - The Redux store.
94+
* @returns {void}
95+
*/
96+
function _handlePromotionNotification(
97+
{ dispatch, getState }: { dispatch: IStore['dispatch']; getState: IStore['getState']; }) {
98+
const requests = getPromotionRequests(getState());
99+
100+
if (requests.length === 0) {
101+
dispatch(hideNotification(VISITORS_PROMOTION_NOTIFICATION_ID));
102+
103+
return;
104+
}
105+
106+
let notificationTitle;
107+
let customActionNameKey;
108+
let customActionHandler;
109+
let customActionType;
110+
let descriptionKey;
111+
let icon;
112+
113+
if (requests.length === 1) {
114+
const firstRequest = requests[0];
115+
116+
descriptionKey = 'notify.participantWantsToJoin';
117+
notificationTitle = firstRequest.nick;
118+
icon = NOTIFICATION_ICON.PARTICIPANT;
119+
customActionNameKey = [ 'participantsPane.actions.admit', 'participantsPane.actions.reject' ];
120+
customActionType = [ BUTTON_TYPES.PRIMARY, BUTTON_TYPES.DESTRUCTIVE ];
121+
customActionHandler = [ () => batch(() => {
122+
dispatch(hideNotification(VISITORS_PROMOTION_NOTIFICATION_ID));
123+
dispatch(approveRequest(firstRequest));
124+
}),
125+
() => batch(() => {
126+
dispatch(hideNotification(VISITORS_PROMOTION_NOTIFICATION_ID));
127+
dispatch(denyRequest(firstRequest));
128+
}) ];
129+
} else {
130+
descriptionKey = 'notify.participantsWantToJoin';
131+
notificationTitle = i18n.t('notify.waitingParticipants', {
132+
waitingParticipants: requests.length
133+
});
134+
icon = NOTIFICATION_ICON.PARTICIPANTS;
135+
customActionNameKey = [ 'notify.viewLobby' ];
136+
customActionType = [ BUTTON_TYPES.PRIMARY ];
137+
customActionHandler = [ () => batch(() => {
138+
dispatch(hideNotification(VISITORS_PROMOTION_NOTIFICATION_ID));
139+
dispatch(openParticipantsPane());
140+
}) ];
141+
}
142+
143+
dispatch(showNotification({
144+
title: notificationTitle,
145+
descriptionKey,
146+
uid: VISITORS_PROMOTION_NOTIFICATION_ID,
147+
customActionNameKey,
148+
customActionType,
149+
customActionHandler,
150+
icon
151+
}, NOTIFICATION_TIMEOUT_TYPE.STICKY));
152+
}

0 commit comments

Comments
 (0)