AP Delate Activityの修正 (#6512)
This commit is contained in:
parent
6eff6ee451
commit
5f8fb43cc9
2 changed files with 42 additions and 12 deletions
|
@ -1,26 +1,48 @@
|
|||
import Resolver from '../../resolver';
|
||||
import deleteNote from './note';
|
||||
import { IRemoteUser } from '../../../../models/entities/user';
|
||||
import { IDelete, getApId, validPost } from '../../type';
|
||||
import { apLogger } from '../../logger';
|
||||
import { IDelete, getApId, isTombstone, IObject, validPost, validActor } from '../../type';
|
||||
import { toSingle } from '../../../../prelude/array';
|
||||
|
||||
/**
|
||||
* 削除アクティビティを捌きます
|
||||
*/
|
||||
export default async (actor: IRemoteUser, activity: IDelete): Promise<void> => {
|
||||
export default async (actor: IRemoteUser, activity: IDelete): Promise<string> => {
|
||||
if ('actor' in activity && actor.uri !== activity.actor) {
|
||||
throw new Error('invalid actor');
|
||||
}
|
||||
|
||||
const resolver = new Resolver();
|
||||
// 削除対象objectのtype
|
||||
let formarType: string | undefined;
|
||||
|
||||
const object = await resolver.resolve(activity.object);
|
||||
|
||||
const uri = getApId(object);
|
||||
|
||||
if (validPost.includes(object.type) || object.type === 'Tombstone') {
|
||||
deleteNote(actor, uri);
|
||||
if (typeof activity.object === 'string') {
|
||||
// typeが不明だけど、どうせ消えてるのでremote resolveしない
|
||||
formarType = undefined;
|
||||
} else {
|
||||
apLogger.warn(`Unknown type: ${object.type}`);
|
||||
const object = activity.object as IObject;
|
||||
if (isTombstone(object)) {
|
||||
formarType = toSingle(object.formerType);
|
||||
} else {
|
||||
formarType = toSingle(object.type);
|
||||
}
|
||||
}
|
||||
|
||||
const uri = getApId(activity.object);
|
||||
|
||||
// type不明でもactorとobjectが同じならばそれはPersonに違いない
|
||||
if (!formarType && actor.uri === uri) {
|
||||
formarType = 'Person';
|
||||
}
|
||||
|
||||
// それでもなかったらおそらくNote
|
||||
if (!formarType) {
|
||||
formarType = 'Note';
|
||||
}
|
||||
|
||||
if (validPost.includes(formarType)) {
|
||||
return await deleteNote(actor, uri);
|
||||
} else if (validActor.includes(formarType)) {
|
||||
return `Delete Actor is not implanted`;
|
||||
} else {
|
||||
return `Unknown type ${formarType}`;
|
||||
}
|
||||
};
|
||||
|
|
|
@ -119,6 +119,14 @@ interface IQuestionChoice {
|
|||
replies?: ICollection;
|
||||
_misskey_votes?: number;
|
||||
}
|
||||
export interface ITombstone extends IObject {
|
||||
type: 'Tombstone';
|
||||
formerType?: string;
|
||||
deleted?: Date;
|
||||
}
|
||||
|
||||
export const isTombstone = (object: IObject): object is ITombstone =>
|
||||
object.type === 'Tombstone';
|
||||
|
||||
export const validActor = ['Person', 'Service', 'Group', 'Organization', 'Application'];
|
||||
|
||||
|
|
Loading…
Reference in a new issue