diff options
| author | anatawa12 <anatawa12@icloud.com> | 2025-07-15 09:20:48 +0900 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-07-15 09:20:48 +0900 |
| commit | 08cc5a99bb026a9e9f308254ae814f1b9a2f620d (patch) | |
| tree | cb2a7c94f29dcaf31ee0fce4fa74e5b3bb808c00 /packages/backend/src/core | |
| parent | Bump version to 2025.7.0-beta.1 (diff) | |
| download | misskey-08cc5a99bb026a9e9f308254ae814f1b9a2f620d.tar.gz misskey-08cc5a99bb026a9e9f308254ae814f1b9a2f620d.tar.bz2 misskey-08cc5a99bb026a9e9f308254ae814f1b9a2f620d.zip | |
Don't remove notes when reply / renote is removed (#16287)
* chore: make NO ACTION on channel/reply/renote removal
* chore(docs): add description to show a possibility of reply null with replyId non-null
* fix: packing NoteDraft fails when reply / renote is removed
* feat: show drafts targeting removed renote / reply as "削除された投稿への投稿"
Diffstat (limited to 'packages/backend/src/core')
| -rw-r--r-- | packages/backend/src/core/entities/NoteDraftEntityService.ts | 20 |
1 files changed, 16 insertions, 4 deletions
diff --git a/packages/backend/src/core/entities/NoteDraftEntityService.ts b/packages/backend/src/core/entities/NoteDraftEntityService.ts index 26455029d5..3ef8cdaa12 100644 --- a/packages/backend/src/core/entities/NoteDraftEntityService.ts +++ b/packages/backend/src/core/entities/NoteDraftEntityService.ts @@ -5,6 +5,7 @@ import { Inject, Injectable } from '@nestjs/common'; import { ModuleRef } from '@nestjs/core'; +import { EntityNotFoundError } from 'typeorm'; import { DI } from '@/di-symbols.js'; import type { Packed } from '@/misc/json-schema.js'; import { awaitAll } from '@/misc/prelude/await-all.js'; @@ -90,6 +91,17 @@ export class NoteDraftEntityService implements OnModuleInit { const packedFiles = options?._hint_?.packedFiles; const packedUsers = options?._hint_?.packedUsers; + async function nullIfEntityNotFound<T>(promise: Promise<T>): Promise<T | null> { + try { + return await promise; + } catch (err) { + if (err instanceof EntityNotFoundError) { + return null; + } + throw err; + } + } + const packed: Packed<'NoteDraft'> = await awaitAll({ id: noteDraft.id, createdAt: this.idService.parse(noteDraft.id).date.toISOString(), @@ -117,15 +129,15 @@ export class NoteDraftEntityService implements OnModuleInit { } : undefined, ...(opts.detail ? { - reply: noteDraft.replyId ? this.noteEntityService.pack(noteDraft.replyId, me, { + reply: noteDraft.replyId ? nullIfEntityNotFound(this.noteEntityService.pack(noteDraft.replyId, me, { detail: false, skipHide: opts.skipHide, - }) : undefined, + })) : undefined, - renote: noteDraft.renoteId ? this.noteEntityService.pack(noteDraft.renoteId, me, { + renote: noteDraft.renoteId ? nullIfEntityNotFound(this.noteEntityService.pack(noteDraft.renoteId, me, { detail: true, skipHide: opts.skipHide, - }) : undefined, + })) : undefined, poll: noteDraft.hasPoll ? { choices: noteDraft.pollChoices, |