1
+ import i18n from 'i18next' ;
2
+ import { batch } from 'react-redux' ;
3
+
4
+ import { IStore } from '../app/types' ;
1
5
import { CONFERENCE_JOINED , CONFERENCE_JOIN_IN_PROGRESS } from '../base/conference/actionTypes' ;
2
6
import { JitsiConferenceEvents } from '../base/lib-jitsi-meet' ;
3
7
import { raiseHand } from '../base/participants/actions' ;
4
8
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' ;
7
17
8
- import { clearPromotionRequest , promotionRequestReceived , updateVisitorsCount } from './actions' ;
18
+ import {
19
+ approveRequest ,
20
+ clearPromotionRequest ,
21
+ denyRequest ,
22
+ promotionRequestReceived ,
23
+ updateVisitorsCount
24
+ } from './actions' ;
9
25
import { getPromotionRequests } from './functions' ;
10
26
11
27
MiddlewareRegistry . register ( ( { dispatch, getState } ) => next => action => {
@@ -44,6 +60,10 @@ MiddlewareRegistry.register(({ dispatch, getState }) => next => action => {
44
60
} else {
45
61
dispatch ( clearPromotionRequest ( request ) ) ;
46
62
}
63
+ _handlePromotionNotification ( {
64
+ dispatch,
65
+ getState
66
+ } ) ;
47
67
} ) ;
48
68
49
69
conference . on ( JitsiConferenceEvents . VISITORS_REJECTION , ( ) => {
@@ -66,3 +86,67 @@ MiddlewareRegistry.register(({ dispatch, getState }) => next => action => {
66
86
67
87
return next ( action ) ;
68
88
} ) ;
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