From 8f0f162d2c35f7fdeb8329b7e1f67dddf2bf802d Mon Sep 17 00:00:00 2001 From: gabriellsh Date: Mon, 1 Jul 2024 16:57:12 -0300 Subject: [PATCH 1/7] implement bridge method --- apps/meteor/app/apps/server/bridges/rooms.ts | 23 ++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/apps/meteor/app/apps/server/bridges/rooms.ts b/apps/meteor/app/apps/server/bridges/rooms.ts index 1584d0788629..4b1d217ba918 100644 --- a/apps/meteor/app/apps/server/bridges/rooms.ts +++ b/apps/meteor/app/apps/server/bridges/rooms.ts @@ -11,6 +11,7 @@ import { createDirectMessage } from '../../../../server/methods/createDirectMess import { createDiscussion } from '../../../discussion/server/methods/createDiscussion'; import { addUserToRoom } from '../../../lib/server/functions/addUserToRoom'; import { deleteRoom } from '../../../lib/server/functions/deleteRoom'; +import { removeUserFromRoom } from '../../../lib/server/functions/removeUserFromRoom'; import { createChannelMethod } from '../../../lib/server/methods/createChannel'; import { createPrivateGroupMethod } from '../../../lib/server/methods/createPrivateGroup'; @@ -210,6 +211,28 @@ export class AppRoomBridge extends RoomBridge { return users.map((user: ICoreUser) => userConverter.convertToApp(user)); } + protected async removeUsers(roomId: string, usernames: Array, appId: string): Promise { + this.orch.debugLog(`The App ${appId} is removing users ${usernames} from room id: ${roomId}`); + if (!roomId) { + throw new Error('roomId was not provided.'); + } + + const room = await Rooms.findOneById(roomId); + if (!roomId || !room) { + throw new Error('A room must exist to update.'); + } + + for await (const username of usernames) { + const member = await Users.findOneByUsername(username, {}); + + if (!member) { + continue; + } + + await removeUserFromRoom(room._id, member); + } + } + protected getMessages( _roomId: string, _options: { limit: number; skip?: number; sort?: Record }, From 458f198a51a6fe7cb8e5d3435b4d9afa4fb03e85 Mon Sep 17 00:00:00 2001 From: gabriellsh <40830821+gabriellsh@users.noreply.github.com> Date: Mon, 1 Jul 2024 18:19:50 -0300 Subject: [PATCH 2/7] add cs --- .changeset/hip-queens-taste.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/hip-queens-taste.md diff --git a/.changeset/hip-queens-taste.md b/.changeset/hip-queens-taste.md new file mode 100644 index 000000000000..510d94209560 --- /dev/null +++ b/.changeset/hip-queens-taste.md @@ -0,0 +1,5 @@ +--- +"@rocket.chat/meteor": patch +--- + +Added the possibility for apps to remove users from a room From 46cbc415dd0ec1fefe904a80f3783d32d886b266 Mon Sep 17 00:00:00 2001 From: Douglas Gubert Date: Wed, 3 Jul 2024 17:46:24 -0300 Subject: [PATCH 3/7] Update .changeset/hip-queens-taste.md --- .changeset/hip-queens-taste.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.changeset/hip-queens-taste.md b/.changeset/hip-queens-taste.md index 510d94209560..f1d7bb6f3f0e 100644 --- a/.changeset/hip-queens-taste.md +++ b/.changeset/hip-queens-taste.md @@ -1,5 +1,5 @@ --- -"@rocket.chat/meteor": patch +"@rocket.chat/meteor": minor --- Added the possibility for apps to remove users from a room From 2eaf1fa95cb614ce05a3c74710de4b7740fda4aa Mon Sep 17 00:00:00 2001 From: gabriellsh Date: Thu, 4 Jul 2024 19:05:28 -0300 Subject: [PATCH 4/7] Fix removeUsers --- apps/meteor/app/apps/server/bridges/rooms.ts | 17 +++-------------- 1 file changed, 3 insertions(+), 14 deletions(-) diff --git a/apps/meteor/app/apps/server/bridges/rooms.ts b/apps/meteor/app/apps/server/bridges/rooms.ts index 4b1d217ba918..db75f46abfa3 100644 --- a/apps/meteor/app/apps/server/bridges/rooms.ts +++ b/apps/meteor/app/apps/server/bridges/rooms.ts @@ -217,20 +217,9 @@ export class AppRoomBridge extends RoomBridge { throw new Error('roomId was not provided.'); } - const room = await Rooms.findOneById(roomId); - if (!roomId || !room) { - throw new Error('A room must exist to update.'); - } - - for await (const username of usernames) { - const member = await Users.findOneByUsername(username, {}); - - if (!member) { - continue; - } - - await removeUserFromRoom(room._id, member); - } + // not sure what the limit should be here, but we have to limit it + const members = await Users.findUsersByUsernames(usernames, { limit: 50 }).toArray(); + await Promise.all(members.map((user) => removeUserFromRoom(roomId, user))); } protected getMessages( From 4b103a86751d9b9f702ad903a4aaf80f46d48cf1 Mon Sep 17 00:00:00 2001 From: Douglas Gubert Date: Wed, 10 Jul 2024 19:35:27 -0300 Subject: [PATCH 5/7] Bump apps-engine version --- apps/meteor/app/apps/server/bridges/rooms.ts | 6 ++-- apps/meteor/package.json | 2 +- yarn.lock | 31 +++----------------- 3 files changed, 9 insertions(+), 30 deletions(-) diff --git a/apps/meteor/app/apps/server/bridges/rooms.ts b/apps/meteor/app/apps/server/bridges/rooms.ts index db75f46abfa3..dd9b8db5ce94 100644 --- a/apps/meteor/app/apps/server/bridges/rooms.ts +++ b/apps/meteor/app/apps/server/bridges/rooms.ts @@ -217,9 +217,11 @@ export class AppRoomBridge extends RoomBridge { throw new Error('roomId was not provided.'); } + await Users.findUsersByUsernames(usernames, { batchSize: 50 }).forEach((user) => (removeUserFromRoom(roomId, user), true)); + // not sure what the limit should be here, but we have to limit it - const members = await Users.findUsersByUsernames(usernames, { limit: 50 }).toArray(); - await Promise.all(members.map((user) => removeUserFromRoom(roomId, user))); + // const members = await Users.findUsersByUsernames(usernames, { limit: 50 }).toArray(); + // await Promise.all(members.map((user) => removeUserFromRoom(roomId, user))); } protected getMessages( diff --git a/apps/meteor/package.json b/apps/meteor/package.json index c78ce6e0a7ab..816379df08a9 100644 --- a/apps/meteor/package.json +++ b/apps/meteor/package.json @@ -231,7 +231,7 @@ "@rocket.chat/agenda": "workspace:^", "@rocket.chat/api-client": "workspace:^", "@rocket.chat/apps": "workspace:^", - "@rocket.chat/apps-engine": "^1.43.0-alpha.773", + "@rocket.chat/apps-engine": "alpha", "@rocket.chat/base64": "workspace:^", "@rocket.chat/cas-validate": "workspace:^", "@rocket.chat/core-services": "workspace:^", diff --git a/yarn.lock b/yarn.lock index 5d7943ccd130..8faee615c91e 100644 --- a/yarn.lock +++ b/yarn.lock @@ -8508,32 +8508,9 @@ __metadata: languageName: unknown linkType: soft -"@rocket.chat/apps-engine@npm:^1.43.0-alpha.773": - version: 1.43.0-deno.761 - resolution: "@rocket.chat/apps-engine@npm:1.43.0-deno.761" - dependencies: - "@msgpack/msgpack": 3.0.0-beta2 - adm-zip: ^0.5.9 - cryptiles: ^4.1.3 - debug: ^4.3.4 - deno-bin: 1.37.1 - esbuild: ^0.20.2 - jose: ^4.11.1 - jsonrpc-lite: ^2.2.0 - lodash.clonedeep: ^4.5.0 - semver: ^5.7.1 - stack-trace: 0.0.10 - uuid: ~8.3.2 - vm2: ^3.9.19 - peerDependencies: - "@rocket.chat/ui-kit": "*" - checksum: cbcc1cd818504a0d5a300635192053592d54234d640696d14e40f67acf1129bca8a952d34365e08e888bd22ef4ebcae0f9f45888f9b724a627a3b7e48380ab3d - languageName: node - linkType: hard - "@rocket.chat/apps-engine@npm:alpha": - version: 1.43.0-alpha.765 - resolution: "@rocket.chat/apps-engine@npm:1.43.0-alpha.765" + version: 1.44.0-alpha.814 + resolution: "@rocket.chat/apps-engine@npm:1.44.0-alpha.814" dependencies: "@msgpack/msgpack": 3.0.0-beta2 adm-zip: ^0.5.9 @@ -8549,7 +8526,7 @@ __metadata: uuid: ~8.3.2 peerDependencies: "@rocket.chat/ui-kit": "*" - checksum: 97fb5773c8d99e63e8c1d6f6002956d35b031cbe60d640d637b28a65ebbc37b89366e91f5c8bda254f634987a66fef37b70716c20d9a75bae86171447d477bb6 + checksum: 03f777ecd035af20c88558a941db77bb104f4402f78169a6d23e1629613c11ac23c04f6bdfb451a4273558789de58d4567661a7bd5de91b78464f98698e5f6a6 languageName: node linkType: hard @@ -9379,7 +9356,7 @@ __metadata: "@rocket.chat/agenda": "workspace:^" "@rocket.chat/api-client": "workspace:^" "@rocket.chat/apps": "workspace:^" - "@rocket.chat/apps-engine": ^1.43.0-alpha.773 + "@rocket.chat/apps-engine": alpha "@rocket.chat/base64": "workspace:^" "@rocket.chat/cas-validate": "workspace:^" "@rocket.chat/core-services": "workspace:^" From 71c7656c52b63d912759fce231145fbc495864a0 Mon Sep 17 00:00:00 2001 From: Douglas Gubert Date: Wed, 10 Jul 2024 19:42:03 -0300 Subject: [PATCH 6/7] Revert unintentional changes --- apps/meteor/app/apps/server/bridges/rooms.ts | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/apps/meteor/app/apps/server/bridges/rooms.ts b/apps/meteor/app/apps/server/bridges/rooms.ts index dd9b8db5ce94..86817c5721e2 100644 --- a/apps/meteor/app/apps/server/bridges/rooms.ts +++ b/apps/meteor/app/apps/server/bridges/rooms.ts @@ -217,11 +217,8 @@ export class AppRoomBridge extends RoomBridge { throw new Error('roomId was not provided.'); } - await Users.findUsersByUsernames(usernames, { batchSize: 50 }).forEach((user) => (removeUserFromRoom(roomId, user), true)); - - // not sure what the limit should be here, but we have to limit it - // const members = await Users.findUsersByUsernames(usernames, { limit: 50 }).toArray(); - // await Promise.all(members.map((user) => removeUserFromRoom(roomId, user))); + const members = await Users.findUsersByUsernames(usernames, { limit: 50 }).toArray(); + await Promise.all(members.map((user) => removeUserFromRoom(roomId, user))); } protected getMessages( From 05b11596e9f9079ea114684388f82d9f825cd81b Mon Sep 17 00:00:00 2001 From: gabriellsh Date: Fri, 12 Jul 2024 14:26:44 -0300 Subject: [PATCH 7/7] Remove duplicated method --- apps/meteor/app/apps/server/bridges/rooms.ts | 4 ---- 1 file changed, 4 deletions(-) diff --git a/apps/meteor/app/apps/server/bridges/rooms.ts b/apps/meteor/app/apps/server/bridges/rooms.ts index 9b1c1089569a..86817c5721e2 100644 --- a/apps/meteor/app/apps/server/bridges/rooms.ts +++ b/apps/meteor/app/apps/server/bridges/rooms.ts @@ -228,8 +228,4 @@ export class AppRoomBridge extends RoomBridge { ): Promise { throw new Error('Method not implemented.'); } - - protected removeUsers(_roomId: string, _usernames: Array, _appId: string): Promise { - throw new Error('Method not implemented.'); - } }