Pārlūkot izejas kodu

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 4 gadus atpakaļ
vecāks
revīzija
ddc2b4f26e

+ 0
- 29
react/features/lobby/functions.js Parādīt failu

@@ -1,23 +1,6 @@
1 1
 // @flow
2 2
 
3 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 6
  * Approves (lets in) or rejects a knocking participant.
@@ -38,15 +21,3 @@ export function setKnockingParticipantApproval(getState: Function, id: string, a
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 Parādīt failu

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

+ 11
- 5
resources/prosody-plugins/mod_muc_lobby_rooms.lua Parādīt failu

@@ -101,9 +101,10 @@ end
101 101
 
102 102
 -- Sends a json message notifying that the jid was granted/denied access in lobby
103 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 105
     local notify_json = {
106
-        value = jid
106
+        value = jid,
107
+        name = display_name
107 108
     };
108 109
     if granted then
109 110
         notify_json.event = NOTIFY_LOBBY_ACCESS_GRANTED;
@@ -234,8 +235,10 @@ function process_lobby_muc_loaded(lobby_muc, host_module)
234 235
     host_module:hook('muc-broadcast-presence', function (event)
235 236
         local actor, occupant, room, x = event.actor, event.occupant, event.room, event.x;
236 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 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 242
         end
240 243
     end);
241 244
 end
@@ -362,7 +365,10 @@ process_host_module(main_muc_component_config, function(host_module, host)
362 365
         if room._data.lobbyroom then
363 366
             local occupant = room._data.lobbyroom:get_occupant_by_real_jid(invitee);
364 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 372
             end
367 373
         end
368 374
     end);
@@ -396,4 +402,4 @@ end
396 402
 module:hook_global('bosh-session', update_session);
397 403
 module:hook_global('websocket-session', update_session);
398 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);

Notiek ielāde…
Atcelt
Saglabāt