From 24bc1c653d47d674bfb2734d2859a1b26f79bcc5 Mon Sep 17 00:00:00 2001 From: Hazelnoot Date: Thu, 18 Sep 2025 14:16:30 -0400 Subject: [PATCH] fix DMs converting to public notes when the audience can't be resolved --- .../src/core/activitypub/ApAudienceService.ts | 13 +++++++++++++ .../src/core/activitypub/models/ApNoteService.ts | 14 ++++---------- 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/packages/backend/src/core/activitypub/ApAudienceService.ts b/packages/backend/src/core/activitypub/ApAudienceService.ts index 5a5a76f7d6..15c4546063 100644 --- a/packages/backend/src/core/activitypub/ApAudienceService.ts +++ b/packages/backend/src/core/activitypub/ApAudienceService.ts @@ -42,6 +42,19 @@ export class ApAudienceService { others.map(id => limit(() => this.apPersonService.resolvePerson(id, resolver).catch(() => null))), )).filter(x => x != null); + // If no audience is specified, then assume public + if ( + toGroups.public.length === 0 && toGroups.followers.length === 0 && + ccGroups.public.length === 0 && ccGroups.followers.length === 0 && + others.length === 0 + ) { + return { + visibility: 'public', + mentionedUsers: [], + visibleUsers: [], + }; + } + if (toGroups.public.length > 0) { return { visibility: 'public', diff --git a/packages/backend/src/core/activitypub/models/ApNoteService.ts b/packages/backend/src/core/activitypub/models/ApNoteService.ts index 32661fb6d9..b451cbe1dc 100644 --- a/packages/backend/src/core/activitypub/models/ApNoteService.ts +++ b/packages/backend/src/core/activitypub/models/ApNoteService.ts @@ -239,15 +239,12 @@ export class ApNoteService { } const noteAudience = await this.apAudienceService.parseAudience(actor, note.to, note.cc, resolver); - let visibility = noteAudience.visibility; + const visibility = noteAudience.visibility; const visibleUsers = noteAudience.visibleUsers; // Audience (to, cc) が指定されてなかった場合 if (visibility === 'specified' && visibleUsers.length === 0) { - if (typeof value === 'string') { // 入力がstringならばresolverでGETが発生している - // こちらから匿名GET出来たものならばpublic - visibility = 'public'; - } + throw new IdentifiableError('dc2ad0d1-36bf-41f5-8e4c-a4d265a28387', `failed to create note ${entryUri}: could not resolve any recipients`); } const processErrors: string[] = []; @@ -430,15 +427,12 @@ export class ApNoteService { //#endregion const noteAudience = await this.apAudienceService.parseAudience(actor, note.to, note.cc, resolver); - let visibility = noteAudience.visibility; + const visibility = noteAudience.visibility; const visibleUsers = noteAudience.visibleUsers; // Audience (to, cc) が指定されてなかった場合 if (visibility === 'specified' && visibleUsers.length === 0) { - if (typeof value === 'string') { // 入力がstringならばresolverでGETが発生している - // こちらから匿名GET出来たものならばpublic - visibility = 'public'; - } + throw new IdentifiableError('dc2ad0d1-36bf-41f5-8e4c-a4d265a28387', `failed to create note ${entryUri}: could not resolve any recipients`); } const processErrors: string[] = [];