Merge branch 'Marie-develop-patch-33974' into 'develop'

feat: Fetch total posts of users on create/update

Closes #10652

See merge request firefish/firefish!10558
This commit is contained in:
Kainoa Kanter 2023-08-12 01:00:29 +00:00
commit c4018c969c

View File

@ -231,6 +231,21 @@ export async function createPerson(
}
}
let notesCount: number | undefined;
if (typeof person.outbox === "string") {
try {
let data = await fetch(person.outbox, {
headers: { Accept: "application/json" },
});
let json_data = JSON.parse(await data.text());
notesCount = json_data.totalItems;
} catch (e) {
notesCount = undefined;
}
}
// Create user
let user: IRemoteUser;
try {
@ -274,6 +289,14 @@ export async function createPerson(
isCollectionOrOrderedCollection(person.following)
? person.following.totalItems
: undefined,
notesCount:
notesCount !== undefined
? notesCount
: person.outbox &&
typeof person.outbox !== "string" &&
isCollectionOrOrderedCollection(person.outbox)
? person.outbox.totalItems
: undefined,
featured: person.featured ? getApId(person.featured) : undefined,
uri: person.id,
tags,
@ -472,6 +495,21 @@ export async function updatePerson(
}
}
let notesCount: number | undefined;
if (typeof person.outbox === "string") {
try {
let data = await fetch(person.outbox, {
headers: { Accept: "application/json" },
});
let json_data = JSON.parse(await data.text());
notesCount = json_data.totalItems;
} catch (e) {
notesCount = undefined;
}
}
const updates = {
lastFetchedAt: new Date(),
inbox: person.inbox,
@ -495,6 +533,14 @@ export async function updatePerson(
isCollectionOrOrderedCollection(person.following)
? person.following.totalItems
: undefined,
notesCount:
notesCount !== undefined
? notesCount
: person.outbox &&
typeof person.outbox !== "string" &&
isCollectionOrOrderedCollection(person.outbox)
? person.outbox.totalItems
: undefined,
featured: person.featured,
emojis: emojiNames,
name: truncate(person.name, nameLength),
@ -663,7 +709,7 @@ export async function updateFeatured(userId: User["id"], resolver?: Resolver) {
? collection.items
: collection.orderedItems;
const items = await Promise.all(
toArray(unresolvedItems).map((x) => resolver.resolve(x)),
toArray(unresolvedItems).map((x) => resolver?.resolve(x)),
);
// Resolve and regist Notes