perform only create activities
This commit is contained in:
parent
ca0c673b44
commit
08e2b6ee32
3 changed files with 96 additions and 44 deletions
|
|
@ -86,11 +86,19 @@ export class ApInboxService {
|
|||
}
|
||||
|
||||
@bindThis
|
||||
public async performActivity(actor: RemoteUser, activity: IObject, limit = Infinity) {
|
||||
public async performActivity(actor: RemoteUser, activity: IObject, {
|
||||
limit = Infinity,
|
||||
allow = null as (string[] | null) } = {},
|
||||
): Promise<void> {
|
||||
if (isCollectionOrOrderedCollection(activity) || isOrderedCollectionPage(activity)) {
|
||||
const resolver = this.apResolverService.createResolver();
|
||||
for (const item of toArray(isCollection(activity) ? activity.items : activity.orderedItems).slice(0, limit)) {
|
||||
const act = await resolver.resolve(item);
|
||||
const type = getApType(act);
|
||||
if (allow && !allow.includes(type)) {
|
||||
this.logger.info(`skipping activity type: ${type}`);
|
||||
continue;
|
||||
}
|
||||
try {
|
||||
await this.performOneActivity(actor, act);
|
||||
} catch (err) {
|
||||
|
|
|
|||
|
|
@ -380,10 +380,10 @@ export class ApPersonService implements OnModuleInit {
|
|||
await this.usersRepository.update(user.id, { emojis: emojiNames });
|
||||
//#endregion
|
||||
|
||||
await Promise.all([
|
||||
this.updateFeatured(user.id, resolver),
|
||||
this.updateOutboxFirstPage(user, person.outbox, resolver),
|
||||
]).catch(err => this.logger.error(err));
|
||||
await Promise.allSettled([
|
||||
this.updateFeatured(user.id, resolver).catch(err => this.logger.error(err)),
|
||||
this.updateOutboxFirstPage(user, person.outbox, resolver).catch(err => this.logger.error(err)),
|
||||
]);
|
||||
|
||||
return user;
|
||||
}
|
||||
|
|
@ -587,33 +587,6 @@ export class ApPersonService implements OnModuleInit {
|
|||
return fields;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve outbox from an actor object.
|
||||
*
|
||||
* This only retrieves the first page for now.
|
||||
*/
|
||||
public async updateOutboxFirstPage(user: RemoteUser, outbox: IActor['outbox'], resolver: Resolver): Promise<void> {
|
||||
// https://www.w3.org/TR/activitypub/#actor-objects
|
||||
// Outbox is a required property for all actors
|
||||
if (!outbox) {
|
||||
throw new Error('No outbox property');
|
||||
}
|
||||
|
||||
this.logger.info(`Fetching the outbox for ${user.uri}: ${outbox}`);
|
||||
|
||||
const collection = await resolver.resolveCollection(outbox);
|
||||
if (!isOrderedCollection(collection)) {
|
||||
throw new Error('Outbox must be an ordered collection');
|
||||
}
|
||||
|
||||
const firstPage = collection.first ?
|
||||
await resolver.resolveOrderedCollectionPage(collection.first) :
|
||||
collection;
|
||||
|
||||
// Perform activity but only the first 20 ones
|
||||
await this.apInboxService.performActivity(user, firstPage, 20);
|
||||
}
|
||||
|
||||
@bindThis
|
||||
public async updateFeatured(userId: User['id'], resolver?: Resolver): Promise<void> {
|
||||
const user = await this.usersRepository.findOneByOrFail({ id: userId });
|
||||
|
|
@ -659,6 +632,33 @@ export class ApPersonService implements OnModuleInit {
|
|||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve outbox from an actor object.
|
||||
*
|
||||
* This only retrieves the first page for now.
|
||||
*/
|
||||
public async updateOutboxFirstPage(user: RemoteUser, outbox: IActor['outbox'], resolver: Resolver): Promise<void> {
|
||||
// https://www.w3.org/TR/activitypub/#actor-objects
|
||||
// Outbox is a required property for all actors
|
||||
if (!outbox) {
|
||||
throw new Error('No outbox property');
|
||||
}
|
||||
|
||||
this.logger.info(`Fetching the outbox for ${user.uri}: ${outbox}`);
|
||||
|
||||
const collection = await resolver.resolveCollection(outbox);
|
||||
if (!isOrderedCollection(collection)) {
|
||||
throw new Error('Outbox must be an ordered collection');
|
||||
}
|
||||
|
||||
const firstPage = collection.first ?
|
||||
await resolver.resolveOrderedCollectionPage(collection.first) :
|
||||
collection;
|
||||
|
||||
// Perform activity but only the first 20 ones with `type: Create`
|
||||
await this.apInboxService.performActivity(user, firstPage, { limit: 20, allow: ['Create'] });
|
||||
}
|
||||
|
||||
/**
|
||||
* リモート由来のアカウント移行処理を行います
|
||||
* @param src 移行元アカウント(リモートかつupdatePerson後である必要がある、というかこれ自体がupdatePersonで呼ばれる前提)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue