snapshot of https://github.com/RocketChat/Rocket.Chat.git (develop, 2026-09-16; blobs > 131072B omitted)
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 1s
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 1s
This commit is contained in:
108
apps/meteor/server/lib/messages/updateMessage.ts
Normal file
108
apps/meteor/server/lib/messages/updateMessage.ts
Normal file
@@ -0,0 +1,108 @@
|
||||
import { AppEvents, Apps } from '@rocket.chat/apps';
|
||||
import { Message } from '@rocket.chat/core-services';
|
||||
import type { IMessage, IUser, AtLeast } from '@rocket.chat/core-typings';
|
||||
import { Messages, Rooms } from '@rocket.chat/models';
|
||||
import { Meteor } from 'meteor/meteor';
|
||||
|
||||
import { afterSaveMessage } from '../../hooks/messages/afterSaveMessage';
|
||||
import { settings } from '../../settings';
|
||||
import { validateCustomMessageFields } from '../messaging/validateCustomMessageFields';
|
||||
import { notifyOnRoomChangedById } from '../notifyListener';
|
||||
|
||||
export const updateMessage = async function (
|
||||
{
|
||||
parseUrls,
|
||||
...message
|
||||
}: (AtLeast<IMessage, '_id' | 'rid' | 'msg' | 'customFields'> | AtLeast<IMessage, '_id' | 'rid' | 'content'>) & {
|
||||
parseUrls?: boolean;
|
||||
},
|
||||
user: IUser,
|
||||
originalMsg?: IMessage,
|
||||
previewUrls?: string[],
|
||||
): Promise<void> {
|
||||
const originalMessage = originalMsg || (await Messages.findOneById(message._id));
|
||||
if (!originalMessage) {
|
||||
throw new Error('Invalid message ID.');
|
||||
}
|
||||
|
||||
let messageData: IMessage = Object.assign({}, originalMessage, message);
|
||||
|
||||
// For the Rocket.Chat Apps :)
|
||||
if (message && Apps.self && Apps.isLoaded()) {
|
||||
const prevent = await Apps.self?.triggerEvent(AppEvents.IPreMessageUpdatedPrevent, messageData);
|
||||
if (prevent) {
|
||||
throw new Meteor.Error('error-app-prevented-updating', 'A Rocket.Chat App prevented the message updating.');
|
||||
}
|
||||
|
||||
let result = await Apps.self?.triggerEvent(AppEvents.IPreMessageUpdatedExtend, messageData);
|
||||
result = await Apps.self?.triggerEvent(AppEvents.IPreMessageUpdatedModify, result);
|
||||
|
||||
if (typeof result === 'object') {
|
||||
Object.assign(messageData, result);
|
||||
}
|
||||
}
|
||||
|
||||
// If we keep history of edits, insert a new message to store history information
|
||||
if (settings.get('Message_KeepHistory')) {
|
||||
await Messages.cloneAndSaveAsHistoryById(messageData._id, user as Required<Pick<IUser, '_id' | 'username' | 'name'>>);
|
||||
}
|
||||
|
||||
Object.assign(messageData, {
|
||||
editedAt: new Date(),
|
||||
editedBy: {
|
||||
_id: user._id,
|
||||
username: user.username,
|
||||
},
|
||||
});
|
||||
|
||||
const room = await Rooms.findOneById(messageData.rid);
|
||||
if (!room) {
|
||||
return;
|
||||
}
|
||||
|
||||
messageData = await Message.beforeSave({ message: messageData, room, user, previewUrls, parseUrls });
|
||||
|
||||
if (messageData.customFields) {
|
||||
validateCustomMessageFields({
|
||||
customFields: messageData.customFields,
|
||||
messageCustomFieldsEnabled: settings.get<boolean>('Message_CustomFields_Enabled'),
|
||||
messageCustomFields: settings.get<string>('Message_CustomFields'),
|
||||
});
|
||||
}
|
||||
|
||||
const { _id, ...editedMessage } = messageData;
|
||||
|
||||
if (!editedMessage.msg) {
|
||||
delete editedMessage.md;
|
||||
}
|
||||
|
||||
// do not send $unset if not defined. Can cause exceptions in certain mongo versions.
|
||||
await Messages.updateOne(
|
||||
{ _id },
|
||||
{
|
||||
$set: {
|
||||
...editedMessage,
|
||||
},
|
||||
...(!editedMessage.md && { $unset: { md: 1 } }),
|
||||
},
|
||||
);
|
||||
|
||||
if (Apps.self?.isLoaded()) {
|
||||
// This returns a promise, but it won't mutate anything about the message
|
||||
// so, we don't really care if it is successful or fails
|
||||
void Apps.self?.triggerEvent(AppEvents.IPostMessageUpdated, messageData);
|
||||
}
|
||||
|
||||
setImmediate(async () => {
|
||||
const msg = await Messages.findOneById(_id);
|
||||
if (!msg) {
|
||||
return;
|
||||
}
|
||||
|
||||
await afterSaveMessage(msg, room, user);
|
||||
|
||||
if (room?.lastMessage?._id === msg._id) {
|
||||
void notifyOnRoomChangedById(message.rid);
|
||||
}
|
||||
});
|
||||
};
|
||||
Reference in New Issue
Block a user