Skip to content

Commit

Permalink
feat(prosody): extend jigasi kick endpoint to work for any participant (
Browse files Browse the repository at this point in the history
#15387)

* feat(prosody): extend jigasi kick endpoint to work for any participant

* apply review

* squash: Fix UI when there is no actor of the kick.

---------

Co-authored-by: damencho <[email protected]>
  • Loading branch information
roanta2 and damencho authored Dec 12, 2024
1 parent 3d56538 commit 01a731a
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 13 deletions.
1 change: 1 addition & 0 deletions lang/main.json
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,7 @@
"kickParticipantButton": "Kick",
"kickParticipantDialog": "Are you sure you want to kick this participant?",
"kickParticipantTitle": "Kick this participant?",
"kickSystemTitle": "Ouch! You were kicked out of the meeting",
"kickTitle": "Ouch! {{participantDisplayName}} kicked you out of the meeting",
"linkMeeting": "Link meeting",
"linkMeetingTitle": "Link meeting to Salesforce",
Expand Down
6 changes: 3 additions & 3 deletions react/features/conference/actions.native.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,17 @@ import { DISMISS_CALENDAR_NOTIFICATION } from './actionTypes';
*/
export function notifyKickedOut(participant: any, submit?: Function) {
return (dispatch: IStore['dispatch'], getState: IStore['getState']) => {
if (!participant || participant?.isReplaced?.()) {
if (participant?.isReplaced?.()) {
submit?.();

return;
}

dispatch(openDialog(AlertDialog, {
contentKey: {
key: 'dialog.kickTitle',
key: participant ? 'dialog.kickTitle' : 'dialog.kickSystemTitle',
params: {
participantDisplayName: getParticipantDisplayName(getState, participant.getId())
participantDisplayName: participant && getParticipantDisplayName(getState, participant.getId())
}
},
onSubmit: submit
Expand Down
11 changes: 8 additions & 3 deletions react/features/conference/middleware.web.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,17 @@ MiddlewareRegistry.register(store => next => action => {
const { dispatch } = store;
const { participant } = action;

// we need to first finish dispatching or the notification can be cleared out
const result = next(action);

const participantDisplayName
= getParticipantDisplayName(store.getState, participant.getId());
= participant && getParticipantDisplayName(store.getState, participant.getId());

dispatch(hangup(true, i18next.t('dialog.kickTitle', { participantDisplayName })));
dispatch(hangup(true,
participantDisplayName ? i18next.t('dialog.kickTitle', { participantDisplayName })
: i18next.t('dialog.kickSystemTitle')));

break;
return result;
}
}

Expand Down
4 changes: 2 additions & 2 deletions react/features/external-api/middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,8 @@ MiddlewareRegistry.register(store => next => action => {
local: true
},
{
id: actor.getId(),
name: actor.getDisplayName()
id: actor?.getId(),
name: actor?.getDisplayName()
}
);
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,10 @@ function handle_kick_participant (event)
end

local number = params["number"];
local participantId = params["participantId"];

if not number then
module:log("warn", "Missing number param");
if (not number and not participantId) or (number and participantId) then
module:log("warn", "Invalid parameters: exactly one of 'number' or 'participantId' must be provided.");
return { status_code = 400; };
end

Expand All @@ -134,10 +135,8 @@ function handle_kick_participant (event)

for _, occupant in room:each_occupant() do
local pr = occupant:get_presence();
local displayName = pr:get_child_text(
'nick', 'http://jabber.org/protocol/nick');

if is_sip_jigasi(pr) and displayName and starts_with(displayName, number) then
if is_participant_match(pr, number, participantId) then
room:set_role(true, occupant.nick, nil);
module:log('info', 'Occupant kicked %s from %s', occupant.nick, room.jid);
return { status_code = 200; }
Expand All @@ -148,6 +147,20 @@ function handle_kick_participant (event)
return { status_code = 404; };
end

function is_participant_match(pr, number, participantId)
if number then
local displayName = pr:get_child_text('nick', 'http://jabber.org/protocol/nick');
return is_sip_jigasi(pr) and displayName and starts_with(displayName, number);
elseif participantId then
local from = pr.attr.from;
local _, _, from_resource = jid.split(from);
if from_resource then
return from_resource == participantId;
end
end
return false;
end

module:log("info","Adding http handler for /kick-participant on %s", module.host);
module:depends("http");
module:provides("http", {
Expand Down

0 comments on commit 01a731a

Please sign in to comment.