mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-12-05 18:34:09 +00:00
fix(collab): a deleted chat message keeps no text
Deleting a message set the flag and kept the text in the row and in every backup; only the client hid it. The delete now blanks the text with the flag, and a migration clears what earlier deletes left. The row stays for the placeholder.
This commit is contained in:
+15
@@ -0,0 +1,15 @@
|
||||
import { Migration } from '@mikro-orm/migrations';
|
||||
|
||||
/**
|
||||
* A chat message deleted before this release kept its text in the row; only the
|
||||
* client hid it. Deleting now blanks the text with the flag
|
||||
* (`CollabMessagesRepository.softDelete`), and this clears what older deletes
|
||||
* left behind. The row itself stays for the "message deleted" placeholder.
|
||||
*/
|
||||
export class Migration20200101046370_a_deleted_chat_message_keeps_no_text extends Migration {
|
||||
override name = 'Migration20200101046370_a_deleted_chat_message_keeps_no_text';
|
||||
|
||||
override up(): void {
|
||||
this.addSql("UPDATE collab_messages SET text = '' WHERE deleted = 1 AND text != ''");
|
||||
}
|
||||
}
|
||||
@@ -179,9 +179,13 @@ export class CollabMessagesRepository extends TrekRepository<CollabMessages> {
|
||||
return await this.insert({ trip: trip_id, user: user_id, text, reply_to, origin });
|
||||
}
|
||||
|
||||
/** CB54 (`deleteMessage`, inside its transaction) — `UPDATE collab_messages SET deleted = 1 WHERE id = ?`, soft delete — the row survives for the placeholder. */
|
||||
/**
|
||||
* CB54 (`deleteMessage`, inside its transaction) — `UPDATE collab_messages SET deleted = 1, text = '' WHERE id = ?`,
|
||||
* soft delete: the row survives for the placeholder, its text does not, so a deleted message is gone from the
|
||||
* database and every backup made after it, not only hidden from the client.
|
||||
*/
|
||||
async softDelete(id: number): Promise<void> {
|
||||
await this.nativeUpdate({ id }, { deleted: 1 });
|
||||
await this.nativeUpdate({ id }, { deleted: 1, text: '' });
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
Reference in New Issue
Block a user