Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Apps-Engine method to read multiple messages from a room #32176

Merged
merged 37 commits into from
Jul 19, 2024
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
d7134c5
implement the rooms bridge
Dnouv Apr 11, 2024
2c6bd5b
change param order
Dnouv Apr 15, 2024
f3bb1a5
Update Apps-Engine
d-gubert Apr 15, 2024
4b0c386
change changeset
Dnouv Apr 16, 2024
9d34e6d
Merge branch 'develop' into new/room_msg_bridge
Dnouv Apr 16, 2024
2b20034
make changeset less developer friendly
Dnouv Apr 16, 2024
caf56fb
Update .changeset/polite-foxes-repair.md
d-gubert Apr 16, 2024
c1c5378
handle type assertions
Apr 16, 2024
d35c081
handle NaN, -Infifity
Apr 17, 2024
12b2b84
merge develop
Dnouv May 20, 2024
fb24310
resolve conflick on yarn.lock
Dnouv May 20, 2024
47418c5
update method and linting issues
Dnouv May 20, 2024
33cd125
Merge branch 'develop' into new/room_msg_bridge
d-gubert May 20, 2024
9c10374
introduce new converter to reduce db calls
Dnouv May 23, 2024
e9913d8
correct type for editedby id
Dnouv May 23, 2024
4f91b44
Merge branch 'develop' into new/room_msg_bridge
Dnouv May 23, 2024
667dcd3
Update packages/apps/src/converters/IAppMessagesConverter.ts
d-gubert May 23, 2024
cd37b40
add new type msgraw
Dnouv May 24, 2024
248495a
update apps-engine version
Dnouv May 30, 2024
eb4e60d
Merge branch 'develop' into new/room_msg_bridge
Dnouv May 30, 2024
624e077
Merge branch 'develop' into new/room_msg_bridge
d-gubert May 31, 2024
a58737b
Merge branch 'develop' into new/room_msg_bridge
d-gubert May 31, 2024
06042f6
Merge branch 'develop' into new/room_msg_bridge
d-gubert Jun 3, 2024
d3c51be
use map<->foreach
Dnouv Jun 4, 2024
fd2aee8
add logs
Dnouv Jun 7, 2024
41f3b9f
Fix wrong field name
d-gubert Jun 10, 2024
deabeb6
remove the limit checks
Dnouv Jun 20, 2024
f35fa9a
merge develop
Dnouv Jun 20, 2024
0dc45d9
Merge remote-tracking branch 'origin/develop' into new/room_msg_bridge
d-gubert Jul 19, 2024
6ac6e9d
Adapt implementation to apps-engine changes
d-gubert Jul 19, 2024
286d1a6
Merge branch 'develop' into new/room_msg_bridge
Dnouv Jul 19, 2024
a5348fd
bump apps engine
Dnouv Jul 19, 2024
b0d35be
lint
Dnouv Jul 19, 2024
bd288d8
Merge branch 'develop' into new/room_msg_bridge
Dnouv Jul 19, 2024
22aca58
Convert field name in sort option
d-gubert Jul 19, 2024
a73afff
Merge branch 'develop' into new/room_msg_bridge
d-gubert Jul 19, 2024
8a0e0fa
Merge branch 'develop' into new/room_msg_bridge
d-gubert Jul 19, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/polite-foxes-repair.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@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.
d-gubert marked this conversation as resolved.
Show resolved Hide resolved
30 changes: 29 additions & 1 deletion apps/meteor/app/apps/server/bridges/rooms.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -102,6 +102,34 @@ 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<string, 1 | -1>;
},
appId: string,
): Promise<IMessage[]> {
this.orch.debugLog(`The App ${appId} is getting the messages of the room: "${roomId}"`);
Dnouv marked this conversation as resolved.
Show resolved Hide resolved
const { limit, skip, sort = { ts: -1 } } = options;

const messageQueryOptions = {
limit: Math.min(limit, 100),
skip,
sort,
};
Dnouv marked this conversation as resolved.
Show resolved Hide resolved

const messages = await Messages.findVisibleByRoomId(roomId, messageQueryOptions).toArray();

const messageConverter = this.orch.getConverters()?.get('messages');
if (!messageConverter) {
throw new Error('Message converter not found');
}
Dnouv marked this conversation as resolved.
Show resolved Hide resolved

return Promise.all(messages.map((message) => messageConverter.convertMessage(message)));
}

protected async getMembers(roomId: string, appId: string): Promise<Array<IUser>> {
this.orch.debugLog(`The App ${appId} is getting the room's members by room id: "${roomId}"`);
const subscriptions = await Subscriptions.findByRoomId(roomId, {});
Expand Down
2 changes: 1 addition & 1 deletion apps/meteor/ee/server/services/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion apps/meteor/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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:^",
Expand Down
2 changes: 1 addition & 1 deletion ee/apps/ddp-streamer/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion ee/packages/presence/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion packages/apps/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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:^"
}
Expand Down
2 changes: 1 addition & 1 deletion packages/core-services/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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:^",
Expand Down
2 changes: 1 addition & 1 deletion packages/core-typings/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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:~"
Expand Down
2 changes: 1 addition & 1 deletion packages/fuselage-ui-kit/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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.4",
"@rocket.chat/fuselage-hooks": "^0.33.1",
Expand Down
2 changes: 1 addition & 1 deletion packages/rest-typings/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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:~",
Expand Down
26 changes: 13 additions & 13 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -8354,15 +8354,15 @@ __metadata:
vm2: ^3.9.19
peerDependencies:
"@rocket.chat/ui-kit": "*"
checksum: b38265f53a0d64e8de9862b2039a93cde600b6111f04435301994c95aab252364c0490d1da8cd9a357f80828f75efd83f11e4cea966a1ca86a150bf6439a5de0
checksum: 0951f1a1632d1b8131c5ecdb23ba3ca83d90e219d89176302c8406c2b1ef6b53e8c82a8f3de120e5bdd7ab31df440f5732d13ca95f6243f7678923f21e038b8a
languageName: node
linkType: hard

"@rocket.chat/apps@workspace:^, @rocket.chat/apps@workspace:packages/apps":
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
Expand Down Expand Up @@ -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
Expand All @@ -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:^"
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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.42.1
"@rocket.chat/apps-engine": 1.43.0-alpha.694
"@rocket.chat/eslint-config": "workspace:^"
"@rocket.chat/fuselage": ^0.53.4
"@rocket.chat/fuselage-hooks": ^0.33.1
Expand Down Expand Up @@ -9181,7 +9181,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:^"
Expand Down Expand Up @@ -9806,7 +9806,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:^"
Expand Down Expand Up @@ -9921,7 +9921,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:^"
Expand Down Expand Up @@ -36841,7 +36841,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
Expand Down
Loading