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.
This commit is contained in:
parent
b106e51a10
commit
ddc2b4f26e
|
@ -1,23 +1,6 @@
|
|||
// @flow
|
||||
|
||||
import { getCurrentConference } from '../base/conference';
|
||||
import { toState } from '../base/redux';
|
||||
|
||||
const JID_PATTERN = '[^@]+@[^/]+/(.+)';
|
||||
|
||||
/**
|
||||
* Returns a knocking participant by ID or JID.
|
||||
*
|
||||
* @param {Function | Object} stateful - The Redux state or a function that resolves to the Redux state.
|
||||
* @param {string} id - The ID or JID of the participant.
|
||||
* @returns {Object}
|
||||
*/
|
||||
export function getKnockingParticipantById(stateful: Function | Object, id: string): Object {
|
||||
const { knockingParticipants } = toState(stateful)['features/lobby'];
|
||||
const idToFind = getIdFromJid(id) || id;
|
||||
|
||||
return knockingParticipants.find(p => p.id === idToFind);
|
||||
}
|
||||
|
||||
/**
|
||||
* Approves (lets in) or rejects a knocking participant.
|
||||
|
@ -38,15 +21,3 @@ export function setKnockingParticipantApproval(getState: Function, id: string, a
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses an ID from a JID, if a JID is provided, undefined otherwise.
|
||||
*
|
||||
* @param {string} jid - The JID to get the ID from.
|
||||
* @returns {?string}
|
||||
*/
|
||||
function getIdFromJid(jid: string): ?string {
|
||||
const match = new RegExp(JID_PATTERN, 'g').exec(jid) || [];
|
||||
|
||||
return match[1];
|
||||
}
|
||||
|
|
|
@ -17,7 +17,6 @@ import {
|
|||
startKnocking,
|
||||
setPasswordJoinFailed
|
||||
} from './actions';
|
||||
import { getKnockingParticipantById } from './functions';
|
||||
|
||||
MiddlewareRegistry.register(store => next => action => {
|
||||
switch (action.type) {
|
||||
|
@ -176,7 +175,8 @@ function _maybeSendLobbyNotification(origin, message, { dispatch, getState }) {
|
|||
|
||||
const notificationProps: any = {
|
||||
descriptionArguments: {
|
||||
originParticipantName: getParticipantDisplayName(getState, origin._id)
|
||||
originParticipantName: getParticipantDisplayName(getState, origin._id),
|
||||
targetParticipantName: message.name
|
||||
},
|
||||
titleKey: 'lobby.notificationTitle'
|
||||
};
|
||||
|
@ -187,13 +187,9 @@ function _maybeSendLobbyNotification(origin, message, { dispatch, getState }) {
|
|||
break;
|
||||
case 'LOBBY-ACCESS-GRANTED':
|
||||
notificationProps.descriptionKey = 'lobby.notificationLobbyAccessGranted';
|
||||
notificationProps.descriptionArguments.targetParticipantName
|
||||
= getKnockingParticipantById(getState, message.value)?.name;
|
||||
break;
|
||||
case 'LOBBY-ACCESS-DENIED':
|
||||
notificationProps.descriptionKey = 'lobby.notificationLobbyAccessDenied';
|
||||
notificationProps.descriptionArguments.targetParticipantName
|
||||
= getKnockingParticipantById(getState, message.value)?.name;
|
||||
break;
|
||||
}
|
||||
|
||||
|
|
|
@ -101,9 +101,10 @@ end
|
|||
|
||||
-- Sends a json message notifying that the jid was granted/denied access in lobby
|
||||
-- the message from is the actor that did the operation
|
||||
function notify_lobby_access(room, actor, jid, granted)
|
||||
function notify_lobby_access(room, actor, jid, display_name, granted)
|
||||
local notify_json = {
|
||||
value = jid
|
||||
value = jid,
|
||||
name = display_name
|
||||
};
|
||||
if granted then
|
||||
notify_json.event = NOTIFY_LOBBY_ACCESS_GRANTED;
|
||||
|
@ -234,8 +235,10 @@ function process_lobby_muc_loaded(lobby_muc, host_module)
|
|||
host_module:hook('muc-broadcast-presence', function (event)
|
||||
local actor, occupant, room, x = event.actor, event.occupant, event.room, event.x;
|
||||
if check_status(x, '307') then
|
||||
local display_name = occupant:get_presence():get_child_text(
|
||||
'nick', 'http://jabber.org/protocol/nick');
|
||||
-- we need to notify in the main room
|
||||
notify_lobby_access(room.main_room, actor, occupant.nick, false);
|
||||
notify_lobby_access(room.main_room, actor, occupant.nick, display_name, false);
|
||||
end
|
||||
end);
|
||||
end
|
||||
|
@ -362,7 +365,10 @@ process_host_module(main_muc_component_config, function(host_module, host)
|
|||
if room._data.lobbyroom then
|
||||
local occupant = room._data.lobbyroom:get_occupant_by_real_jid(invitee);
|
||||
if occupant then
|
||||
notify_lobby_access(room, from, occupant.nick, true);
|
||||
local display_name = occupant:get_presence():get_child_text(
|
||||
'nick', 'http://jabber.org/protocol/nick');
|
||||
|
||||
notify_lobby_access(room, from, occupant.nick, display_name, true);
|
||||
end
|
||||
end
|
||||
end);
|
||||
|
@ -396,4 +402,4 @@ end
|
|||
module:hook_global('bosh-session', update_session);
|
||||
module:hook_global('websocket-session', update_session);
|
||||
module:hook_global('config-reloaded', load_config);
|
||||
module:hook_global('create-lobby-room', handle_create_lobby);
|
||||
module:hook_global('create-lobby-room', handle_create_lobby);
|
||||
|
|
Loading…
Reference in New Issue