Some checks failed
Create issues from TODOs / todos (push) Failing after 3s
Close inactive issues / close-issues (push) Has been cancelled
Deploy GitHub Pages / deploy-preview (push) Has been cancelled
CI / ⚙️ Variables Setup (push) Has been cancelled
CI / ⚙️ Test Guard (push) Has been cancelled
CI / 🚀 Notify external services - draft (push) Has been cancelled
CI / 📦 Build Packages (push) Has been cancelled
CI / 📦 Meteor Build (coverage) (push) Has been cancelled
CI / 📦 Meteor Build (production) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [account-service presence-service omnichannel-transcript-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [account-service presence-service omnichannel-transcript-service], fips) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [authorization-service queue-worker-service ddp-streamer-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [authorization-service queue-worker-service ddp-streamer-service], fips) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [rocketchat], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [rocketchat], coverage) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [rocketchat], fips) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [account-service presence-service omnichannel-transcript-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [authorization-service queue-worker-service ddp-streamer-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [rocketchat], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [rocketchat], coverage) (push) Has been cancelled
CI / 🚢 Publish Docker Images (ghcr.io) (push) Has been cancelled
CI / 📦 Track Image Sizes (push) Has been cancelled
CI / 🔎 Code Check - Action Lint (push) Has been cancelled
CI / 🔎 Code Check (push) Has been cancelled
CI / 🔨 Test Storybook (push) Has been cancelled
CI / 🔨 Test Unit (push) Has been cancelled
CI / 🔨 Test API (CE) (push) Has been cancelled
CI / 🔨 Test API Livechat (CE) (push) Has been cancelled
CI / 🔨 Test UI (CE) (push) Has been cancelled
CI / 🔨 Test API (EE) (push) Has been cancelled
CI / 🔨 Test API Livechat (EE) (push) Has been cancelled
CI / 🔨 Test API Apps (deno-runtime - EE) (push) Has been cancelled
CI / 🔨 Test UI (EE) (push) Has been cancelled
CI / 🔨 Test API (FIPS) (push) Has been cancelled
CI / 🔨 Test API Livechat (FIPS) (push) Has been cancelled
CI / 🔨 Test UI (FIPS) (push) Has been cancelled
CI / 🔨 Test Federation Matrix (push) Has been cancelled
CI / 📊 Report Coverage (push) Has been cancelled
CI / ✅ Tests Done (push) Has been cancelled
CI / 🚀 Publish build assets (push) Has been cancelled
CI / 🚀 Publish Docker Images (DockerHub) (push) Has been cancelled
CI / 🚀 Notify external services (push) Has been cancelled
CI / Update Version Durability (push) Has been cancelled
Release / Release (push) Has been cancelled
Auto-close duplicate issues / auto-close-duplicates (push) Failing after 1s
Code scanning - action / CodeQL-Build (push) Failing after 2s
98 lines
3.5 KiB
TypeScript
98 lines
3.5 KiB
TypeScript
import type { IMessage, IRoom, IUser } from '@rocket.chat/core-typings';
|
|
import { isEditedMessage } from '@rocket.chat/core-typings';
|
|
import { Messages, Subscriptions, NotificationQueue } from '@rocket.chat/models';
|
|
|
|
import { getMentions, getUserIdsFromHighlights } from '../../../hooks/messages/notifyUsersOnMessage';
|
|
import { callbacks } from '../../callbacks';
|
|
import { notifyOnSubscriptionChangedByRoomIdAndUserIds, notifyOnSubscriptionChangedByRoomIdAndUserId } from '../../notifyListener';
|
|
|
|
export async function reply({ tmid }: { tmid?: string }, message: IMessage, parentMessage: IMessage, followers: string[]) {
|
|
if (!tmid || isEditedMessage(message)) {
|
|
return false;
|
|
}
|
|
|
|
const { rid, ts, u } = message;
|
|
|
|
const { toAll, toHere, mentionIds } = await getMentions(message);
|
|
|
|
const addToReplies = [
|
|
...new Set([
|
|
...followers,
|
|
...mentionIds,
|
|
...(Array.isArray(parentMessage.replies) && parentMessage.replies.length ? [u._id] : [parentMessage.u._id, u._id]),
|
|
]),
|
|
];
|
|
|
|
await Messages.updateRepliesByThreadId(tmid, addToReplies, ts);
|
|
|
|
const [highlightsUids, threadFollowers] = await Promise.all([
|
|
getUserIdsFromHighlights(rid, message),
|
|
Messages.getThreadFollowsByThreadId(tmid),
|
|
]);
|
|
|
|
const threadFollowersUids = threadFollowers?.filter((userId) => userId !== u._id && !mentionIds.includes(userId)) || [];
|
|
|
|
// Notify everyone involved in the thread
|
|
const notifyOptions = toAll || toHere ? { groupMention: true } : {};
|
|
|
|
// Notify message mentioned users and highlights
|
|
const mentionedUsers = [...new Set([...mentionIds, ...highlightsUids])];
|
|
|
|
const promises = [Subscriptions.addUnreadThreadByRoomIdAndUserIds(rid, threadFollowersUids, tmid, notifyOptions)];
|
|
|
|
if (mentionedUsers.length) {
|
|
promises.push(Subscriptions.addUnreadThreadByRoomIdAndUserIds(rid, mentionedUsers, tmid, { userMention: true }));
|
|
}
|
|
|
|
if (highlightsUids.length) {
|
|
promises.push(
|
|
Subscriptions.setAlertForRoomIdAndUserIds(rid, highlightsUids),
|
|
Subscriptions.setOpenForRoomIdAndUserIds(rid, highlightsUids),
|
|
);
|
|
}
|
|
|
|
await Promise.allSettled(promises);
|
|
|
|
void notifyOnSubscriptionChangedByRoomIdAndUserIds(rid, [...threadFollowersUids, ...mentionedUsers, ...highlightsUids]);
|
|
}
|
|
|
|
export async function follow({ tmid, uid }: { tmid: string; uid: string }) {
|
|
if (!tmid || !uid) {
|
|
return false;
|
|
}
|
|
|
|
await Messages.addThreadFollowerByThreadId(tmid, uid);
|
|
}
|
|
|
|
export async function unfollow({ tmid, rid, uid }: { tmid: string; rid: string; uid: string }) {
|
|
if (!tmid || !uid) {
|
|
return false;
|
|
}
|
|
|
|
const removeUnreadThreadResponse = await Subscriptions.removeUnreadThreadByRoomIdAndUserId(rid, uid, tmid);
|
|
if (removeUnreadThreadResponse.modifiedCount) {
|
|
void notifyOnSubscriptionChangedByRoomIdAndUserId(rid, uid);
|
|
}
|
|
|
|
await Messages.removeThreadFollowerByThreadId(tmid, uid);
|
|
}
|
|
|
|
export const readThread = async ({ user, room, tmid }: { user: IUser; room: IRoom; tmid: string }) => {
|
|
const sub = await Subscriptions.findOneByRoomIdAndUserId(room._id, user._id, { projection: { tunread: 1 } });
|
|
if (!sub) {
|
|
return;
|
|
}
|
|
|
|
// if the thread being marked as read is the last one unread also clear the unread subscription flag
|
|
const clearAlert = sub.tunread && sub.tunread?.length <= 1 && sub.tunread.includes(tmid);
|
|
|
|
const removeUnreadThreadResponse = await Subscriptions.removeUnreadThreadByRoomIdAndUserId(room._id, user._id, tmid, clearAlert);
|
|
if (removeUnreadThreadResponse.modifiedCount) {
|
|
void notifyOnSubscriptionChangedByRoomIdAndUserId(room._id, user._id);
|
|
}
|
|
|
|
await NotificationQueue.clearQueueByUserId(user._id);
|
|
|
|
callbacks.runAsync('afterReadMessages', room, { uid: user._id, tmid });
|
|
};
|