Procházet zdrojové kódy

fix: Adds display name to notifications about lobby operations.

Display name for lobby operations notifications are taken from the list of knocking participants which is available only to moderators. In case of not all moderators the notifications were broken.
j8
damencho před 4 roky
rodič
revize
ddc2b4f26e

+ 0
- 29
react/features/lobby/functions.js Zobrazit soubor

1
 // @flow
1
 // @flow
2
 
2
 
3
 import { getCurrentConference } from '../base/conference';
3
 import { getCurrentConference } from '../base/conference';
4
-import { toState } from '../base/redux';
5
-
6
-const JID_PATTERN = '[^@]+@[^/]+/(.+)';
7
-
8
-/**
9
- * Returns a knocking participant by ID or JID.
10
- *
11
- * @param {Function | Object} stateful - The Redux state or a function that resolves to the Redux state.
12
- * @param {string} id - The ID or JID of the participant.
13
- * @returns {Object}
14
- */
15
-export function getKnockingParticipantById(stateful: Function | Object, id: string): Object {
16
-    const { knockingParticipants } = toState(stateful)['features/lobby'];
17
-    const idToFind = getIdFromJid(id) || id;
18
-
19
-    return knockingParticipants.find(p => p.id === idToFind);
20
-}
21
 
4
 
22
 /**
5
 /**
23
  * Approves (lets in) or rejects a knocking participant.
6
  * Approves (lets in) or rejects a knocking participant.
38
         }
21
         }
39
     }
22
     }
40
 }
23
 }
41
-
42
-/**
43
- * Parses an ID from a JID, if a JID is provided, undefined otherwise.
44
- *
45
- * @param {string} jid - The JID to get the ID from.
46
- * @returns {?string}
47
- */
48
-function getIdFromJid(jid: string): ?string {
49
-    const match = new RegExp(JID_PATTERN, 'g').exec(jid) || [];
50
-
51
-    return match[1];
52
-}

+ 2
- 6
react/features/lobby/middleware.js Zobrazit soubor

17
     startKnocking,
17
     startKnocking,
18
     setPasswordJoinFailed
18
     setPasswordJoinFailed
19
 } from './actions';
19
 } from './actions';
20
-import { getKnockingParticipantById } from './functions';
21
 
20
 
22
 MiddlewareRegistry.register(store => next => action => {
21
 MiddlewareRegistry.register(store => next => action => {
23
     switch (action.type) {
22
     switch (action.type) {
176
 
175
 
177
     const notificationProps: any = {
176
     const notificationProps: any = {
178
         descriptionArguments: {
177
         descriptionArguments: {
179
-            originParticipantName: getParticipantDisplayName(getState, origin._id)
178
+            originParticipantName: getParticipantDisplayName(getState, origin._id),
179
+            targetParticipantName: message.name
180
         },
180
         },
181
         titleKey: 'lobby.notificationTitle'
181
         titleKey: 'lobby.notificationTitle'
182
     };
182
     };
187
         break;
187
         break;
188
     case 'LOBBY-ACCESS-GRANTED':
188
     case 'LOBBY-ACCESS-GRANTED':
189
         notificationProps.descriptionKey = 'lobby.notificationLobbyAccessGranted';
189
         notificationProps.descriptionKey = 'lobby.notificationLobbyAccessGranted';
190
-        notificationProps.descriptionArguments.targetParticipantName
191
-            = getKnockingParticipantById(getState, message.value)?.name;
192
         break;
190
         break;
193
     case 'LOBBY-ACCESS-DENIED':
191
     case 'LOBBY-ACCESS-DENIED':
194
         notificationProps.descriptionKey = 'lobby.notificationLobbyAccessDenied';
192
         notificationProps.descriptionKey = 'lobby.notificationLobbyAccessDenied';
195
-        notificationProps.descriptionArguments.targetParticipantName
196
-            = getKnockingParticipantById(getState, message.value)?.name;
197
         break;
193
         break;
198
     }
194
     }
199
 
195
 

+ 11
- 5
resources/prosody-plugins/mod_muc_lobby_rooms.lua Zobrazit soubor

101
 
101
 
102
 -- Sends a json message notifying that the jid was granted/denied access in lobby
102
 -- Sends a json message notifying that the jid was granted/denied access in lobby
103
 -- the message from is the actor that did the operation
103
 -- the message from is the actor that did the operation
104
-function notify_lobby_access(room, actor, jid, granted)
104
+function notify_lobby_access(room, actor, jid, display_name, granted)
105
     local notify_json = {
105
     local notify_json = {
106
-        value = jid
106
+        value = jid,
107
+        name = display_name
107
     };
108
     };
108
     if granted then
109
     if granted then
109
         notify_json.event = NOTIFY_LOBBY_ACCESS_GRANTED;
110
         notify_json.event = NOTIFY_LOBBY_ACCESS_GRANTED;
234
     host_module:hook('muc-broadcast-presence', function (event)
235
     host_module:hook('muc-broadcast-presence', function (event)
235
         local actor, occupant, room, x = event.actor, event.occupant, event.room, event.x;
236
         local actor, occupant, room, x = event.actor, event.occupant, event.room, event.x;
236
         if check_status(x, '307') then
237
         if check_status(x, '307') then
238
+            local display_name = occupant:get_presence():get_child_text(
239
+                'nick', 'http://jabber.org/protocol/nick');
237
             -- we need to notify in the main room
240
             -- we need to notify in the main room
238
-            notify_lobby_access(room.main_room, actor, occupant.nick, false);
241
+            notify_lobby_access(room.main_room, actor, occupant.nick, display_name, false);
239
         end
242
         end
240
     end);
243
     end);
241
 end
244
 end
362
         if room._data.lobbyroom then
365
         if room._data.lobbyroom then
363
             local occupant = room._data.lobbyroom:get_occupant_by_real_jid(invitee);
366
             local occupant = room._data.lobbyroom:get_occupant_by_real_jid(invitee);
364
             if occupant then
367
             if occupant then
365
-                notify_lobby_access(room, from, occupant.nick, true);
368
+                local display_name = occupant:get_presence():get_child_text(
369
+                    'nick', 'http://jabber.org/protocol/nick');
370
+
371
+                notify_lobby_access(room, from, occupant.nick, display_name, true);
366
             end
372
             end
367
         end
373
         end
368
     end);
374
     end);
396
 module:hook_global('bosh-session', update_session);
402
 module:hook_global('bosh-session', update_session);
397
 module:hook_global('websocket-session', update_session);
403
 module:hook_global('websocket-session', update_session);
398
 module:hook_global('config-reloaded', load_config);
404
 module:hook_global('config-reloaded', load_config);
399
-module:hook_global('create-lobby-room', handle_create_lobby);
405
+module:hook_global('create-lobby-room', handle_create_lobby);

Načítá se…
Zrušit
Uložit