From 667daebb79c09f7ab80f97e5d3dd30f5b5add4a5 Mon Sep 17 00:00:00 2001 From: Marie Date: Sun, 31 Dec 2023 03:48:51 +0100 Subject: [PATCH] upd: prevent vanilla mastodon imports from importing DMs Also adds the visibility function to mastodon imports --- .../src/queue/processors/ImportNotesProcessorService.ts | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/packages/backend/src/queue/processors/ImportNotesProcessorService.ts b/packages/backend/src/queue/processors/ImportNotesProcessorService.ts index 552b69d92d..942870dfc7 100644 --- a/packages/backend/src/queue/processors/ImportNotesProcessorService.ts +++ b/packages/backend/src/queue/processors/ImportNotesProcessorService.ts @@ -72,7 +72,6 @@ export class ImportNotesProcessorService { } } - // Function was taken from Firefish and modified for our needs @bindThis private async recreateChain(idFieldPath: string[], replyFieldPath: string[], arr: any[], includeOrphans: boolean): Promise { type NotesMap = { @@ -378,7 +377,11 @@ export class ImportNotesProcessorService { return; } - if (toot.directMessage) return; + const followers = toot.to.some((str: string) => str.includes('/followers')); + + if (toot.directMessage || (!toot.to.includes('https://www.w3.org/ns/activitystreams#Public') || !followers)) return; + + const visibility = followers ? 'home' : 'public'; const date = new Date(toot.object.published); let text = undefined; @@ -417,7 +420,7 @@ export class ImportNotesProcessorService { } } - const createdNote = await this.noteCreateService.import(user, { createdAt: date, text: text, files: files, apMentions: new Array(0), cw: toot.object.sensitive ? toot.object.summary : null, reply: reply }); + const createdNote = await this.noteCreateService.import(user, { createdAt: date, text: text, files: files, visibility: visibility, apMentions: new Array(0), cw: toot.object.sensitive ? toot.object.summary : null, reply: reply }); if (toot.childNotes) this.queueService.createImportMastoToDbJob(user, toot.childNotes, createdNote.id); }