Skip to content

Commit

Permalink
fix: Adds display name to notifications about lobby operations.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
damencho committed Jul 23, 2020
1 parent b106e51 commit ddc2b4f
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 40 deletions.
29 changes: 0 additions & 29 deletions react/features/lobby/functions.js
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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];
}
8 changes: 2 additions & 6 deletions react/features/lobby/middleware.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import {
startKnocking,
setPasswordJoinFailed
} from './actions';
import { getKnockingParticipantById } from './functions';

MiddlewareRegistry.register(store => next => action => {
switch (action.type) {
Expand Down Expand Up @@ -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'
};
Expand All @@ -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;
}

Expand Down
16 changes: 11 additions & 5 deletions resources/prosody-plugins/mod_muc_lobby_rooms.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);

0 comments on commit ddc2b4f

Please sign in to comment.