Fix for CASCADE DELETE not being federated (#5812)
* Fix for CASCADE DELETE not being federated * Use JOIN to get user * fix typo
This commit is contained in:
parent
8755b5f353
commit
f40dcbfe13
2 changed files with 86 additions and 8 deletions
|
@ -20,11 +20,6 @@ import { deliverToFollowers } from '../../remote/activitypub/deliver-manager';
|
|||
export default async function(user: User, note: Note, quiet = false) {
|
||||
const deletedAt = new Date();
|
||||
|
||||
await Notes.delete({
|
||||
id: note.id,
|
||||
userId: user.id
|
||||
});
|
||||
|
||||
if (note.renoteId) {
|
||||
Notes.decrement({ id: note.renoteId }, 'renoteCount', 1);
|
||||
Notes.decrement({ id: note.renoteId }, 'score', 1);
|
||||
|
@ -39,6 +34,7 @@ export default async function(user: User, note: Note, quiet = false) {
|
|||
if (Users.isLocalUser(user)) {
|
||||
let renote: Note | undefined;
|
||||
|
||||
// if deletd note is renote
|
||||
if (note.renoteId && note.text == null && !note.hasPoll && (note.fileIds == null || note.fileIds.length == 0)) {
|
||||
renote = await Notes.findOne({
|
||||
id: note.renoteId
|
||||
|
@ -51,6 +47,15 @@ export default async function(user: User, note: Note, quiet = false) {
|
|||
|
||||
deliverToFollowers(user, content);
|
||||
}
|
||||
|
||||
// also deliever delete activity to cascaded notes
|
||||
const cascadingNotes = (await findCascadingNotes(note)).filter(note => !note.localOnly); // filter out local-only notes
|
||||
for (const cascadingNote of cascadingNotes) {
|
||||
if (!cascadingNote.user) continue;
|
||||
if (!Users.isLocalUser(cascadingNote.user)) continue;
|
||||
const content = renderActivity(renderDelete(renderTombstone(`${config.url}/notes/${cascadingNote.id}`), cascadingNote.user));
|
||||
deliverToFollowers(cascadingNote.user, content);
|
||||
}
|
||||
//#endregion
|
||||
|
||||
// 統計を更新
|
||||
|
@ -64,4 +69,27 @@ export default async function(user: User, note: Note, quiet = false) {
|
|||
});
|
||||
}
|
||||
}
|
||||
|
||||
await Notes.delete({
|
||||
id: note.id,
|
||||
userId: user.id
|
||||
});
|
||||
}
|
||||
|
||||
async function findCascadingNotes(note: Note) {
|
||||
const cascadingNotes: Note[] = [];
|
||||
|
||||
const recursive = async (noteId: string) => {
|
||||
const query = Notes.createQueryBuilder('note')
|
||||
.where('note.replyId = :noteId', { noteId })
|
||||
.leftJoinAndSelect('note.user', 'user');
|
||||
const replies = await query.getMany();
|
||||
for (const reply of replies) {
|
||||
cascadingNotes.push(reply);
|
||||
await recursive(reply.id);
|
||||
}
|
||||
};
|
||||
await recursive(note.id);
|
||||
|
||||
return cascadingNotes.filter(note => note.userHost === null); // filter out non-local users
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue