From 61e31aa04f216eba9d8f0b9ac2625fa2638bf1b0 Mon Sep 17 00:00:00 2001 From: Kevin Aleman Date: Mon, 20 May 2024 09:20:02 -0600 Subject: [PATCH] fix: Bypass trash when removing OTR system messages and read receipts (#32269) --- .changeset/weak-turkeys-sit.md | 8 ++++++++ apps/meteor/ee/server/models/raw/ReadReceipts.ts | 2 +- apps/meteor/server/models/raw/Messages.ts | 2 +- 3 files changed, 10 insertions(+), 2 deletions(-) create mode 100644 .changeset/weak-turkeys-sit.md diff --git a/.changeset/weak-turkeys-sit.md b/.changeset/weak-turkeys-sit.md new file mode 100644 index 000000000000..c4673b9d049d --- /dev/null +++ b/.changeset/weak-turkeys-sit.md @@ -0,0 +1,8 @@ +--- +"@rocket.chat/meteor": patch +--- + +Fixed a bad behavior with the interaction between OTR system messages & trash collection. We use trash collection as a temporary storage that holds recently deleted items from some collections. Messages is one of those. This was causing "User joined OTR" messages to be viewable when querying the trash collection. +Since OTR messages are by definition private, code was updated to bypass trash collection when removing these special messages. + +Note: this only applies to these system messages. OTR user's messages are not stored on the database. diff --git a/apps/meteor/ee/server/models/raw/ReadReceipts.ts b/apps/meteor/ee/server/models/raw/ReadReceipts.ts index f3a08d4de8ca..cf0dd7283f31 100644 --- a/apps/meteor/ee/server/models/raw/ReadReceipts.ts +++ b/apps/meteor/ee/server/models/raw/ReadReceipts.ts @@ -51,7 +51,7 @@ export class ReadReceiptsRaw extends BaseRaw implements IReadReceip }, ts: { $lte: until }, }; - return this.deleteMany(query); + return this.col.deleteMany(query); } async removeByIdPinnedTimestampLimitAndUsers( diff --git a/apps/meteor/server/models/raw/Messages.ts b/apps/meteor/server/models/raw/Messages.ts index 0bd25dca4620..9f9ff7882d32 100644 --- a/apps/meteor/server/models/raw/Messages.ts +++ b/apps/meteor/server/models/raw/Messages.ts @@ -673,7 +673,7 @@ export class MessagesRaw extends BaseRaw implements IMessagesModel { }, ts: { $lte: ts }, }; - return this.deleteMany(query); + return this.col.deleteMany(query); } addTranslations(messageId: string, translations: Record, providerName: string): Promise {