server: Use shared resolver in featured and question accept
Some checks failed
ci/woodpecker/push/build Pipeline was successful
ci/woodpecker/push/lint-client Pipeline was successful
ci/woodpecker/push/lint-backend Pipeline was successful
ci/woodpecker/push/lint-foundkey-js Pipeline was successful
ci/woodpecker/push/test Pipeline was successful
ci/woodpecker/pr/lint-backend Pipeline failed
ci/woodpecker/pr/build Pipeline was successful
ci/woodpecker/pr/test Pipeline failed
ci/woodpecker/pr/lint-foundkey-js Pipeline was successful
ci/woodpecker/pr/lint-client Pipeline failed

This commit is contained in:
Derek Schmidt 2022-12-01 00:46:37 -05:00 committed by Francis Dinh
parent d3af00a912
commit 11a6e706f4
Signed by: norm
GPG key ID: 7123E30E441E80DE
3 changed files with 8 additions and 7 deletions

View file

@ -26,7 +26,7 @@ export default async (actor: CacheableRemoteUser, activity: IUpdate): Promise<st
await updatePerson(actor.uri!, resolver, object);
return 'ok: Person updated';
} else if (getApType(object) === 'Question') {
await updateQuestion(object).catch(e => console.log(e));
await updateQuestion(object, resolver).catch(e => console.log(e));
return 'ok: Question updated';
} else {
return `skip: Unknown type: ${getApType(object)}`;

View file

@ -269,7 +269,7 @@ export async function createPerson(uri: string, resolver?: Resolver = new Resolv
});
//#endregion
await updateFeatured(user!.id).catch(err => logger.error(err));
await updateFeatured(user!.id, resolver).catch(err => logger.error(err));
return user!;
}
@ -380,7 +380,7 @@ export async function updatePerson(uri: string, resolver?: Resolver = new Resolv
followerSharedInbox: person.sharedInbox || (person.endpoints ? person.endpoints.sharedInbox : undefined),
});
await updateFeatured(exist.id).catch(err => logger.error(err));
await updateFeatured(exist.id, resolver).catch(err => logger.error(err));
}
/**
@ -458,14 +458,14 @@ export function analyzeAttachments(attachments: IObject | IObject[] | undefined)
return { fields, services };
}
export async function updateFeatured(userId: User['id']) {
export async function updateFeatured(userId: User['id'], resolver?: Resolver) {
const user = await Users.findOneByOrFail({ id: userId });
if (!Users.isRemoteUser(user)) return;
if (!user.featured) return;
logger.info(`Updating the featured: ${user.uri}`);
const resolver = new Resolver();
if (resolver == null) resolver = new Resolver();
// Resolve to (Ordered)Collection Object
const collection = await resolver.resolveCollection(user.featured);

View file

@ -36,9 +36,10 @@ export async function extractPollFromQuestion(source: string | IObject, resolver
/**
* Update votes of Question
* @param value AP Question object or its id
* @param resolver Resolver to use
* @returns true if updated
*/
export async function updateQuestion(value: string | IObject) {
export async function updateQuestion(value: string | IObject, resolver?: Resolver) {
const uri = typeof value === 'string' ? value : value.id;
// URIがこのサーバーを指しているならスキップ
@ -53,7 +54,7 @@ export async function updateQuestion(value: string | IObject) {
//#endregion
// resolve new Question object
const resolver = new Resolver();
if (resolver == null) resolver = new Resolver();
const question = await resolver.resolve(value) as IQuestion;
apLogger.debug(`fetched question: ${JSON.stringify(question, null, 2)}`);