From d7134c54c5088175e4853fdcbfa433e523aced90 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=83=87=E3=83=B4=E3=81=81=E3=82=93=E3=81=99?= Date: Thu, 11 Apr 2024 14:07:40 +0530 Subject: [PATCH 01/23] implement the rooms bridge --- .changeset/polite-foxes-repair.md | 5 ++++ apps/meteor/app/apps/server/bridges/rooms.ts | 30 +++++++++++++++++++- 2 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 .changeset/polite-foxes-repair.md diff --git a/.changeset/polite-foxes-repair.md b/.changeset/polite-foxes-repair.md new file mode 100644 index 000000000000..12f4ce770804 --- /dev/null +++ b/.changeset/polite-foxes-repair.md @@ -0,0 +1,5 @@ +--- +'@rocket.chat/meteor': minor +--- + +Implement the `getMessages` method in the Apps Engine Room bridge, this method will allow Apps to fetch messages from a room. diff --git a/apps/meteor/app/apps/server/bridges/rooms.ts b/apps/meteor/app/apps/server/bridges/rooms.ts index bbd24152716f..a2aa1cdb57d6 100644 --- a/apps/meteor/app/apps/server/bridges/rooms.ts +++ b/apps/meteor/app/apps/server/bridges/rooms.ts @@ -5,7 +5,7 @@ import { RoomType } from '@rocket.chat/apps-engine/definition/rooms'; import type { IUser } from '@rocket.chat/apps-engine/definition/users'; import { RoomBridge } from '@rocket.chat/apps-engine/server/bridges/RoomBridge'; import type { ISubscription, IUser as ICoreUser, IRoom as ICoreRoom } from '@rocket.chat/core-typings'; -import { Subscriptions, Users, Rooms } from '@rocket.chat/models'; +import { Subscriptions, Users, Rooms, Messages } from '@rocket.chat/models'; import { createDirectMessage } from '../../../../server/methods/createDirectMessage'; import { createDiscussion } from '../../../discussion/server/methods/createDiscussion'; @@ -102,6 +102,34 @@ export class AppRoomBridge extends RoomBridge { return this.orch.getConverters()?.get('users').convertById(room.u._id); } + protected async getMessages( + roomId: string, + appId: string, + options: { + limit?: number; + skip?: number; + sort?: Record; + } = {}, + ): Promise { + this.orch.debugLog(`The App ${appId} is getting the messages of the room: "${roomId}"`); + const { limit = 100, skip, sort = { ts: -1 } } = options; + + const messageQueryOptions = { + limit: Math.min(limit, 100), + skip, + sort, + }; + + const messages = await Messages.findVisibleByRoomId(roomId, messageQueryOptions).toArray(); + + const messageConverter = this.orch.getConverters()?.get('messages'); + if (!messageConverter) { + throw new Error('Message converter not found'); + } + + return Promise.all(messages.map((message) => messageConverter.convertMessage(message))); + } + protected async getMembers(roomId: string, appId: string): Promise> { this.orch.debugLog(`The App ${appId} is getting the room's members by room id: "${roomId}"`); const subscriptions = await Subscriptions.findByRoomId(roomId, {}); From 2c6bd5bef1ccf7819a9636ee3c410b0de0390cb6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=83=87=E3=83=B4=E3=81=81=E3=82=93=E3=81=99?= Date: Tue, 16 Apr 2024 00:06:41 +0530 Subject: [PATCH 02/23] change param order --- apps/meteor/app/apps/server/bridges/rooms.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/apps/meteor/app/apps/server/bridges/rooms.ts b/apps/meteor/app/apps/server/bridges/rooms.ts index a2aa1cdb57d6..a383907f26fb 100644 --- a/apps/meteor/app/apps/server/bridges/rooms.ts +++ b/apps/meteor/app/apps/server/bridges/rooms.ts @@ -104,15 +104,15 @@ export class AppRoomBridge extends RoomBridge { protected async getMessages( roomId: string, - appId: string, options: { - limit?: number; + limit: number; skip?: number; sort?: Record; - } = {}, + }, + appId: string, ): Promise { this.orch.debugLog(`The App ${appId} is getting the messages of the room: "${roomId}"`); - const { limit = 100, skip, sort = { ts: -1 } } = options; + const { limit, skip, sort = { ts: -1 } } = options; const messageQueryOptions = { limit: Math.min(limit, 100), From f3bb1a5fadac366f63305399f77ba09f70364ccb Mon Sep 17 00:00:00 2001 From: Douglas Gubert Date: Mon, 15 Apr 2024 20:20:55 -0300 Subject: [PATCH 03/23] Update Apps-Engine --- apps/meteor/ee/server/services/package.json | 2 +- apps/meteor/package.json | 2 +- ee/apps/ddp-streamer/package.json | 2 +- ee/packages/presence/package.json | 2 +- packages/apps/package.json | 2 +- packages/core-services/package.json | 2 +- packages/core-typings/package.json | 2 +- packages/fuselage-ui-kit/package.json | 2 +- packages/rest-typings/package.json | 2 +- yarn.lock | 26 ++++++++++----------- 10 files changed, 22 insertions(+), 22 deletions(-) diff --git a/apps/meteor/ee/server/services/package.json b/apps/meteor/ee/server/services/package.json index 9489b8c38dc7..532b9c4e6ea4 100644 --- a/apps/meteor/ee/server/services/package.json +++ b/apps/meteor/ee/server/services/package.json @@ -18,7 +18,7 @@ "author": "Rocket.Chat", "license": "MIT", "dependencies": { - "@rocket.chat/apps-engine": "^1.42.1", + "@rocket.chat/apps-engine": "1.43.0-alpha.694", "@rocket.chat/core-services": "workspace:^", "@rocket.chat/core-typings": "workspace:^", "@rocket.chat/emitter": "~0.31.25", diff --git a/apps/meteor/package.json b/apps/meteor/package.json index 5240f55b08be..fcba51568516 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.42.1", + "@rocket.chat/apps-engine": "1.43.0-alpha.694", "@rocket.chat/base64": "workspace:^", "@rocket.chat/cas-validate": "workspace:^", "@rocket.chat/core-services": "workspace:^", diff --git a/ee/apps/ddp-streamer/package.json b/ee/apps/ddp-streamer/package.json index a8712fac594f..db245dd6c91c 100644 --- a/ee/apps/ddp-streamer/package.json +++ b/ee/apps/ddp-streamer/package.json @@ -15,7 +15,7 @@ ], "author": "Rocket.Chat", "dependencies": { - "@rocket.chat/apps-engine": "^1.42.1", + "@rocket.chat/apps-engine": "1.43.0-alpha.694", "@rocket.chat/core-services": "workspace:^", "@rocket.chat/core-typings": "workspace:^", "@rocket.chat/emitter": "~0.31.25", diff --git a/ee/packages/presence/package.json b/ee/packages/presence/package.json index 085beb967836..928f8caad963 100644 --- a/ee/packages/presence/package.json +++ b/ee/packages/presence/package.json @@ -6,7 +6,7 @@ "@babel/core": "~7.22.20", "@babel/preset-env": "~7.22.20", "@babel/preset-typescript": "~7.22.15", - "@rocket.chat/apps-engine": "^1.42.1", + "@rocket.chat/apps-engine": "1.43.0-alpha.694", "@rocket.chat/eslint-config": "workspace:^", "@rocket.chat/rest-typings": "workspace:^", "@types/node": "^14.18.63", diff --git a/packages/apps/package.json b/packages/apps/package.json index 0d47f6b52779..c4b83a88cf27 100644 --- a/packages/apps/package.json +++ b/packages/apps/package.json @@ -22,7 +22,7 @@ "/dist" ], "dependencies": { - "@rocket.chat/apps-engine": "^1.42.1", + "@rocket.chat/apps-engine": "1.43.0-alpha.694", "@rocket.chat/core-typings": "workspace:^", "@rocket.chat/model-typings": "workspace:^" } diff --git a/packages/core-services/package.json b/packages/core-services/package.json index 8e27b3d2306f..441db2fc52e7 100644 --- a/packages/core-services/package.json +++ b/packages/core-services/package.json @@ -34,7 +34,7 @@ "extends": "../../package.json" }, "dependencies": { - "@rocket.chat/apps-engine": "^1.42.1", + "@rocket.chat/apps-engine": "1.43.0-alpha.694", "@rocket.chat/core-typings": "workspace:^", "@rocket.chat/icons": "^0.34.0", "@rocket.chat/message-parser": "workspace:^", diff --git a/packages/core-typings/package.json b/packages/core-typings/package.json index c0165e9e3c9f..8386cc9b9959 100644 --- a/packages/core-typings/package.json +++ b/packages/core-typings/package.json @@ -23,7 +23,7 @@ "/dist" ], "dependencies": { - "@rocket.chat/apps-engine": "^1.42.1", + "@rocket.chat/apps-engine": "1.43.0-alpha.694", "@rocket.chat/icons": "^0.34.0", "@rocket.chat/message-parser": "workspace:^", "@rocket.chat/ui-kit": "workspace:~" diff --git a/packages/fuselage-ui-kit/package.json b/packages/fuselage-ui-kit/package.json index bd215f0fd8f8..c30350110e1a 100644 --- a/packages/fuselage-ui-kit/package.json +++ b/packages/fuselage-ui-kit/package.json @@ -62,7 +62,7 @@ "@babel/preset-env": "~7.22.20", "@babel/preset-react": "~7.22.15", "@babel/preset-typescript": "~7.22.15", - "@rocket.chat/apps-engine": "^1.42.1", + "@rocket.chat/apps-engine": "1.43.0-alpha.694", "@rocket.chat/eslint-config": "workspace:^", "@rocket.chat/fuselage": "^0.53.2", "@rocket.chat/fuselage-hooks": "^0.33.1", diff --git a/packages/rest-typings/package.json b/packages/rest-typings/package.json index 78091b752a5b..16f232c0e4d1 100644 --- a/packages/rest-typings/package.json +++ b/packages/rest-typings/package.json @@ -25,7 +25,7 @@ "/dist" ], "dependencies": { - "@rocket.chat/apps-engine": "^1.42.1", + "@rocket.chat/apps-engine": "1.43.0-alpha.694", "@rocket.chat/core-typings": "workspace:^", "@rocket.chat/message-parser": "workspace:^", "@rocket.chat/ui-kit": "workspace:~", diff --git a/yarn.lock b/yarn.lock index 09fe4fb8dc9d..8aa231bc087f 100644 --- a/yarn.lock +++ b/yarn.lock @@ -8340,9 +8340,9 @@ __metadata: languageName: unknown linkType: soft -"@rocket.chat/apps-engine@npm:^1.42.1": - version: 1.42.1 - resolution: "@rocket.chat/apps-engine@npm:1.42.1" +"@rocket.chat/apps-engine@npm:1.43.0-alpha.694": + version: 1.43.0-alpha.694 + resolution: "@rocket.chat/apps-engine@npm:1.43.0-alpha.694" dependencies: adm-zip: ^0.5.9 cryptiles: ^4.1.3 @@ -8354,7 +8354,7 @@ __metadata: vm2: ^3.9.19 peerDependencies: "@rocket.chat/ui-kit": "*" - checksum: b38265f53a0d64e8de9862b2039a93cde600b6111f04435301994c95aab252364c0490d1da8cd9a357f80828f75efd83f11e4cea966a1ca86a150bf6439a5de0 + checksum: 0951f1a1632d1b8131c5ecdb23ba3ca83d90e219d89176302c8406c2b1ef6b53e8c82a8f3de120e5bdd7ab31df440f5732d13ca95f6243f7678923f21e038b8a languageName: node linkType: hard @@ -8362,7 +8362,7 @@ __metadata: version: 0.0.0-use.local resolution: "@rocket.chat/apps@workspace:packages/apps" dependencies: - "@rocket.chat/apps-engine": ^1.42.1 + "@rocket.chat/apps-engine": 1.43.0-alpha.694 "@rocket.chat/core-typings": "workspace:^" "@rocket.chat/model-typings": "workspace:^" "@types/jest": ~29.5.7 @@ -8441,7 +8441,7 @@ __metadata: "@babel/core": ~7.22.20 "@babel/preset-env": ~7.22.20 "@babel/preset-typescript": ~7.22.15 - "@rocket.chat/apps-engine": ^1.42.1 + "@rocket.chat/apps-engine": 1.43.0-alpha.694 "@rocket.chat/core-typings": "workspace:^" "@rocket.chat/eslint-config": "workspace:^" "@rocket.chat/icons": ^0.34.0 @@ -8467,7 +8467,7 @@ __metadata: version: 0.0.0-use.local resolution: "@rocket.chat/core-typings@workspace:packages/core-typings" dependencies: - "@rocket.chat/apps-engine": ^1.42.1 + "@rocket.chat/apps-engine": 1.43.0-alpha.694 "@rocket.chat/eslint-config": "workspace:^" "@rocket.chat/icons": ^0.34.0 "@rocket.chat/message-parser": "workspace:^" @@ -8544,7 +8544,7 @@ __metadata: version: 0.0.0-use.local resolution: "@rocket.chat/ddp-streamer@workspace:ee/apps/ddp-streamer" dependencies: - "@rocket.chat/apps-engine": ^1.42.1 + "@rocket.chat/apps-engine": 1.43.0-alpha.694 "@rocket.chat/core-services": "workspace:^" "@rocket.chat/core-typings": "workspace:^" "@rocket.chat/emitter": ~0.31.25 @@ -8739,7 +8739,7 @@ __metadata: "@babel/preset-env": ~7.22.20 "@babel/preset-react": ~7.22.15 "@babel/preset-typescript": ~7.22.15 - "@rocket.chat/apps-engine": ^1.42.1 + "@rocket.chat/apps-engine": 1.43.0-alpha.694 "@rocket.chat/eslint-config": "workspace:^" "@rocket.chat/fuselage": ^0.53.2 "@rocket.chat/fuselage-hooks": ^0.33.1 @@ -9180,7 +9180,7 @@ __metadata: "@rocket.chat/agenda": "workspace:^" "@rocket.chat/api-client": "workspace:^" "@rocket.chat/apps": "workspace:^" - "@rocket.chat/apps-engine": ^1.42.1 + "@rocket.chat/apps-engine": 1.43.0-alpha.694 "@rocket.chat/base64": "workspace:^" "@rocket.chat/cas-validate": "workspace:^" "@rocket.chat/core-services": "workspace:^" @@ -9805,7 +9805,7 @@ __metadata: "@babel/core": ~7.22.20 "@babel/preset-env": ~7.22.20 "@babel/preset-typescript": ~7.22.15 - "@rocket.chat/apps-engine": ^1.42.1 + "@rocket.chat/apps-engine": 1.43.0-alpha.694 "@rocket.chat/core-services": "workspace:^" "@rocket.chat/core-typings": "workspace:^" "@rocket.chat/eslint-config": "workspace:^" @@ -9920,7 +9920,7 @@ __metadata: version: 0.0.0-use.local resolution: "@rocket.chat/rest-typings@workspace:packages/rest-typings" dependencies: - "@rocket.chat/apps-engine": ^1.42.1 + "@rocket.chat/apps-engine": 1.43.0-alpha.694 "@rocket.chat/core-typings": "workspace:^" "@rocket.chat/eslint-config": "workspace:^" "@rocket.chat/message-parser": "workspace:^" @@ -36267,7 +36267,7 @@ __metadata: version: 0.0.0-use.local resolution: "rocketchat-services@workspace:apps/meteor/ee/server/services" dependencies: - "@rocket.chat/apps-engine": ^1.42.1 + "@rocket.chat/apps-engine": 1.43.0-alpha.694 "@rocket.chat/core-services": "workspace:^" "@rocket.chat/core-typings": "workspace:^" "@rocket.chat/emitter": ~0.31.25 From 4b0c386786937eb5c836dcc7076d9d224c932a68 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=83=87=E3=83=B4=E3=81=81=E3=82=93=E3=81=99?= Date: Tue, 16 Apr 2024 13:48:16 +0530 Subject: [PATCH 04/23] change changeset --- .changeset/polite-foxes-repair.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/.changeset/polite-foxes-repair.md b/.changeset/polite-foxes-repair.md index 12f4ce770804..209078d7406b 100644 --- a/.changeset/polite-foxes-repair.md +++ b/.changeset/polite-foxes-repair.md @@ -2,4 +2,8 @@ '@rocket.chat/meteor': minor --- -Implement the `getMessages` method in the Apps Engine Room bridge, this method will allow Apps to fetch messages from a room. +Added the `getMessages` method in the Apps Engine, this method will allow Apps to read room messages. You can pass your own query to filter the messages you want to retrieve. The available options are: + +- `limit`: The number of messages to retrieve. (Default: 100 and Max: 100) +- `skip`: The number of messages to skip. +- `sort`: The sort order of the messages. e.g. `{ ts: -1 }` will sort the messages by timestamp in descending order. From 2b20034d02805b491c43399a6008293f74be2d0d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=83=87=E3=83=B4=E3=81=81=E3=82=93=E3=81=99?= Date: Tue, 16 Apr 2024 14:29:46 +0530 Subject: [PATCH 05/23] make changeset less developer friendly --- .changeset/polite-foxes-repair.md | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/.changeset/polite-foxes-repair.md b/.changeset/polite-foxes-repair.md index 209078d7406b..6e0ec543ca47 100644 --- a/.changeset/polite-foxes-repair.md +++ b/.changeset/polite-foxes-repair.md @@ -2,8 +2,4 @@ '@rocket.chat/meteor': minor --- -Added the `getMessages` method in the Apps Engine, this method will allow Apps to read room messages. You can pass your own query to filter the messages you want to retrieve. The available options are: - -- `limit`: The number of messages to retrieve. (Default: 100 and Max: 100) -- `skip`: The number of messages to skip. -- `sort`: The sort order of the messages. e.g. `{ ts: -1 }` will sort the messages by timestamp in descending order. +Added the `getMessages` method in the Apps Engine, this method will allow Apps to read room messages. You can pass your own query to filter the messages you want to retrieve. With flexibility of viewing up to 100 messages at once, skipping over content you’ve already seen, and sorting messages to find what you need quickly. From caf56fbe26d9db999b822af9b3de220b8956ecbb Mon Sep 17 00:00:00 2001 From: Douglas Gubert Date: Tue, 16 Apr 2024 10:08:26 -0300 Subject: [PATCH 06/23] Update .changeset/polite-foxes-repair.md --- .changeset/polite-foxes-repair.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.changeset/polite-foxes-repair.md b/.changeset/polite-foxes-repair.md index 6e0ec543ca47..2f524c7e5f10 100644 --- a/.changeset/polite-foxes-repair.md +++ b/.changeset/polite-foxes-repair.md @@ -2,4 +2,4 @@ '@rocket.chat/meteor': minor --- -Added the `getMessages` method in the Apps Engine, this method will allow Apps to read room messages. You can pass your own query to filter the messages you want to retrieve. With flexibility of viewing up to 100 messages at once, skipping over content you’ve already seen, and sorting messages to find what you need quickly. +Added a method to the Apps-Engine that allows apps to read multiple messages from a room From c1c537835593573db5ff322f47ec336e21a7b486 Mon Sep 17 00:00:00 2001 From: Dnouv Date: Tue, 16 Apr 2024 18:44:51 +0000 Subject: [PATCH 07/23] handle type assertions --- apps/meteor/app/apps/server/bridges/rooms.ts | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/apps/meteor/app/apps/server/bridges/rooms.ts b/apps/meteor/app/apps/server/bridges/rooms.ts index a383907f26fb..f07267407333 100644 --- a/apps/meteor/app/apps/server/bridges/rooms.ts +++ b/apps/meteor/app/apps/server/bridges/rooms.ts @@ -112,8 +112,17 @@ export class AppRoomBridge extends RoomBridge { appId: string, ): Promise { this.orch.debugLog(`The App ${appId} is getting the messages of the room: "${roomId}"`); + if (typeof options.limit !== 'number') { + options.limit = 100; + } + const { limit, skip, sort = { ts: -1 } } = options; + const messageConverter = this.orch.getConverters()?.get('messages'); + if (!messageConverter) { + throw new Error('Message converter not found'); + } + const messageQueryOptions = { limit: Math.min(limit, 100), skip, @@ -122,11 +131,6 @@ export class AppRoomBridge extends RoomBridge { const messages = await Messages.findVisibleByRoomId(roomId, messageQueryOptions).toArray(); - const messageConverter = this.orch.getConverters()?.get('messages'); - if (!messageConverter) { - throw new Error('Message converter not found'); - } - return Promise.all(messages.map((message) => messageConverter.convertMessage(message))); } From d35c08129bf8847d1381533d6fb3e94e0b9c09c5 Mon Sep 17 00:00:00 2001 From: Dnouv Date: Wed, 17 Apr 2024 08:29:44 +0000 Subject: [PATCH 08/23] handle NaN, -Infifity --- apps/meteor/app/apps/server/bridges/rooms.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/meteor/app/apps/server/bridges/rooms.ts b/apps/meteor/app/apps/server/bridges/rooms.ts index f07267407333..7c1181011e1e 100644 --- a/apps/meteor/app/apps/server/bridges/rooms.ts +++ b/apps/meteor/app/apps/server/bridges/rooms.ts @@ -112,7 +112,7 @@ export class AppRoomBridge extends RoomBridge { appId: string, ): Promise { this.orch.debugLog(`The App ${appId} is getting the messages of the room: "${roomId}"`); - if (typeof options.limit !== 'number') { + if (!Number.isFinite(options.limit) || options.limit < 1) { options.limit = 100; } From fb24310d8212276dc8ac16a4119ce04251719270 Mon Sep 17 00:00:00 2001 From: Dnouv Date: Mon, 20 May 2024 13:10:28 +0530 Subject: [PATCH 09/23] resolve conflick on yarn.lock --- yarn.lock | 42 ------------------------------------------ 1 file changed, 42 deletions(-) diff --git a/yarn.lock b/yarn.lock index 1923a4610359..96312fd7a847 100644 --- a/yarn.lock +++ b/yarn.lock @@ -8340,15 +8340,9 @@ __metadata: languageName: unknown linkType: soft -<<<<<<< HEAD "@rocket.chat/apps-engine@npm:1.43.0-alpha.694": version: 1.43.0-alpha.694 resolution: "@rocket.chat/apps-engine@npm:1.43.0-alpha.694" -======= -"@rocket.chat/apps-engine@npm:1.42.2, @rocket.chat/apps-engine@npm:^1.42.2": - version: 1.42.2 - resolution: "@rocket.chat/apps-engine@npm:1.42.2" ->>>>>>> develop dependencies: adm-zip: ^0.5.9 cryptiles: ^4.1.3 @@ -8360,11 +8354,7 @@ __metadata: vm2: ^3.9.19 peerDependencies: "@rocket.chat/ui-kit": "*" -<<<<<<< HEAD - checksum: 0951f1a1632d1b8131c5ecdb23ba3ca83d90e219d89176302c8406c2b1ef6b53e8c82a8f3de120e5bdd7ab31df440f5732d13ca95f6243f7678923f21e038b8a -======= checksum: d7aa23249823e37072b6b7af16a40d9a4e7cb6b8047f2a87e52163dfe516d6c8a09b21cafd4f28dfbe4dd3da9cd0190d71f7623fec8c573a3f215ca4f9529b56 ->>>>>>> develop languageName: node linkType: hard @@ -8372,11 +8362,7 @@ __metadata: version: 0.0.0-use.local resolution: "@rocket.chat/apps@workspace:packages/apps" dependencies: -<<<<<<< HEAD "@rocket.chat/apps-engine": 1.43.0-alpha.694 -======= - "@rocket.chat/apps-engine": 1.42.2 ->>>>>>> develop "@rocket.chat/core-typings": "workspace:^" "@rocket.chat/model-typings": "workspace:^" "@types/jest": ~29.5.7 @@ -8481,11 +8467,7 @@ __metadata: version: 0.0.0-use.local resolution: "@rocket.chat/core-typings@workspace:packages/core-typings" dependencies: -<<<<<<< HEAD "@rocket.chat/apps-engine": 1.43.0-alpha.694 -======= - "@rocket.chat/apps-engine": 1.42.2 ->>>>>>> develop "@rocket.chat/eslint-config": "workspace:^" "@rocket.chat/icons": ^0.35.0 "@rocket.chat/message-parser": "workspace:^" @@ -8562,11 +8544,7 @@ __metadata: version: 0.0.0-use.local resolution: "@rocket.chat/ddp-streamer@workspace:ee/apps/ddp-streamer" dependencies: -<<<<<<< HEAD "@rocket.chat/apps-engine": 1.43.0-alpha.694 -======= - "@rocket.chat/apps-engine": 1.42.2 ->>>>>>> develop "@rocket.chat/core-services": "workspace:^" "@rocket.chat/core-typings": "workspace:^" "@rocket.chat/emitter": ~0.31.25 @@ -8762,12 +8740,8 @@ __metadata: "@babel/preset-env": ~7.22.20 "@babel/preset-react": ~7.22.15 "@babel/preset-typescript": ~7.22.15 -<<<<<<< HEAD "@rocket.chat/apps-engine": 1.43.0-alpha.694 -======= - "@rocket.chat/apps-engine": ^1.42.2 "@rocket.chat/core-typings": "workspace:^" ->>>>>>> develop "@rocket.chat/eslint-config": "workspace:^" "@rocket.chat/fuselage": ^0.53.7 "@rocket.chat/fuselage-hooks": ^0.33.1 @@ -9210,11 +9184,7 @@ __metadata: "@rocket.chat/agenda": "workspace:^" "@rocket.chat/api-client": "workspace:^" "@rocket.chat/apps": "workspace:^" -<<<<<<< HEAD "@rocket.chat/apps-engine": 1.43.0-alpha.694 -======= - "@rocket.chat/apps-engine": 1.42.2 ->>>>>>> develop "@rocket.chat/base64": "workspace:^" "@rocket.chat/cas-validate": "workspace:^" "@rocket.chat/core-services": "workspace:^" @@ -9852,11 +9822,7 @@ __metadata: "@babel/core": ~7.22.20 "@babel/preset-env": ~7.22.20 "@babel/preset-typescript": ~7.22.15 -<<<<<<< HEAD "@rocket.chat/apps-engine": 1.43.0-alpha.694 -======= - "@rocket.chat/apps-engine": 1.42.2 ->>>>>>> develop "@rocket.chat/core-services": "workspace:^" "@rocket.chat/core-typings": "workspace:^" "@rocket.chat/eslint-config": "workspace:^" @@ -9971,11 +9937,7 @@ __metadata: version: 0.0.0-use.local resolution: "@rocket.chat/rest-typings@workspace:packages/rest-typings" dependencies: -<<<<<<< HEAD "@rocket.chat/apps-engine": 1.43.0-alpha.694 -======= - "@rocket.chat/apps-engine": 1.42.2 ->>>>>>> develop "@rocket.chat/core-typings": "workspace:^" "@rocket.chat/eslint-config": "workspace:^" "@rocket.chat/message-parser": "workspace:^" @@ -36891,11 +36853,7 @@ __metadata: version: 0.0.0-use.local resolution: "rocketchat-services@workspace:apps/meteor/ee/server/services" dependencies: -<<<<<<< HEAD "@rocket.chat/apps-engine": 1.43.0-alpha.694 -======= - "@rocket.chat/apps-engine": 1.42.2 ->>>>>>> develop "@rocket.chat/core-services": "workspace:^" "@rocket.chat/core-typings": "workspace:^" "@rocket.chat/emitter": ~0.31.25 From 47418c5a79517936e2ef170e075eb937f3058e05 Mon Sep 17 00:00:00 2001 From: Dnouv Date: Mon, 20 May 2024 14:35:07 +0530 Subject: [PATCH 10/23] update method and linting issues --- apps/meteor/app/apps/server/bridges/rooms.ts | 30 ++++++++++++++++---- apps/meteor/ee/server/services/package.json | 2 +- apps/meteor/package.json | 2 +- ee/apps/ddp-streamer/package.json | 2 +- ee/packages/presence/package.json | 2 +- packages/apps/package.json | 2 +- packages/core-services/package.json | 2 +- packages/core-typings/package.json | 2 +- packages/fuselage-ui-kit/package.json | 2 +- packages/rest-typings/package.json | 2 +- yarn.lock | 2 +- 11 files changed, 35 insertions(+), 15 deletions(-) diff --git a/apps/meteor/app/apps/server/bridges/rooms.ts b/apps/meteor/app/apps/server/bridges/rooms.ts index 7c1181011e1e..bb211c5c5899 100644 --- a/apps/meteor/app/apps/server/bridges/rooms.ts +++ b/apps/meteor/app/apps/server/bridges/rooms.ts @@ -112,11 +112,20 @@ export class AppRoomBridge extends RoomBridge { appId: string, ): Promise { this.orch.debugLog(`The App ${appId} is getting the messages of the room: "${roomId}"`); - if (!Number.isFinite(options.limit) || options.limit < 1) { - options.limit = 100; + + let { limit, skip = 0, sort } = options; + + if (!Number.isFinite(limit) || limit < 1) { + limit = 100; + } + + if (!Number.isFinite(skip) || skip < 0) { + skip = 0; } - const { limit, skip, sort = { ts: -1 } } = options; + if (!sort || typeof sort !== 'object') { + sort = { ts: -1 }; + } const messageConverter = this.orch.getConverters()?.get('messages'); if (!messageConverter) { @@ -129,9 +138,20 @@ export class AppRoomBridge extends RoomBridge { sort, }; - const messages = await Messages.findVisibleByRoomId(roomId, messageQueryOptions).toArray(); + const query = { + rid: roomId, + _hidden: { $ne: true }, + t: { $exists: false }, + }; + + const cursor = Messages.find(query, messageQueryOptions); + + const messagePromises: Promise[] = []; + await cursor.forEach((message) => { + messagePromises.push(messageConverter.convertMessage(message)); + }); - return Promise.all(messages.map((message) => messageConverter.convertMessage(message))); + return Promise.all(messagePromises); } protected async getMembers(roomId: string, appId: string): Promise> { diff --git a/apps/meteor/ee/server/services/package.json b/apps/meteor/ee/server/services/package.json index 0424c09e0c8a..aa7296be366e 100644 --- a/apps/meteor/ee/server/services/package.json +++ b/apps/meteor/ee/server/services/package.json @@ -67,4 +67,4 @@ "volta": { "extends": "../../../package.json" } -} \ No newline at end of file +} diff --git a/apps/meteor/package.json b/apps/meteor/package.json index 53a81a91782c..824840aebf30 100644 --- a/apps/meteor/package.json +++ b/apps/meteor/package.json @@ -469,4 +469,4 @@ "mobile": "4.39.0" } } -} \ No newline at end of file +} diff --git a/ee/apps/ddp-streamer/package.json b/ee/apps/ddp-streamer/package.json index 47b84564efd1..c3e45a7a2896 100644 --- a/ee/apps/ddp-streamer/package.json +++ b/ee/apps/ddp-streamer/package.json @@ -63,4 +63,4 @@ "files": [ "/dist" ] -} \ No newline at end of file +} diff --git a/ee/packages/presence/package.json b/ee/packages/presence/package.json index 9e1155c3c5af..4f3d5b05b234 100644 --- a/ee/packages/presence/package.json +++ b/ee/packages/presence/package.json @@ -37,4 +37,4 @@ "@rocket.chat/models": "workspace:^", "mongodb": "^4.17.2" } -} \ No newline at end of file +} diff --git a/packages/apps/package.json b/packages/apps/package.json index 6ee35414fba7..aa748dee5a47 100644 --- a/packages/apps/package.json +++ b/packages/apps/package.json @@ -26,4 +26,4 @@ "@rocket.chat/core-typings": "workspace:^", "@rocket.chat/model-typings": "workspace:^" } -} \ No newline at end of file +} diff --git a/packages/core-services/package.json b/packages/core-services/package.json index b35e6dea6f2c..e81ab40d5c07 100644 --- a/packages/core-services/package.json +++ b/packages/core-services/package.json @@ -44,4 +44,4 @@ "@types/fibers": "^3.1.3", "fibers": "^5.0.3" } -} \ No newline at end of file +} diff --git a/packages/core-typings/package.json b/packages/core-typings/package.json index c496f10fc323..6a236f943627 100644 --- a/packages/core-typings/package.json +++ b/packages/core-typings/package.json @@ -31,4 +31,4 @@ "volta": { "extends": "../../package.json" } -} \ No newline at end of file +} diff --git a/packages/fuselage-ui-kit/package.json b/packages/fuselage-ui-kit/package.json index 1d49ac122bb4..a55035b052bc 100644 --- a/packages/fuselage-ui-kit/package.json +++ b/packages/fuselage-ui-kit/package.json @@ -118,4 +118,4 @@ "volta": { "extends": "../../package.json" } -} \ No newline at end of file +} diff --git a/packages/rest-typings/package.json b/packages/rest-typings/package.json index 2a4908f85707..9cb9d02b8377 100644 --- a/packages/rest-typings/package.json +++ b/packages/rest-typings/package.json @@ -35,4 +35,4 @@ "volta": { "extends": "../../package.json" } -} \ No newline at end of file +} diff --git a/yarn.lock b/yarn.lock index 96312fd7a847..013953605cc4 100644 --- a/yarn.lock +++ b/yarn.lock @@ -8354,7 +8354,7 @@ __metadata: vm2: ^3.9.19 peerDependencies: "@rocket.chat/ui-kit": "*" - checksum: d7aa23249823e37072b6b7af16a40d9a4e7cb6b8047f2a87e52163dfe516d6c8a09b21cafd4f28dfbe4dd3da9cd0190d71f7623fec8c573a3f215ca4f9529b56 + checksum: 0951f1a1632d1b8131c5ecdb23ba3ca83d90e219d89176302c8406c2b1ef6b53e8c82a8f3de120e5bdd7ab31df440f5732d13ca95f6243f7678923f21e038b8a languageName: node linkType: hard From 9c10374ba42b1082d315a898e2d733fb269219d5 Mon Sep 17 00:00:00 2001 From: Dnouv Date: Thu, 23 May 2024 18:00:01 +0530 Subject: [PATCH 11/23] introduce new converter to reduce db calls --- apps/meteor/app/apps/server/bridges/rooms.ts | 2 +- .../app/apps/server/converters/messages.js | 53 +++++++++++++++++++ .../src/converters/IAppMessagesConverter.ts | 2 + 3 files changed, 56 insertions(+), 1 deletion(-) diff --git a/apps/meteor/app/apps/server/bridges/rooms.ts b/apps/meteor/app/apps/server/bridges/rooms.ts index bb211c5c5899..db9db8014267 100644 --- a/apps/meteor/app/apps/server/bridges/rooms.ts +++ b/apps/meteor/app/apps/server/bridges/rooms.ts @@ -148,7 +148,7 @@ export class AppRoomBridge extends RoomBridge { const messagePromises: Promise[] = []; await cursor.forEach((message) => { - messagePromises.push(messageConverter.convertMessage(message)); + messagePromises.push(messageConverter.convertMessageRaw(message)); }); return Promise.all(messagePromises); diff --git a/apps/meteor/app/apps/server/converters/messages.js b/apps/meteor/app/apps/server/converters/messages.js index 187a6519339a..160369ed0e9d 100644 --- a/apps/meteor/app/apps/server/converters/messages.js +++ b/apps/meteor/app/apps/server/converters/messages.js @@ -14,6 +14,59 @@ export class AppMessagesConverter { return this.convertMessage(msg); } + async convertMessageRaw(msgObj) { + if (!msgObj) { + return undefined; + } + + const { rid, editedBy, attachments, u, ...message } = msgObj; + + const getRoom = () => ({ id: rid }); + + const getEditor = () => (editedBy ? { id: editedBy.id, username: editedBy.username } : undefined); + + const getAttachments = async () => this._convertAttachmentsToApp(attachments); + + const getSender = () => { + if (!u || !u._id) { + return undefined; + } + + const user = { + id: u._id, + username: u.username, + name: u.name, + }; + + return user; + }; + + const map = { + id: '_id', + threadId: 'tmid', + reactions: 'reactions', + parseUrls: 'parseUrls', + text: 'msg', + createdAt: 'ts', + updatedAt: '_updatedAt', + editedAt: 'editedAt', + emoji: 'emoji', + avatarUrl: 'avatar', + alias: 'alias', + file: 'file', + customFields: 'customFields', + groupable: 'groupable', + token: 'token', + blocks: 'blocks', + room: getRoom, + editor: getEditor, + attachments: getAttachments, + sender: getSender, + }; + + return transformMappedData(message, map); + } + async convertMessage(msgObj) { if (!msgObj) { return undefined; diff --git a/packages/apps/src/converters/IAppMessagesConverter.ts b/packages/apps/src/converters/IAppMessagesConverter.ts index 185e247895de..ebcd226e8d07 100644 --- a/packages/apps/src/converters/IAppMessagesConverter.ts +++ b/packages/apps/src/converters/IAppMessagesConverter.ts @@ -10,4 +10,6 @@ export interface IAppMessagesConverter { convertAppMessage(message: undefined | null): Promise; convertAppMessage(message: IAppsMessage): Promise; convertAppMessage(message: IAppsMessage | undefined | null): Promise; + convertMessageRaw(message: IMessage): Promise; + converMessageRaw(message: IMessage | undefined | null): Promise; } From e9913d8b0df869971a9ca703500a879d2c4e417f Mon Sep 17 00:00:00 2001 From: Dnouv Date: Thu, 23 May 2024 18:04:47 +0530 Subject: [PATCH 12/23] correct type for editedby id --- apps/meteor/app/apps/server/converters/messages.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/meteor/app/apps/server/converters/messages.js b/apps/meteor/app/apps/server/converters/messages.js index 160369ed0e9d..4599fef2dcb4 100644 --- a/apps/meteor/app/apps/server/converters/messages.js +++ b/apps/meteor/app/apps/server/converters/messages.js @@ -23,7 +23,7 @@ export class AppMessagesConverter { const getRoom = () => ({ id: rid }); - const getEditor = () => (editedBy ? { id: editedBy.id, username: editedBy.username } : undefined); + const getEditor = () => (editedBy ? { id: editedBy._id, username: editedBy.username } : undefined); const getAttachments = async () => this._convertAttachmentsToApp(attachments); From 667dcd3f6611ce6f2ade1c20ba3baa98d247456d Mon Sep 17 00:00:00 2001 From: Douglas Gubert Date: Thu, 23 May 2024 15:22:34 -0300 Subject: [PATCH 13/23] Update packages/apps/src/converters/IAppMessagesConverter.ts --- packages/apps/src/converters/IAppMessagesConverter.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/apps/src/converters/IAppMessagesConverter.ts b/packages/apps/src/converters/IAppMessagesConverter.ts index ebcd226e8d07..c57617cf4637 100644 --- a/packages/apps/src/converters/IAppMessagesConverter.ts +++ b/packages/apps/src/converters/IAppMessagesConverter.ts @@ -11,5 +11,5 @@ export interface IAppMessagesConverter { convertAppMessage(message: IAppsMessage): Promise; convertAppMessage(message: IAppsMessage | undefined | null): Promise; convertMessageRaw(message: IMessage): Promise; - converMessageRaw(message: IMessage | undefined | null): Promise; + convertMessageRaw(message: IMessage | undefined | null): Promise; } From cd37b402bb0c2a505e77327090f0c8484621b625 Mon Sep 17 00:00:00 2001 From: Dnouv Date: Fri, 24 May 2024 13:50:38 +0530 Subject: [PATCH 14/23] add new type msgraw --- apps/meteor/app/apps/server/bridges/rooms.ts | 6 ++--- .../app/apps/server/converters/messages.js | 27 +++---------------- packages/apps/src/AppsEngine.ts | 1 + .../src/converters/IAppMessagesConverter.ts | 6 ++--- 4 files changed, 11 insertions(+), 29 deletions(-) diff --git a/apps/meteor/app/apps/server/bridges/rooms.ts b/apps/meteor/app/apps/server/bridges/rooms.ts index db9db8014267..09dc6b7b176a 100644 --- a/apps/meteor/app/apps/server/bridges/rooms.ts +++ b/apps/meteor/app/apps/server/bridges/rooms.ts @@ -1,5 +1,5 @@ import type { IAppServerOrchestrator } from '@rocket.chat/apps'; -import type { IMessage } from '@rocket.chat/apps-engine/definition/messages'; +import type { IMessage, IMessageRaw } from '@rocket.chat/apps-engine/definition/messages'; import type { IRoom } from '@rocket.chat/apps-engine/definition/rooms'; import { RoomType } from '@rocket.chat/apps-engine/definition/rooms'; import type { IUser } from '@rocket.chat/apps-engine/definition/users'; @@ -110,7 +110,7 @@ export class AppRoomBridge extends RoomBridge { sort?: Record; }, appId: string, - ): Promise { + ): Promise { this.orch.debugLog(`The App ${appId} is getting the messages of the room: "${roomId}"`); let { limit, skip = 0, sort } = options; @@ -146,7 +146,7 @@ export class AppRoomBridge extends RoomBridge { const cursor = Messages.find(query, messageQueryOptions); - const messagePromises: Promise[] = []; + const messagePromises: Promise[] = []; await cursor.forEach((message) => { messagePromises.push(messageConverter.convertMessageRaw(message)); }); diff --git a/apps/meteor/app/apps/server/converters/messages.js b/apps/meteor/app/apps/server/converters/messages.js index 4599fef2dcb4..9c937e2aeb3a 100644 --- a/apps/meteor/app/apps/server/converters/messages.js +++ b/apps/meteor/app/apps/server/converters/messages.js @@ -19,28 +19,9 @@ export class AppMessagesConverter { return undefined; } - const { rid, editedBy, attachments, u, ...message } = msgObj; - - const getRoom = () => ({ id: rid }); - - const getEditor = () => (editedBy ? { id: editedBy._id, username: editedBy.username } : undefined); - + const { attachments, ...message } = msgObj; const getAttachments = async () => this._convertAttachmentsToApp(attachments); - const getSender = () => { - if (!u || !u._id) { - return undefined; - } - - const user = { - id: u._id, - username: u.username, - name: u.name, - }; - - return user; - }; - const map = { id: '_id', threadId: 'tmid', @@ -58,10 +39,10 @@ export class AppMessagesConverter { groupable: 'groupable', token: 'token', blocks: 'blocks', - room: getRoom, - editor: getEditor, + room: 'rid', + editor: 'editedBy', attachments: getAttachments, - sender: getSender, + sender: 'u', }; return transformMappedData(message, map); diff --git a/packages/apps/src/AppsEngine.ts b/packages/apps/src/AppsEngine.ts index 856bc1253790..b85672d23f5a 100644 --- a/packages/apps/src/AppsEngine.ts +++ b/packages/apps/src/AppsEngine.ts @@ -8,6 +8,7 @@ export type { IVisitorPhone as IAppsVisitorPhone, } from '@rocket.chat/apps-engine/definition/livechat'; export type { IMessage as IAppsMessage } from '@rocket.chat/apps-engine/definition/messages'; +export type { IMessageRaw as IAppsMesssageRaw } from '@rocket.chat/apps-engine/definition/messages'; export { AppInterface as AppEvents } from '@rocket.chat/apps-engine/definition/metadata'; export type { IUser as IAppsUser } from '@rocket.chat/apps-engine/definition/users'; export type { IRole as IAppsRole } from '@rocket.chat/apps-engine/definition/roles'; diff --git a/packages/apps/src/converters/IAppMessagesConverter.ts b/packages/apps/src/converters/IAppMessagesConverter.ts index c57617cf4637..863c10c95477 100644 --- a/packages/apps/src/converters/IAppMessagesConverter.ts +++ b/packages/apps/src/converters/IAppMessagesConverter.ts @@ -1,6 +1,6 @@ import type { IMessage } from '@rocket.chat/core-typings'; -import type { IAppsMessage } from '../AppsEngine'; +import type { IAppsMessage, IAppsMesssageRaw } from '../AppsEngine'; export interface IAppMessagesConverter { convertById(messageId: IMessage['_id']): Promise; @@ -10,6 +10,6 @@ export interface IAppMessagesConverter { convertAppMessage(message: undefined | null): Promise; convertAppMessage(message: IAppsMessage): Promise; convertAppMessage(message: IAppsMessage | undefined | null): Promise; - convertMessageRaw(message: IMessage): Promise; - convertMessageRaw(message: IMessage | undefined | null): Promise; + convertMessageRaw(message: IMessage): Promise; + convertMessageRaw(message: IMessage | undefined | null): Promise; } From 248495ab3ca62f3874f541f0b50dba57de1a415b Mon Sep 17 00:00:00 2001 From: Dnouv Date: Thu, 30 May 2024 16:05:35 +0530 Subject: [PATCH 15/23] update apps-engine version --- apps/meteor/ee/server/services/package.json | 2 +- apps/meteor/package.json | 2 +- ee/apps/ddp-streamer/package.json | 2 +- ee/packages/presence/package.json | 2 +- packages/apps/package.json | 2 +- packages/core-services/package.json | 2 +- packages/core-typings/package.json | 2 +- packages/fuselage-ui-kit/package.json | 2 +- packages/rest-typings/package.json | 2 +- yarn.lock | 26 ++++++++++----------- 10 files changed, 22 insertions(+), 22 deletions(-) diff --git a/apps/meteor/ee/server/services/package.json b/apps/meteor/ee/server/services/package.json index aa7296be366e..22740da8e9bd 100644 --- a/apps/meteor/ee/server/services/package.json +++ b/apps/meteor/ee/server/services/package.json @@ -18,7 +18,7 @@ "author": "Rocket.Chat", "license": "MIT", "dependencies": { - "@rocket.chat/apps-engine": "1.43.0-alpha.694", + "@rocket.chat/apps-engine": "1.43.0-alpha.754", "@rocket.chat/core-services": "workspace:^", "@rocket.chat/core-typings": "workspace:^", "@rocket.chat/emitter": "~0.31.25", diff --git a/apps/meteor/package.json b/apps/meteor/package.json index 824840aebf30..30c9fcbdae7b 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.694", + "@rocket.chat/apps-engine": "1.43.0-alpha.754", "@rocket.chat/base64": "workspace:^", "@rocket.chat/cas-validate": "workspace:^", "@rocket.chat/core-services": "workspace:^", diff --git a/ee/apps/ddp-streamer/package.json b/ee/apps/ddp-streamer/package.json index c3e45a7a2896..31a271525a99 100644 --- a/ee/apps/ddp-streamer/package.json +++ b/ee/apps/ddp-streamer/package.json @@ -15,7 +15,7 @@ ], "author": "Rocket.Chat", "dependencies": { - "@rocket.chat/apps-engine": "1.43.0-alpha.694", + "@rocket.chat/apps-engine": "1.43.0-alpha.754", "@rocket.chat/core-services": "workspace:^", "@rocket.chat/core-typings": "workspace:^", "@rocket.chat/emitter": "~0.31.25", diff --git a/ee/packages/presence/package.json b/ee/packages/presence/package.json index 4f3d5b05b234..7ae1141ffdb2 100644 --- a/ee/packages/presence/package.json +++ b/ee/packages/presence/package.json @@ -6,7 +6,7 @@ "@babel/core": "~7.22.20", "@babel/preset-env": "~7.22.20", "@babel/preset-typescript": "~7.22.15", - "@rocket.chat/apps-engine": "1.43.0-alpha.694", + "@rocket.chat/apps-engine": "1.43.0-alpha.754", "@rocket.chat/eslint-config": "workspace:^", "@rocket.chat/rest-typings": "workspace:^", "@types/node": "^14.18.63", diff --git a/packages/apps/package.json b/packages/apps/package.json index aa748dee5a47..7ace247970ac 100644 --- a/packages/apps/package.json +++ b/packages/apps/package.json @@ -22,7 +22,7 @@ "/dist" ], "dependencies": { - "@rocket.chat/apps-engine": "1.43.0-alpha.694", + "@rocket.chat/apps-engine": "1.43.0-alpha.754", "@rocket.chat/core-typings": "workspace:^", "@rocket.chat/model-typings": "workspace:^" } diff --git a/packages/core-services/package.json b/packages/core-services/package.json index e81ab40d5c07..d1ea5f255503 100644 --- a/packages/core-services/package.json +++ b/packages/core-services/package.json @@ -34,7 +34,7 @@ "extends": "../../package.json" }, "dependencies": { - "@rocket.chat/apps-engine": "1.43.0-alpha.694", + "@rocket.chat/apps-engine": "1.43.0-alpha.754", "@rocket.chat/core-typings": "workspace:^", "@rocket.chat/icons": "^0.35.0", "@rocket.chat/message-parser": "workspace:^", diff --git a/packages/core-typings/package.json b/packages/core-typings/package.json index 6a236f943627..bf0e3af59497 100644 --- a/packages/core-typings/package.json +++ b/packages/core-typings/package.json @@ -23,7 +23,7 @@ "/dist" ], "dependencies": { - "@rocket.chat/apps-engine": "1.43.0-alpha.694", + "@rocket.chat/apps-engine": "1.43.0-alpha.754", "@rocket.chat/icons": "^0.35.0", "@rocket.chat/message-parser": "workspace:^", "@rocket.chat/ui-kit": "workspace:~" diff --git a/packages/fuselage-ui-kit/package.json b/packages/fuselage-ui-kit/package.json index a55035b052bc..673f2e915317 100644 --- a/packages/fuselage-ui-kit/package.json +++ b/packages/fuselage-ui-kit/package.json @@ -63,7 +63,7 @@ "@babel/preset-env": "~7.22.20", "@babel/preset-react": "~7.22.15", "@babel/preset-typescript": "~7.22.15", - "@rocket.chat/apps-engine": "1.43.0-alpha.694", + "@rocket.chat/apps-engine": "1.43.0-alpha.754", "@rocket.chat/core-typings": "workspace:^", "@rocket.chat/eslint-config": "workspace:^", "@rocket.chat/fuselage": "^0.53.7", diff --git a/packages/rest-typings/package.json b/packages/rest-typings/package.json index 9cb9d02b8377..ea23fee59000 100644 --- a/packages/rest-typings/package.json +++ b/packages/rest-typings/package.json @@ -25,7 +25,7 @@ "/dist" ], "dependencies": { - "@rocket.chat/apps-engine": "1.43.0-alpha.694", + "@rocket.chat/apps-engine": "1.43.0-alpha.754", "@rocket.chat/core-typings": "workspace:^", "@rocket.chat/message-parser": "workspace:^", "@rocket.chat/ui-kit": "workspace:~", diff --git a/yarn.lock b/yarn.lock index 013953605cc4..c60747c6aa17 100644 --- a/yarn.lock +++ b/yarn.lock @@ -8340,9 +8340,9 @@ __metadata: languageName: unknown linkType: soft -"@rocket.chat/apps-engine@npm:1.43.0-alpha.694": - version: 1.43.0-alpha.694 - resolution: "@rocket.chat/apps-engine@npm:1.43.0-alpha.694" +"@rocket.chat/apps-engine@npm:1.43.0-alpha.754": + version: 1.43.0-alpha.754 + resolution: "@rocket.chat/apps-engine@npm:1.43.0-alpha.754" dependencies: adm-zip: ^0.5.9 cryptiles: ^4.1.3 @@ -8354,7 +8354,7 @@ __metadata: vm2: ^3.9.19 peerDependencies: "@rocket.chat/ui-kit": "*" - checksum: 0951f1a1632d1b8131c5ecdb23ba3ca83d90e219d89176302c8406c2b1ef6b53e8c82a8f3de120e5bdd7ab31df440f5732d13ca95f6243f7678923f21e038b8a + checksum: 59b1d9b4485cf5a9ba4072d07c4221d26de64a539acbfdd911d724cd582658247022094596da14b7029033a8129af2097190e086ce1f52bb7f298bb95fdccdb7 languageName: node linkType: hard @@ -8362,7 +8362,7 @@ __metadata: version: 0.0.0-use.local resolution: "@rocket.chat/apps@workspace:packages/apps" dependencies: - "@rocket.chat/apps-engine": 1.43.0-alpha.694 + "@rocket.chat/apps-engine": 1.43.0-alpha.754 "@rocket.chat/core-typings": "workspace:^" "@rocket.chat/model-typings": "workspace:^" "@types/jest": ~29.5.7 @@ -8441,7 +8441,7 @@ __metadata: "@babel/core": ~7.22.20 "@babel/preset-env": ~7.22.20 "@babel/preset-typescript": ~7.22.15 - "@rocket.chat/apps-engine": 1.43.0-alpha.694 + "@rocket.chat/apps-engine": 1.43.0-alpha.754 "@rocket.chat/core-typings": "workspace:^" "@rocket.chat/eslint-config": "workspace:^" "@rocket.chat/icons": ^0.35.0 @@ -8467,7 +8467,7 @@ __metadata: version: 0.0.0-use.local resolution: "@rocket.chat/core-typings@workspace:packages/core-typings" dependencies: - "@rocket.chat/apps-engine": 1.43.0-alpha.694 + "@rocket.chat/apps-engine": 1.43.0-alpha.754 "@rocket.chat/eslint-config": "workspace:^" "@rocket.chat/icons": ^0.35.0 "@rocket.chat/message-parser": "workspace:^" @@ -8544,7 +8544,7 @@ __metadata: version: 0.0.0-use.local resolution: "@rocket.chat/ddp-streamer@workspace:ee/apps/ddp-streamer" dependencies: - "@rocket.chat/apps-engine": 1.43.0-alpha.694 + "@rocket.chat/apps-engine": 1.43.0-alpha.754 "@rocket.chat/core-services": "workspace:^" "@rocket.chat/core-typings": "workspace:^" "@rocket.chat/emitter": ~0.31.25 @@ -8740,7 +8740,7 @@ __metadata: "@babel/preset-env": ~7.22.20 "@babel/preset-react": ~7.22.15 "@babel/preset-typescript": ~7.22.15 - "@rocket.chat/apps-engine": 1.43.0-alpha.694 + "@rocket.chat/apps-engine": 1.43.0-alpha.754 "@rocket.chat/core-typings": "workspace:^" "@rocket.chat/eslint-config": "workspace:^" "@rocket.chat/fuselage": ^0.53.7 @@ -9184,7 +9184,7 @@ __metadata: "@rocket.chat/agenda": "workspace:^" "@rocket.chat/api-client": "workspace:^" "@rocket.chat/apps": "workspace:^" - "@rocket.chat/apps-engine": 1.43.0-alpha.694 + "@rocket.chat/apps-engine": 1.43.0-alpha.754 "@rocket.chat/base64": "workspace:^" "@rocket.chat/cas-validate": "workspace:^" "@rocket.chat/core-services": "workspace:^" @@ -9822,7 +9822,7 @@ __metadata: "@babel/core": ~7.22.20 "@babel/preset-env": ~7.22.20 "@babel/preset-typescript": ~7.22.15 - "@rocket.chat/apps-engine": 1.43.0-alpha.694 + "@rocket.chat/apps-engine": 1.43.0-alpha.754 "@rocket.chat/core-services": "workspace:^" "@rocket.chat/core-typings": "workspace:^" "@rocket.chat/eslint-config": "workspace:^" @@ -9937,7 +9937,7 @@ __metadata: version: 0.0.0-use.local resolution: "@rocket.chat/rest-typings@workspace:packages/rest-typings" dependencies: - "@rocket.chat/apps-engine": 1.43.0-alpha.694 + "@rocket.chat/apps-engine": 1.43.0-alpha.754 "@rocket.chat/core-typings": "workspace:^" "@rocket.chat/eslint-config": "workspace:^" "@rocket.chat/message-parser": "workspace:^" @@ -36853,7 +36853,7 @@ __metadata: version: 0.0.0-use.local resolution: "rocketchat-services@workspace:apps/meteor/ee/server/services" dependencies: - "@rocket.chat/apps-engine": 1.43.0-alpha.694 + "@rocket.chat/apps-engine": 1.43.0-alpha.754 "@rocket.chat/core-services": "workspace:^" "@rocket.chat/core-typings": "workspace:^" "@rocket.chat/emitter": ~0.31.25 From d3c51bed4bcc0e67dc5c864b0f5a887c3eccdeac Mon Sep 17 00:00:00 2001 From: Dnouv Date: Wed, 5 Jun 2024 00:49:04 +0530 Subject: [PATCH 16/23] use map<->foreach --- apps/meteor/app/apps/server/bridges/rooms.ts | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/apps/meteor/app/apps/server/bridges/rooms.ts b/apps/meteor/app/apps/server/bridges/rooms.ts index 09dc6b7b176a..26c9b454c437 100644 --- a/apps/meteor/app/apps/server/bridges/rooms.ts +++ b/apps/meteor/app/apps/server/bridges/rooms.ts @@ -146,10 +146,7 @@ export class AppRoomBridge extends RoomBridge { const cursor = Messages.find(query, messageQueryOptions); - const messagePromises: Promise[] = []; - await cursor.forEach((message) => { - messagePromises.push(messageConverter.convertMessageRaw(message)); - }); + const messagePromises: Promise[] = await cursor.map((message) => messageConverter.convertMessageRaw(message)).toArray(); return Promise.all(messagePromises); } From fd2aee8f8839b02bf14decd44911a5dc9766e7f6 Mon Sep 17 00:00:00 2001 From: Dnouv Date: Sat, 8 Jun 2024 00:04:34 +0530 Subject: [PATCH 17/23] add logs --- apps/meteor/app/apps/server/bridges/rooms.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/apps/meteor/app/apps/server/bridges/rooms.ts b/apps/meteor/app/apps/server/bridges/rooms.ts index 26c9b454c437..6e3f8df5fdd8 100644 --- a/apps/meteor/app/apps/server/bridges/rooms.ts +++ b/apps/meteor/app/apps/server/bridges/rooms.ts @@ -111,11 +111,12 @@ export class AppRoomBridge extends RoomBridge { }, appId: string, ): Promise { - this.orch.debugLog(`The App ${appId} is getting the messages of the room: "${roomId}"`); + this.orch.debugLog(`The App ${appId} is getting the messages of the room: "${roomId}" with options:`, options); let { limit, skip = 0, sort } = options; if (!Number.isFinite(limit) || limit < 1) { + this.orch.debugLog(`The limit parameter must be a number greater than 0. Received: ${limit}. It will be set to 100.`); limit = 100; } From 41f3b9f582f8026dd5f38ae71340a9bda9f540bd Mon Sep 17 00:00:00 2001 From: Douglas Gubert Date: Mon, 10 Jun 2024 20:14:52 -0300 Subject: [PATCH 18/23] Fix wrong field name --- apps/meteor/app/apps/server/converters/messages.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/meteor/app/apps/server/converters/messages.js b/apps/meteor/app/apps/server/converters/messages.js index 9c937e2aeb3a..fb7ded38928d 100644 --- a/apps/meteor/app/apps/server/converters/messages.js +++ b/apps/meteor/app/apps/server/converters/messages.js @@ -39,7 +39,7 @@ export class AppMessagesConverter { groupable: 'groupable', token: 'token', blocks: 'blocks', - room: 'rid', + roomId: 'rid', editor: 'editedBy', attachments: getAttachments, sender: 'u', From deabeb64d878b01e2678bfe240a737f808c1e5b1 Mon Sep 17 00:00:00 2001 From: Dnouv Date: Thu, 20 Jun 2024 15:02:52 +0530 Subject: [PATCH 19/23] remove the limit checks --- apps/meteor/app/apps/server/bridges/rooms.ts | 17 ++--------------- 1 file changed, 2 insertions(+), 15 deletions(-) diff --git a/apps/meteor/app/apps/server/bridges/rooms.ts b/apps/meteor/app/apps/server/bridges/rooms.ts index 6e3f8df5fdd8..8ea2a0e6904e 100644 --- a/apps/meteor/app/apps/server/bridges/rooms.ts +++ b/apps/meteor/app/apps/server/bridges/rooms.ts @@ -113,20 +113,7 @@ export class AppRoomBridge extends RoomBridge { ): Promise { this.orch.debugLog(`The App ${appId} is getting the messages of the room: "${roomId}" with options:`, options); - let { limit, skip = 0, sort } = options; - - if (!Number.isFinite(limit) || limit < 1) { - this.orch.debugLog(`The limit parameter must be a number greater than 0. Received: ${limit}. It will be set to 100.`); - limit = 100; - } - - if (!Number.isFinite(skip) || skip < 0) { - skip = 0; - } - - if (!sort || typeof sort !== 'object') { - sort = { ts: -1 }; - } + const { limit, skip = 0, sort } = options; const messageConverter = this.orch.getConverters()?.get('messages'); if (!messageConverter) { @@ -134,7 +121,7 @@ export class AppRoomBridge extends RoomBridge { } const messageQueryOptions = { - limit: Math.min(limit, 100), + limit, skip, sort, }; From 6ac6e9dad0b2bb46f51888f178cfa79a3e2c7e9a Mon Sep 17 00:00:00 2001 From: Douglas Gubert Date: Thu, 18 Jul 2024 21:39:58 -0300 Subject: [PATCH 20/23] Adapt implementation to apps-engine changes --- apps/meteor/app/apps/server/bridges/rooms.ts | 25 ++++---------------- 1 file changed, 5 insertions(+), 20 deletions(-) diff --git a/apps/meteor/app/apps/server/bridges/rooms.ts b/apps/meteor/app/apps/server/bridges/rooms.ts index 7d1d0395120d..281e40a8ee5e 100644 --- a/apps/meteor/app/apps/server/bridges/rooms.ts +++ b/apps/meteor/app/apps/server/bridges/rooms.ts @@ -3,8 +3,8 @@ import type { IMessage, IMessageRaw } from '@rocket.chat/apps-engine/definition/ import type { IRoom } from '@rocket.chat/apps-engine/definition/rooms'; import { RoomType } from '@rocket.chat/apps-engine/definition/rooms'; import type { IUser } from '@rocket.chat/apps-engine/definition/users'; -import { RoomBridge } from '@rocket.chat/apps-engine/server/bridges/RoomBridge'; -import type { ISubscription, IUser as ICoreUser, IRoom as ICoreRoom } from '@rocket.chat/core-typings'; +import { GetMessagesOptions, RoomBridge } from '@rocket.chat/apps-engine/server/bridges/RoomBridge'; +import type { ISubscription, IUser as ICoreUser, IRoom as ICoreRoom, IMessage as ICoreMessage } from '@rocket.chat/core-typings'; import { Subscriptions, Users, Rooms, Messages } from '@rocket.chat/models'; import { createDirectMessage } from '../../../../server/methods/createDirectMessage'; @@ -14,6 +14,7 @@ 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'; +import { FindOptions } from 'mongodb'; export class AppRoomBridge extends RoomBridge { constructor(private readonly orch: IAppServerOrchestrator) { @@ -103,15 +104,7 @@ export class AppRoomBridge extends RoomBridge { return this.orch.getConverters()?.get('users').convertById(room.u._id); } - protected async getMessages( - roomId: string, - options: { - limit: number; - skip?: number; - sort?: Record; - }, - appId: string, - ): Promise { + protected async getMessages(roomId: string, options: GetMessagesOptions, appId: string): Promise { this.orch.debugLog(`The App ${appId} is getting the messages of the room: "${roomId}" with options:`, options); const { limit, skip = 0, sort } = options; @@ -121,7 +114,7 @@ export class AppRoomBridge extends RoomBridge { throw new Error('Message converter not found'); } - const messageQueryOptions = { + const messageQueryOptions: FindOptions = { limit, skip, sort, @@ -257,12 +250,4 @@ export class AppRoomBridge extends RoomBridge { const members = await Users.findUsersByUsernames(usernames, { limit: 50 }).toArray(); await Promise.all(members.map((user) => removeUserFromRoom(roomId, user))); } - - protected getMessages( - _roomId: string, - _options: { limit: number; skip?: number; sort?: Record }, - _appId: string, - ): Promise { - throw new Error('Method not implemented.'); - } } From a5348fd1aad246aa2d46fa313ce8a855f7be3988 Mon Sep 17 00:00:00 2001 From: Dnouv Date: Fri, 19 Jul 2024 17:02:39 +0530 Subject: [PATCH 21/23] bump apps engine --- apps/meteor/ee/server/services/package.json | 2 +- apps/meteor/package.json | 2 +- ee/apps/ddp-streamer/package.json | 2 +- ee/packages/presence/package.json | 2 +- packages/apps/package.json | 2 +- packages/core-services/package.json | 2 +- packages/core-typings/package.json | 2 +- packages/fuselage-ui-kit/package.json | 2 +- packages/rest-typings/package.json | 2 +- yarn.lock | 6 +++--- 10 files changed, 12 insertions(+), 12 deletions(-) diff --git a/apps/meteor/ee/server/services/package.json b/apps/meteor/ee/server/services/package.json index 37efc4f1d840..b36f89a01c3e 100644 --- a/apps/meteor/ee/server/services/package.json +++ b/apps/meteor/ee/server/services/package.json @@ -67,4 +67,4 @@ "volta": { "extends": "../../../package.json" } -} \ No newline at end of file +} diff --git a/apps/meteor/package.json b/apps/meteor/package.json index ee7639fa1db3..0a4877dbeede 100644 --- a/apps/meteor/package.json +++ b/apps/meteor/package.json @@ -469,4 +469,4 @@ "mobile": "4.39.0" } } -} \ No newline at end of file +} diff --git a/ee/apps/ddp-streamer/package.json b/ee/apps/ddp-streamer/package.json index 2324ee9d297c..b20066036c20 100644 --- a/ee/apps/ddp-streamer/package.json +++ b/ee/apps/ddp-streamer/package.json @@ -63,4 +63,4 @@ "files": [ "/dist" ] -} \ No newline at end of file +} diff --git a/ee/packages/presence/package.json b/ee/packages/presence/package.json index 1c16b3ec6180..0ff069768423 100644 --- a/ee/packages/presence/package.json +++ b/ee/packages/presence/package.json @@ -37,4 +37,4 @@ "@rocket.chat/models": "workspace:^", "mongodb": "^4.17.2" } -} \ No newline at end of file +} diff --git a/packages/apps/package.json b/packages/apps/package.json index a69bc1527954..3387deeea23a 100644 --- a/packages/apps/package.json +++ b/packages/apps/package.json @@ -26,4 +26,4 @@ "@rocket.chat/core-typings": "workspace:^", "@rocket.chat/model-typings": "workspace:^" } -} \ No newline at end of file +} diff --git a/packages/core-services/package.json b/packages/core-services/package.json index d606f7abb577..4b7ce783ac8c 100644 --- a/packages/core-services/package.json +++ b/packages/core-services/package.json @@ -44,4 +44,4 @@ "@types/fibers": "^3.1.3", "fibers": "^5.0.3" } -} \ No newline at end of file +} diff --git a/packages/core-typings/package.json b/packages/core-typings/package.json index aefde058264d..7932b00b7e5f 100644 --- a/packages/core-typings/package.json +++ b/packages/core-typings/package.json @@ -30,4 +30,4 @@ "volta": { "extends": "../../package.json" } -} \ No newline at end of file +} diff --git a/packages/fuselage-ui-kit/package.json b/packages/fuselage-ui-kit/package.json index 4955e3063d96..622741719481 100644 --- a/packages/fuselage-ui-kit/package.json +++ b/packages/fuselage-ui-kit/package.json @@ -118,4 +118,4 @@ "volta": { "extends": "../../package.json" } -} \ No newline at end of file +} diff --git a/packages/rest-typings/package.json b/packages/rest-typings/package.json index 099dba4add49..9be27e7634cb 100644 --- a/packages/rest-typings/package.json +++ b/packages/rest-typings/package.json @@ -34,4 +34,4 @@ "volta": { "extends": "../../package.json" } -} \ No newline at end of file +} diff --git a/yarn.lock b/yarn.lock index e7555d99208e..6d962b084493 100644 --- a/yarn.lock +++ b/yarn.lock @@ -8510,8 +8510,8 @@ __metadata: linkType: soft "@rocket.chat/apps-engine@npm:alpha": - version: 1.44.0-alpha.818 - resolution: "@rocket.chat/apps-engine@npm:1.44.0-alpha.818" + version: 1.44.0-alpha.828 + resolution: "@rocket.chat/apps-engine@npm:1.44.0-alpha.828" dependencies: "@msgpack/msgpack": 3.0.0-beta2 adm-zip: ^0.5.9 @@ -8527,7 +8527,7 @@ __metadata: uuid: ~8.3.2 peerDependencies: "@rocket.chat/ui-kit": "*" - checksum: acef47bc7f13e0682d018531638b5168c3acd59beae37b013e881ea6fadfe12670fe10545f4a89487f7bedbe9166028833cba7ed3fc401d4283327e47e00e61c + checksum: e26914b62d2e9823577fe8165a2635d65f69ddc315a880bbc417ddd674e4df487dc9bc9507bf3a0616de06cd927596872c1e90e4c29c61da8581e0a1b7c8d97d languageName: node linkType: hard From b0d35be81b628b62d75fec21b8d25fef04ca8547 Mon Sep 17 00:00:00 2001 From: Dnouv Date: Fri, 19 Jul 2024 19:39:08 +0530 Subject: [PATCH 22/23] lint --- apps/meteor/app/apps/server/bridges/rooms.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/apps/meteor/app/apps/server/bridges/rooms.ts b/apps/meteor/app/apps/server/bridges/rooms.ts index 281e40a8ee5e..b395b1dcadc1 100644 --- a/apps/meteor/app/apps/server/bridges/rooms.ts +++ b/apps/meteor/app/apps/server/bridges/rooms.ts @@ -3,9 +3,11 @@ import type { IMessage, IMessageRaw } from '@rocket.chat/apps-engine/definition/ import type { IRoom } from '@rocket.chat/apps-engine/definition/rooms'; import { RoomType } from '@rocket.chat/apps-engine/definition/rooms'; import type { IUser } from '@rocket.chat/apps-engine/definition/users'; -import { GetMessagesOptions, RoomBridge } from '@rocket.chat/apps-engine/server/bridges/RoomBridge'; +import type { GetMessagesOptions } from '@rocket.chat/apps-engine/server/bridges/RoomBridge'; +import { RoomBridge } from '@rocket.chat/apps-engine/server/bridges/RoomBridge'; import type { ISubscription, IUser as ICoreUser, IRoom as ICoreRoom, IMessage as ICoreMessage } from '@rocket.chat/core-typings'; import { Subscriptions, Users, Rooms, Messages } from '@rocket.chat/models'; +import type { FindOptions } from 'mongodb'; import { createDirectMessage } from '../../../../server/methods/createDirectMessage'; import { createDiscussion } from '../../../discussion/server/methods/createDiscussion'; @@ -14,7 +16,6 @@ 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'; -import { FindOptions } from 'mongodb'; export class AppRoomBridge extends RoomBridge { constructor(private readonly orch: IAppServerOrchestrator) { From 22aca584bc0f4e21cb02d44343c1c8dc0b47f840 Mon Sep 17 00:00:00 2001 From: Douglas Gubert Date: Fri, 19 Jul 2024 12:56:23 -0300 Subject: [PATCH 23/23] Convert field name in sort option --- apps/meteor/app/apps/server/bridges/rooms.ts | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/apps/meteor/app/apps/server/bridges/rooms.ts b/apps/meteor/app/apps/server/bridges/rooms.ts index b395b1dcadc1..344acc74bda4 100644 --- a/apps/meteor/app/apps/server/bridges/rooms.ts +++ b/apps/meteor/app/apps/server/bridges/rooms.ts @@ -7,7 +7,7 @@ import type { GetMessagesOptions } from '@rocket.chat/apps-engine/server/bridges import { RoomBridge } from '@rocket.chat/apps-engine/server/bridges/RoomBridge'; import type { ISubscription, IUser as ICoreUser, IRoom as ICoreRoom, IMessage as ICoreMessage } from '@rocket.chat/core-typings'; import { Subscriptions, Users, Rooms, Messages } from '@rocket.chat/models'; -import type { FindOptions } from 'mongodb'; +import type { FindOptions, Sort } from 'mongodb'; import { createDirectMessage } from '../../../../server/methods/createDirectMessage'; import { createDiscussion } from '../../../discussion/server/methods/createDiscussion'; @@ -108,13 +108,16 @@ export class AppRoomBridge extends RoomBridge { protected async getMessages(roomId: string, options: GetMessagesOptions, appId: string): Promise { this.orch.debugLog(`The App ${appId} is getting the messages of the room: "${roomId}" with options:`, options); - const { limit, skip = 0, sort } = options; + const { limit, skip = 0, sort: _sort } = options; const messageConverter = this.orch.getConverters()?.get('messages'); if (!messageConverter) { throw new Error('Message converter not found'); } + // We support only one field for now + const sort: Sort | undefined = _sort?.createdAt ? { ts: _sort.createdAt } : undefined; + const messageQueryOptions: FindOptions = { limit, skip,