chore: reduce code duplication
This commit is contained in:
parent
ee8679e239
commit
1e348f6a7f
2 changed files with 4 additions and 15 deletions
|
@ -14,6 +14,7 @@ import promiseLimit from "promise-limit";
|
||||||
import { unique, concat } from "@/prelude/array.js";
|
import { unique, concat } from "@/prelude/array.js";
|
||||||
import type { CacheableUser } from "@/models/entities/user.js";
|
import type { CacheableUser } from "@/models/entities/user.js";
|
||||||
import { resolvePerson } from "@/remote/activitypub/models/person.js";
|
import { resolvePerson } from "@/remote/activitypub/models/person.js";
|
||||||
|
import { isPublic } from "@/remote/activitypub/audience.js";
|
||||||
|
|
||||||
const logger = queueLogger.createSubLogger("import-masto-post");
|
const logger = queueLogger.createSubLogger("import-masto-post");
|
||||||
|
|
||||||
|
@ -128,7 +129,7 @@ export async function importMastoPost(
|
||||||
visibility = "public";
|
visibility = "public";
|
||||||
} else if (isPublic(post.cc)) {
|
} else if (isPublic(post.cc)) {
|
||||||
visibility = "home";
|
visibility = "home";
|
||||||
} else if (isFollowers(post.cc)) {
|
} else if ((post.cc as string).endsWith("/followers")) {
|
||||||
visibility = "followers";
|
visibility = "followers";
|
||||||
} else {
|
} else {
|
||||||
try {
|
try {
|
||||||
|
@ -182,15 +183,3 @@ export async function importMastoPost(
|
||||||
|
|
||||||
logger.info("Imported");
|
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");
|
|
||||||
}
|
|
||||||
|
|
|
@ -90,7 +90,7 @@ function groupingAudience(ids: string[], actor: CacheableRemoteUser) {
|
||||||
return groups;
|
return groups;
|
||||||
}
|
}
|
||||||
|
|
||||||
function isPublic(id: string) {
|
export function isPublic(id: string) {
|
||||||
return [
|
return [
|
||||||
"https://www.w3.org/ns/activitystreams#Public",
|
"https://www.w3.org/ns/activitystreams#Public",
|
||||||
"as:Public",
|
"as:Public",
|
||||||
|
@ -98,6 +98,6 @@ function isPublic(id: string) {
|
||||||
].includes(id);
|
].includes(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
function isFollowers(id: string, actor: CacheableRemoteUser) {
|
export function isFollowers(id: string, actor: CacheableRemoteUser) {
|
||||||
return id === (actor.followersUri || `${actor.uri}/followers`);
|
return id === (actor.followersUri || `${actor.uri}/followers`);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue