mirror of
https://github.com/paricafe/misskey.git
synced 2025-01-19 02:18:40 -06:00
backend: fix ApInboxService
This commit is contained in:
parent
fc2f68f1d6
commit
9263c485c4
1 changed files with 30 additions and 23 deletions
|
@ -5,6 +5,7 @@
|
||||||
|
|
||||||
import { Inject, Injectable } from '@nestjs/common';
|
import { Inject, Injectable } from '@nestjs/common';
|
||||||
import { In } from 'typeorm';
|
import { In } from 'typeorm';
|
||||||
|
import * as Bull from 'bullmq';
|
||||||
import { DI } from '@/di-symbols.js';
|
import { DI } from '@/di-symbols.js';
|
||||||
import type { Config } from '@/config.js';
|
import type { Config } from '@/config.js';
|
||||||
import { UserFollowingService } from '@/core/UserFollowingService.js';
|
import { UserFollowingService } from '@/core/UserFollowingService.js';
|
||||||
|
@ -38,6 +39,7 @@ import { ApPersonService } from './models/ApPersonService.js';
|
||||||
import { ApQuestionService } from './models/ApQuestionService.js';
|
import { ApQuestionService } from './models/ApQuestionService.js';
|
||||||
import type { Resolver } from './ApResolverService.js';
|
import type { Resolver } from './ApResolverService.js';
|
||||||
import type { IAccept, IAdd, IAnnounce, IBlock, ICreate, IDelete, IFlag, IFollow, ILike, IObject, IReject, IRemove, IUndo, IUpdate, IMove, IPost } from './type.js';
|
import type { IAccept, IAdd, IAnnounce, IBlock, ICreate, IDelete, IFlag, IFollow, ILike, IObject, IReject, IRemove, IUndo, IUpdate, IMove, IPost } from './type.js';
|
||||||
|
import { fromTuple } from '@/misc/from-tuple.js';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class ApInboxService {
|
export class ApInboxService {
|
||||||
|
@ -84,6 +86,7 @@ export class ApInboxService {
|
||||||
private apQuestionService: ApQuestionService,
|
private apQuestionService: ApQuestionService,
|
||||||
private queueService: QueueService,
|
private queueService: QueueService,
|
||||||
private globalEventService: GlobalEventService,
|
private globalEventService: GlobalEventService,
|
||||||
|
private federatedInstanceService: FederatedInstanceService,
|
||||||
) {
|
) {
|
||||||
this.logger = this.apLoggerService.logger;
|
this.logger = this.apLoggerService.logger;
|
||||||
}
|
}
|
||||||
|
@ -251,7 +254,8 @@ export class ApInboxService {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (activity.target === actor.featured) {
|
if (activity.target === actor.featured) {
|
||||||
const note = await this.apNoteService.resolveNote(activity.object);
|
const object = fromTuple(activity.object);
|
||||||
|
const note = await this.apNoteService.resolveNote(object);
|
||||||
if (note == null) return 'note not found';
|
if (note == null) return 'note not found';
|
||||||
await this.notePiningService.addPinned(actor, note.id);
|
await this.notePiningService.addPinned(actor, note.id);
|
||||||
return;
|
return;
|
||||||
|
@ -268,11 +272,12 @@ export class ApInboxService {
|
||||||
|
|
||||||
const resolver = this.apResolverService.createResolver();
|
const resolver = this.apResolverService.createResolver();
|
||||||
|
|
||||||
if (!activity.object) return 'skip: activity has no object property';
|
const activityObject = fromTuple(activity.object);
|
||||||
const targetUri = getApId(activity.object);
|
if (!activityObject) return 'skip: activity has no object property';
|
||||||
|
const targetUri = getApId(activityObject);
|
||||||
if (targetUri.startsWith('bear:')) return 'skip: bearcaps url not supported.';
|
if (targetUri.startsWith('bear:')) return 'skip: bearcaps url not supported.';
|
||||||
|
|
||||||
const target = await resolver.resolve(activity.object).catch(e => {
|
const target = await resolver.resolve(activityObject).catch(e => {
|
||||||
this.logger.error(`Resolution failed: ${e}`);
|
this.logger.error(`Resolution failed: ${e}`);
|
||||||
return e;
|
return e;
|
||||||
});
|
});
|
||||||
|
@ -367,29 +372,30 @@ export class ApInboxService {
|
||||||
|
|
||||||
this.logger.info(`Create: ${uri}`);
|
this.logger.info(`Create: ${uri}`);
|
||||||
|
|
||||||
if (!activity.object) return 'skip: activity has no object property';
|
const activityObject = fromTuple(activity.object);
|
||||||
const targetUri = getApId(activity.object);
|
if (!activityObject) return 'skip: activity has no object property';
|
||||||
|
const targetUri = getApId(activityObject);
|
||||||
if (targetUri.startsWith('bear:')) return 'skip: bearcaps url not supported.';
|
if (targetUri.startsWith('bear:')) return 'skip: bearcaps url not supported.';
|
||||||
|
|
||||||
// copy audiences between activity <=> object.
|
// copy audiences between activity <=> object.
|
||||||
if (typeof activity.object === 'object') {
|
if (typeof activityObject === 'object') {
|
||||||
const to = unique(concat([toArray(activity.to), toArray(activity.object.to)]));
|
const to = unique(concat([toArray(activity.to), toArray(activityObject.to)]));
|
||||||
const cc = unique(concat([toArray(activity.cc), toArray(activity.object.cc)]));
|
const cc = unique(concat([toArray(activity.cc), toArray(activityObject.cc)]));
|
||||||
|
|
||||||
activity.to = to;
|
activity.to = to;
|
||||||
activity.cc = cc;
|
activity.cc = cc;
|
||||||
activity.object.to = to;
|
activityObject.to = to;
|
||||||
activity.object.cc = cc;
|
activityObject.cc = cc;
|
||||||
}
|
}
|
||||||
|
|
||||||
// If there is no attributedTo, use Activity actor.
|
// If there is no attributedTo, use Activity actor.
|
||||||
if (typeof activity.object === 'object' && !activity.object.attributedTo) {
|
if (typeof activityObject === 'object' && !activityObject.attributedTo) {
|
||||||
activity.object.attributedTo = activity.actor;
|
activityObject.attributedTo = activity.actor;
|
||||||
}
|
}
|
||||||
|
|
||||||
const resolver = this.apResolverService.createResolver();
|
const resolver = this.apResolverService.createResolver();
|
||||||
|
|
||||||
const object = await resolver.resolve(activity.object).catch(e => {
|
const object = await resolver.resolve(activityObject).catch(e => {
|
||||||
this.logger.error(`Resolution failed: ${e}`);
|
this.logger.error(`Resolution failed: ${e}`);
|
||||||
throw e;
|
throw e;
|
||||||
});
|
});
|
||||||
|
@ -445,15 +451,15 @@ export class ApInboxService {
|
||||||
// 削除対象objectのtype
|
// 削除対象objectのtype
|
||||||
let formerType: string | undefined;
|
let formerType: string | undefined;
|
||||||
|
|
||||||
if (typeof activity.object === 'string') {
|
const activityObject = fromTuple(activity.object);
|
||||||
|
if (typeof activityObject === 'string') {
|
||||||
// typeが不明だけど、どうせ消えてるのでremote resolveしない
|
// typeが不明だけど、どうせ消えてるのでremote resolveしない
|
||||||
formerType = undefined;
|
formerType = undefined;
|
||||||
} else {
|
} else {
|
||||||
const object = activity.object;
|
if (isTombstone(activityObject)) {
|
||||||
if (isTombstone(object)) {
|
formerType = toSingle(activityObject.formerType);
|
||||||
formerType = toSingle(object.formerType);
|
|
||||||
} else {
|
} else {
|
||||||
formerType = toSingle(object.type);
|
formerType = toSingle(activityObject.type);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -607,7 +613,8 @@ export class ApInboxService {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (activity.target === actor.featured) {
|
if (activity.target === actor.featured) {
|
||||||
const note = await this.apNoteService.resolveNote(activity.object);
|
const activityObject = fromTuple(activity.object);
|
||||||
|
const note = await this.apNoteService.resolveNote(activityObject);
|
||||||
if (note == null) return 'note not found';
|
if (note == null) return 'note not found';
|
||||||
await this.notePiningService.removePinned(actor, note.id);
|
await this.notePiningService.removePinned(actor, note.id);
|
||||||
return;
|
return;
|
||||||
|
@ -770,9 +777,9 @@ export class ApInboxService {
|
||||||
} else if (getApType(object) === 'Question') {
|
} else if (getApType(object) === 'Question') {
|
||||||
await this.apQuestionService.updateQuestion(object, resolver).catch(err => console.error(err));
|
await this.apQuestionService.updateQuestion(object, resolver).catch(err => console.error(err));
|
||||||
return 'ok: Question updated';
|
return 'ok: Question updated';
|
||||||
} else if (isPost(object)) {
|
} else if (getApType(object) === 'Note') {
|
||||||
await this.apNoteService.updateNote(object, resolver);
|
await this.apNoteService.updateNote(object, resolver).catch(err => console.error(err));
|
||||||
return 'ok: Post updated';
|
return 'ok: Note updated';
|
||||||
} else {
|
} else {
|
||||||
return `skip: Unknown type: ${getApType(object)}`;
|
return `skip: Unknown type: ${getApType(object)}`;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue