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 for reading and counting unread room messages for a user #32194

Merged
merged 28 commits into from
Oct 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
b903f16
add unread read
Dnouv Apr 12, 2024
cb8b653
Add support for getting unread message count by room
Dnouv Apr 15, 2024
223378c
change param order and change changeset
Apr 16, 2024
433d8d8
check for NaN
Apr 17, 2024
9548065
merge develop
Dnouv Sep 20, 2024
f32dc9d
update method w changes on limits
Dnouv Sep 20, 2024
5defb76
migrate methods to room bridge
Dnouv Sep 24, 2024
8d5d083
Merge branch 'develop' into new/unread_bridge
d-gubert Sep 25, 2024
a7937c5
correct name and order
Dnouv Sep 26, 2024
d9d98ce
Merge branch 'develop' into new/unread_bridge
Dnouv Sep 30, 2024
f99ab7d
Merge branch 'develop' into new/unread_bridge
Dnouv Oct 4, 2024
9650e4b
Merge branch 'develop' into new/unread_bridge
Dnouv Oct 7, 2024
8e5b2a9
Update .changeset/chilled-files-relate.md
Dnouv Oct 10, 2024
d4ac717
Merge branch 'develop' into new/unread_bridge
Dnouv Oct 10, 2024
6bf8804
make sequential
Dnouv Oct 10, 2024
162082f
Merge branch 'develop' into new/unread_bridge
Dnouv Oct 10, 2024
0d61bce
Merge branch 'develop' into new/unread_bridge
kodiakhq[bot] Oct 10, 2024
fcdb0b4
update changeset
Dnouv Oct 11, 2024
d00555d
remove room checks
Dnouv Oct 11, 2024
2979d60
simplify error messages
Dnouv Oct 11, 2024
0c28e39
debug log
Dnouv Oct 11, 2024
2edfa2c
Merge branch 'develop' into new/unread_bridge
Dnouv Oct 11, 2024
96ba70e
Merge branch 'develop' into new/unread_bridge
Dnouv Oct 11, 2024
09f74aa
Merge branch 'develop' into new/unread_bridge
Dnouv Oct 12, 2024
16559d2
Merge branch 'develop' into new/unread_bridge
Dnouv Oct 14, 2024
99b9be2
Merge branch 'develop' into new/unread_bridge
Dnouv Oct 15, 2024
0d4ce6b
Merge branch 'develop' into new/unread_bridge
Dnouv Oct 15, 2024
027b566
Merge branch 'develop' into new/unread_bridge
Dnouv Oct 15, 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/chilled-files-relate.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@rocket.chat/meteor': minor
---

Adds methods to the Apps-Engine to interact with unread messages to enhance message capabilities on Apps.
51 changes: 51 additions & 0 deletions apps/meteor/app/apps/server/bridges/rooms.ts
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,57 @@ export class AppRoomBridge extends RoomBridge {
return users.map((user: ICoreUser) => userConverter.convertToApp(user));
}

protected async getUnreadByUser(roomId: string, uid: string, options: GetMessagesOptions, appId: string): Promise<Array<IMessageRaw>> {
this.orch.debugLog(`The App ${appId} is getting the unread messages for the user: "${uid}" in the room: "${roomId}"`);

const messageConverter = this.orch.getConverters()?.get('messages');
if (!messageConverter) {
throw new Error('Message converter not found');
}

const subscription = await Subscriptions.findOneByRoomIdAndUserId(roomId, uid, { projection: { ls: 1 } });

if (!subscription) {
Dnouv marked this conversation as resolved.
Show resolved Hide resolved
const errorMessage = `No subscription found for user with ID "${uid}" in room with ID "${roomId}". This means the user is not subscribed to the room.`;
this.orch.debugLog(errorMessage);
throw new Error('User not subscribed to room');
}

const lastSeen = subscription?.ls;
if (!lastSeen) {
return [];
}

const sort: Sort = options.sort?.createdAt ? { ts: options.sort.createdAt } : { ts: 1 };

const cursor = Messages.findVisibleByRoomIdBetweenTimestampsNotContainingTypes(roomId, lastSeen, new Date(), [], {
Dnouv marked this conversation as resolved.
Show resolved Hide resolved
...options,
sort,
});

const messages = await cursor.toArray();
return Promise.all(messages.map((msg) => messageConverter.convertMessageRaw(msg)));
Dnouv marked this conversation as resolved.
Show resolved Hide resolved
}

protected async getUserUnreadMessageCount(roomId: string, uid: string, appId: string): Promise<number> {
this.orch.debugLog(`The App ${appId} is getting the unread messages count of the room: "${roomId}" for the user: "${uid}"`);

const subscription = await Subscriptions.findOneByRoomIdAndUserId(roomId, uid, { projection: { ls: 1 } });

if (!subscription) {
const errorMessage = `No subscription found for user with ID "${uid}" in room with ID "${roomId}". This means the user is not subscribed to the room.`;
this.orch.debugLog(errorMessage);
throw new Error('User not subscribed to room');
}

const lastSeen = subscription?.ls;
if (!lastSeen) {
return 0;
}

return Messages.countVisibleByRoomIdBetweenTimestampsNotContainingTypes(roomId, lastSeen, new Date(), []);
Dnouv marked this conversation as resolved.
Show resolved Hide resolved
}

protected async removeUsers(roomId: string, usernames: Array<string>, appId: string): Promise<void> {
this.orch.debugLog(`The App ${appId} is removing users ${usernames} from room id: ${roomId}`);
if (!roomId) {
Expand Down
Loading