diff --git a/packages/backend/src/remote/activitypub/models/person.ts b/packages/backend/src/remote/activitypub/models/person.ts index 73743bec7..fef04d593 100644 --- a/packages/backend/src/remote/activitypub/models/person.ts +++ b/packages/backend/src/remote/activitypub/models/person.ts @@ -48,7 +48,11 @@ import Resolver from "../resolver.js"; import { extractApHashtags } from "./tag.js"; import { resolveNote, extractEmojis } from "./note.js"; import { resolveImage } from "./image.js"; -import { getSubjectHostFromUri, getSubjectHostFromRemoteUser } from "@/remote/resolve-user.js" +import { + getSubjectHostFromUri, + getSubjectHostFromRemoteUser, + getSubjectHostFromAcctParts +} from "@/remote/resolve-user.js" const logger = apLogger; @@ -185,10 +189,12 @@ export async function createPerson( logger.info(`Creating the Person: ${person.id}`); - const host = subjectHost ?? await getSubjectHostFromUri(object.id) ?? toPuny(new URL(object.id).hostname); - const usernameLower = person.preferredUsername?.toLowerCase(); + const urlHostname = toPuny(new URL(object.id).hostname); + + const host = subjectHost ?? await getSubjectHostFromUri(object.id) ?? await getSubjectHostFromAcctParts(usernameLower, urlHostname) ?? urlHostname; + if (usernameLower !== null) { let checkUser = (await Users.findOneBy({ usernameLower: usernameLower, diff --git a/packages/backend/src/remote/resolve-user.ts b/packages/backend/src/remote/resolve-user.ts index b9edbd560..f6d6b2dfe 100644 --- a/packages/backend/src/remote/resolve-user.ts +++ b/packages/backend/src/remote/resolve-user.ts @@ -207,6 +207,10 @@ export async function getSubjectHostFromRemoteUser(user: IRemoteUser | undefined return user ? getSubjectHostFromAcct(`${user.username}@${user.host}`) : null; } +export async function getSubjectHostFromAcctParts(username?: string | undefined, host?: string | undefined): Promise { + return username !== null && host !== null ? getSubjectHostFromAcct(`${username}@${host}`) : null; +} + async function resolveUserWebFinger(acctLower: string, recurse: boolean = true): Promise<{ subject: string, self: {