From 1e348f6a7fdca2a05dd130e970860e9f00d76f7e Mon Sep 17 00:00:00 2001 From: naskya Date: Thu, 4 Jul 2024 02:58:10 +0900 Subject: [PATCH] chore: reduce code duplication --- .../src/queue/processors/db/import-masto-post.ts | 15 ++------------- .../backend/src/remote/activitypub/audience.ts | 4 ++-- 2 files changed, 4 insertions(+), 15 deletions(-) diff --git a/packages/backend/src/queue/processors/db/import-masto-post.ts b/packages/backend/src/queue/processors/db/import-masto-post.ts index f87c44e98e..54308b7e97 100644 --- a/packages/backend/src/queue/processors/db/import-masto-post.ts +++ b/packages/backend/src/queue/processors/db/import-masto-post.ts @@ -14,6 +14,7 @@ import promiseLimit from "promise-limit"; import { unique, concat } from "@/prelude/array.js"; import type { CacheableUser } from "@/models/entities/user.js"; import { resolvePerson } from "@/remote/activitypub/models/person.js"; +import { isPublic } from "@/remote/activitypub/audience.js"; const logger = queueLogger.createSubLogger("import-masto-post"); @@ -128,7 +129,7 @@ export async function importMastoPost( visibility = "public"; } else if (isPublic(post.cc)) { visibility = "home"; - } else if (isFollowers(post.cc)) { + } else if ((post.cc as string).endsWith("/followers")) { visibility = "followers"; } else { try { @@ -182,15 +183,3 @@ export async function importMastoPost( logger.info("Imported"); } - -function isPublic(id: string) { - return [ - "https://www.w3.org/ns/activitystreams#Public", - "as:Public", - "Public", - ].includes(id); -} - -function isFollowers(id: string) { - return id.endsWith("/followers"); -} diff --git a/packages/backend/src/remote/activitypub/audience.ts b/packages/backend/src/remote/activitypub/audience.ts index 9d840bc574..ec4ac6d317 100644 --- a/packages/backend/src/remote/activitypub/audience.ts +++ b/packages/backend/src/remote/activitypub/audience.ts @@ -90,7 +90,7 @@ function groupingAudience(ids: string[], actor: CacheableRemoteUser) { return groups; } -function isPublic(id: string) { +export function isPublic(id: string) { return [ "https://www.w3.org/ns/activitystreams#Public", "as:Public", @@ -98,6 +98,6 @@ function isPublic(id: string) { ].includes(id); } -function isFollowers(id: string, actor: CacheableRemoteUser) { +export function isFollowers(id: string, actor: CacheableRemoteUser) { return id === (actor.followersUri || `${actor.uri}/followers`); }