Skip to content

Commit 1cba261

Browse files
committed
fix: format thread followers filter helper (prettier)
1 parent fe2dfca commit 1cba261

1 file changed

Lines changed: 30 additions & 45 deletions

File tree

apps/meteor/app/threads/server/functions.ts

Lines changed: 30 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,38 @@
11
import type { IMessage, IRoom } from '@rocket.chat/core-typings';
22
import { isEditedMessage } from '@rocket.chat/core-typings';
3-
import { Messages, Subscriptions, ReadReceipts, NotificationQueue, Rooms } from '@rocket.chat/models';
3+
import { Messages, NotificationQueue, ReadReceipts, Rooms, Subscriptions } from '@rocket.chat/models';
44

55
import {
66
notifyOnSubscriptionChangedByRoomIdAndUserIds,
77
notifyOnSubscriptionChangedByRoomIdAndUserId,
88
} from '../../lib/server/lib/notifyListener';
99
import { getMentions, getUserIdsFromHighlights } from '../../lib/server/lib/notifyUsersOnMessage';
1010

11+
async function filterUsersInRoom({ roomId, userIds, room }: { roomId: string; userIds: string[]; room: IRoom | null }): Promise<string[]> {
12+
try {
13+
if (!userIds.length || !room) {
14+
return [];
15+
}
16+
17+
if (room.t === 'd') {
18+
return userIds.filter((userId) => room.uids?.includes(userId));
19+
}
20+
21+
if (room.t === 'p' || room.t === 'c') {
22+
const subscriptions = await Subscriptions.findByRoomIdAndUserIds(roomId, userIds, {
23+
projection: { u: 1 },
24+
}).toArray();
25+
26+
return subscriptions.filter((sub) => sub.u?._id).map((sub) => sub.u._id);
27+
}
28+
29+
return [];
30+
} catch (error) {
31+
console.error('Error filtering users in room:', { roomId, error });
32+
return [];
33+
}
34+
}
35+
1136
export async function reply({ tmid }: { tmid?: string }, message: IMessage, parentMessage: IMessage, followers: string[]) {
1237
if (!tmid || isEditedMessage(message)) {
1338
return false;
@@ -16,55 +41,19 @@ export async function reply({ tmid }: { tmid?: string }, message: IMessage, pare
1641
const { rid, ts, u } = message;
1742

1843
const { toAll, toHere, mentionIds } = await getMentions(message);
19-
20-
const filterUsersInRoom = async ({
21-
roomId,
22-
userIds,
23-
room
24-
}: {
25-
roomId: string;
26-
userIds: string[];
27-
room: IRoom | null
28-
}) => {
29-
try {
30-
31-
if (!userIds.length || !room) {
32-
return [];
33-
}
34-
35-
if (room.t === 'd') {
36-
return userIds.filter((userId) => room.uids?.includes(userId));
37-
}
38-
39-
if (room.t === 'p' || room.t === 'c') {
40-
41-
const subscriptions = await Subscriptions.findByRoomIdAndUserIds(roomId, userIds, {
42-
projection: { u: 1 },
43-
}).toArray();
44-
45-
return subscriptions.map((sub) => sub.u._id);
46-
}
47-
48-
return [];
4944

50-
} catch (error) {
51-
console.error('Error filtering users in room:', { roomId, error });
52-
return [];
53-
}
54-
}
55-
5645
const room = await Rooms.findOneById(rid);
46+
5747
const [highlightsUids, threadFollowers] = await Promise.all([
5848
getUserIdsFromHighlights(rid, message),
5949
Messages.getThreadFollowsByThreadId(tmid),
6050
]);
61-
62-
51+
6352
const [followersInRoom, mentionIdsInRoom, highlightsUidsInRoom] = await Promise.all([
6453
filterUsersInRoom({ roomId: rid, userIds: followers, room }),
6554
filterUsersInRoom({ roomId: rid, userIds: mentionIds, room }),
66-
filterUsersInRoom({ roomId: rid, userIds: highlightsUids, room }), // ← Add here
67-
]);
55+
filterUsersInRoom({ roomId: rid, userIds: highlightsUids, room }),
56+
]);
6857

6958
const addToReplies = [
7059
...new Set([
@@ -76,14 +65,10 @@ export async function reply({ tmid }: { tmid?: string }, message: IMessage, pare
7665

7766
await Messages.updateRepliesByThreadId(tmid, addToReplies, ts);
7867

79-
80-
8168
const threadFollowersUids = threadFollowers?.filter((userId) => userId !== u._id && !mentionIdsInRoom.includes(userId)) || [];
8269

83-
// Notify everyone involved in the thread
8470
const notifyOptions = toAll || toHere ? { groupMention: true } : {};
8571

86-
// Notify message mentioned users and highlights
8772
const mentionedUsers = [...new Set([...mentionIdsInRoom, ...highlightsUidsInRoom])];
8873

8974
const promises = [

0 commit comments

Comments
 (0)