From f6cfa5cbb4b7a28f3fe2e1417d5ac0771f772e12 Mon Sep 17 00:00:00 2001 From: DW <36347199+chocological00@users.noreply.github.com> Date: Sat, 16 May 2020 11:49:46 -0400 Subject: [PATCH] Fix CASCADE-related problems (#6374) * Fix renotes remaining on remote when CASCADE is invoked * Fix CASCADE-invoked deletion not being federated to relays Co-authored-by: DW --- src/services/drive/delete-file.ts | 8 ++++++++ src/services/note/delete.ts | 6 ++++++ 2 files changed, 14 insertions(+) diff --git a/src/services/drive/delete-file.ts b/src/services/drive/delete-file.ts index 5f691bd6b4..f9141ebaac 100644 --- a/src/services/drive/delete-file.ts +++ b/src/services/drive/delete-file.ts @@ -12,6 +12,8 @@ import renderDelete from '../../remote/activitypub/renderer/delete'; import renderTombstone from '../../remote/activitypub/renderer/tombstone'; import config from '../../config'; import { deliverToFollowers } from '../../remote/activitypub/deliver-manager'; +import { Brackets } from 'typeorm'; +import { deliverToRelays } from '../relay'; export async function deleteFile(file: DriveFile, isExpired = false) { if (file.storedInternal) { @@ -95,11 +97,13 @@ async function postProcess(file: DriveFile, isExpired = false) { if (!Users.isLocalUser(cascadingNote.user)) continue; const content = renderActivity(renderDelete(renderTombstone(`${config.url}/notes/${cascadingNote.id}`), cascadingNote.user)); deliverToFollowers(cascadingNote.user, content); // federate delete msg + deliverToRelays(cascadingNote.user, content); } if (!relatedNote.user) continue; if (Users.isLocalUser(relatedNote.user)) { const content = renderActivity(renderDelete(renderTombstone(`${config.url}/notes/${relatedNote.id}`), relatedNote.user)); deliverToFollowers(relatedNote.user, content); + deliverToRelays(relatedNote.user, content); } } Notes.createQueryBuilder().delete() @@ -145,6 +149,10 @@ async function findCascadingNotes(note: Note) { const recursive = async (noteId: string) => { const query = Notes.createQueryBuilder('note') .where('note.replyId = :noteId', { noteId }) + .orWhere(new Brackets(q => { + q.where('note.renoteId = :noteId', { noteId }) + .andWhere('note.text IS NOT NULL'); + })) .leftJoinAndSelect('note.user', 'user'); const replies = await query.getMany(); for (const reply of replies) { diff --git a/src/services/note/delete.ts b/src/services/note/delete.ts index 11b52cd135..1972801ab7 100644 --- a/src/services/note/delete.ts +++ b/src/services/note/delete.ts @@ -13,6 +13,7 @@ import { notesChart, perUserNotesChart, instanceChart } from '../chart'; import { deliverToFollowers } from '../../remote/activitypub/deliver-manager'; import { countSameRenotes } from '../../misc/count-same-renotes'; import { deliverToRelays } from '../relay'; +import { Brackets } from 'typeorm'; /** * 投稿を削除します。 @@ -59,6 +60,7 @@ export default async function(user: User, note: Note, quiet = false) { if (!Users.isLocalUser(cascadingNote.user)) continue; const content = renderActivity(renderDelete(renderTombstone(`${config.url}/notes/${cascadingNote.id}`), cascadingNote.user)); deliverToFollowers(cascadingNote.user, content); + deliverToRelays(cascadingNote.user, content); } //#endregion @@ -86,6 +88,10 @@ async function findCascadingNotes(note: Note) { const recursive = async (noteId: string) => { const query = Notes.createQueryBuilder('note') .where('note.replyId = :noteId', { noteId }) + .orWhere(new Brackets(q => { + q.where('note.renoteId = :noteId', { noteId }) + .andWhere('note.text IS NOT NULL'); + })) .leftJoinAndSelect('note.user', 'user'); const replies = await query.getMany(); for (const reply of replies) {