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 1 commit
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
---

Implement the `getMessages` method in the Apps Engine Room bridge, this method will allow Apps to fetch messages from a room.
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,
appId: string,
d-gubert marked this conversation as resolved.
Show resolved Hide resolved
options: {
limit?: number;
skip?: number;
sort?: Record<string, 1 | -1>;
} = {},
): 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 = 100, 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
Loading