2020-04-15 13:13:43 +00:00
|
|
|
// @flow
|
|
|
|
|
2020-05-20 08:25:31 +00:00
|
|
|
import { getCurrentConference } from '../base/conference';
|
2020-07-06 14:54:33 +00:00
|
|
|
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);
|
|
|
|
}
|
2020-04-15 13:13:43 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Approves (lets in) or rejects a knocking participant.
|
|
|
|
*
|
|
|
|
* @param {Function} getState - Function to get the Redux state.
|
|
|
|
* @param {string} id - The id of the knocking participant.
|
|
|
|
* @param {boolean} approved - True if the participant is approved, false otherwise.
|
|
|
|
* @returns {Function}
|
|
|
|
*/
|
|
|
|
export function setKnockingParticipantApproval(getState: Function, id: string, approved: boolean) {
|
2020-05-20 08:25:31 +00:00
|
|
|
const conference = getCurrentConference(getState());
|
2020-04-15 13:13:43 +00:00
|
|
|
|
|
|
|
if (conference) {
|
|
|
|
if (approved) {
|
|
|
|
conference.lobbyApproveAccess(id);
|
|
|
|
} else {
|
|
|
|
conference.lobbyDenyAccess(id);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-07-06 14:54:33 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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];
|
|
|
|
}
|