Skip to content

Commit

Permalink
Replicate event in meteor method and add removedBy
Browse files Browse the repository at this point in the history
  • Loading branch information
gabriellsh committed Jul 4, 2024
1 parent 06707d8 commit d2730f3
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
3 changes: 2 additions & 1 deletion apps/meteor/app/apps/server/bridges/listeners.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,10 +143,11 @@ export class AppListenerBridge {
};
case AppInterface.IPreRoomUserLeave:
case AppInterface.IPostRoomUserLeave:
const [leavingUser] = payload;
const [leavingUser, removedBy] = payload;
return {
room: rm,
leavingUser: this.orch.getConverters().get('users').convertToApp(leavingUser),
removedBy: this.orch.getConverters().get('users').convertToApp(removedBy),
};
default:
return rm;
Expand Down
4 changes: 2 additions & 2 deletions apps/meteor/app/lib/server/functions/removeUserFromRoom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export const removeUserFromRoom = async function (
}

try {
await Apps.self?.triggerEvent(AppEvents.IPreRoomUserLeave, room, user);
await Apps.self?.triggerEvent(AppEvents.IPreRoomUserLeave, room, user, options?.byUser);
} catch (error: any) {
if (error.name === AppsEngineException.name) {
throw new Meteor.Error('error-app-prevented', error.message);
Expand Down Expand Up @@ -75,5 +75,5 @@ export const removeUserFromRoom = async function (

void notifyOnRoomChangedById(rid);

await Apps.self?.triggerEvent(AppEvents.IPostRoomUserLeave, room, user);
await Apps.self?.triggerEvent(AppEvents.IPostRoomUserLeave, room, user, options?.byUser);
};
14 changes: 14 additions & 0 deletions apps/meteor/server/methods/removeUserFromRoom.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { Apps, AppEvents } from '@rocket.chat/apps';
import { AppsEngineException } from '@rocket.chat/apps-engine/definition/exceptions';
import { Message, Team } from '@rocket.chat/core-services';
import { Subscriptions, Rooms, Users } from '@rocket.chat/models';
import type { ServerMethods } from '@rocket.chat/ui-contexts';
Expand Down Expand Up @@ -75,6 +77,16 @@ export const removeUserFromRoomMethod = async (fromId: string, data: { rid: stri
}
}

try {
await Apps.self?.triggerEvent(AppEvents.IPreRoomUserLeave, room, removedUser, fromUser);
} catch (error: any) {
if (error.name === AppsEngineException.name) {
throw new Meteor.Error('error-app-prevented', error.message);
}

throw error;
}

await callbacks.run('beforeRemoveFromRoom', { removedUser, userWhoRemoved: fromUser }, room);

await Subscriptions.removeByRoomIdAndUserId(data.rid, removedUser._id);
Expand All @@ -99,6 +111,8 @@ export const removeUserFromRoomMethod = async (fromId: string, data: { rid: stri
void notifyOnRoomChanged(room);
});

await Apps.self?.triggerEvent(AppEvents.IPostRoomUserLeave, room, removedUser, fromUser);

return true;
};

Expand Down

0 comments on commit d2730f3

Please sign in to comment.