From 85a68a5eee14b8e638d2f9fabacf5ea3f2298cdf Mon Sep 17 00:00:00 2001 From: Johann150 Date: Sat, 4 Feb 2023 00:13:43 +0100 Subject: [PATCH] activitypub: properly render CW only quotes Changelog: Fixed --- packages/backend/src/misc/renote.ts | 3 ++- packages/backend/src/server/activitypub/outbox.ts | 2 +- packages/backend/src/services/note/create.ts | 15 +++------------ 3 files changed, 6 insertions(+), 14 deletions(-) diff --git a/packages/backend/src/misc/renote.ts b/packages/backend/src/misc/renote.ts index cd51cd04a..5b2657633 100644 --- a/packages/backend/src/misc/renote.ts +++ b/packages/backend/src/misc/renote.ts @@ -1,8 +1,9 @@ import { Note } from '@/models/entities/note.js'; -export function isPureRenote(note: Note): note is Note & { renoteId: string, text: null, fileIds: null | never[], hasPoll: false } { +export function isPureRenote(note: Note): note is Note & { renoteId: string, text: null, cw: null, fileIds: null | never[], hasPoll: false } { return note.renoteId != null && note.text == null + && note.cw == null && ( note.fileIds == null || note.fileIds.length === 0 diff --git a/packages/backend/src/server/activitypub/outbox.ts b/packages/backend/src/server/activitypub/outbox.ts index 60e2ab711..d517ffcfe 100644 --- a/packages/backend/src/server/activitypub/outbox.ts +++ b/packages/backend/src/server/activitypub/outbox.ts @@ -102,7 +102,7 @@ export default async (ctx: Router.RouterContext) => { export async function packActivity(note: Note): Promise { if (isPureRenote(note)) { const renote = await Notes.findOneByOrFail({ id: note.renoteId }); - return renderAnnounce(renote.uri ? renote.uri : `${config.url}/notes/${renote.id}`, note); + return renderAnnounce(renote.uri ?? `${config.url}/notes/${renote.id}`, note); } else { return renderCreate(await renderNote(note, false), note); } diff --git a/packages/backend/src/services/note/create.ts b/packages/backend/src/services/note/create.ts index 67f5e0d57..04b4a22a5 100644 --- a/packages/backend/src/services/note/create.ts +++ b/packages/backend/src/services/note/create.ts @@ -36,6 +36,7 @@ import { Cache } from '@/misc/cache.js'; import { UserProfile } from '@/models/entities/user-profile.js'; import { getActiveWebhooks } from '@/misc/webhook-cache.js'; import { IActivity } from '@/remote/activitypub/type.js'; +import { packActivity } from '@/server/activitypub/outbox.js'; import { MINUTE } from '@/const.js'; import { updateHashtags } from '../update-hashtag.js'; import { registerOrFetchInstanceDoc } from '../register-or-fetch-instance-doc.js'; @@ -428,9 +429,9 @@ export default async (user: { id: User['id']; username: User['username']; host: }); //#region AP deliver - if (Users.isLocalUser(user)) { + if (Users.isLocalUser(user) && !data.localOnly) { (async () => { - const noteActivity = await renderNoteOrRenoteActivity(data, note); + const noteActivity = renderActivity(await packActivity(note)); const dm = new DeliverManager(user, noteActivity); // Delivered to remote users who have been mentioned @@ -487,16 +488,6 @@ export default async (user: { id: User['id']; username: User['username']; host: index(note); }); -async function renderNoteOrRenoteActivity(data: Option, note: Note): Promise { - if (data.localOnly) return null; - - const content = data.renote && data.text == null && data.poll == null && (data.files == null || data.files.length === 0) - ? renderAnnounce(data.renote.uri ? data.renote.uri : `${config.url}/notes/${data.renote.id}`, note) - : renderCreate(await renderNote(note, false), note); - - return renderActivity(content); -} - function incRenoteCount(renote: Note): void { Notes.createQueryBuilder().update() .set({