diff --git a/src/remote/activitypub/kernel/undo/announce.ts b/src/remote/activitypub/kernel/undo/announce.ts index 04cd2b411067..53266bd4a17c 100644 --- a/src/remote/activitypub/kernel/undo/announce.ts +++ b/src/remote/activitypub/kernel/undo/announce.ts @@ -1,48 +1,18 @@ -import * as mongo from 'mongodb'; import { IRemoteUser } from '../../../../models/user'; import { IAnnounce, getApId } from '../../type'; import deleteNote from '../../../../services/note/delete'; -import Note, { INote } from '../../../../models/note'; -import { isSelfOrigin } from '../../../../misc/convert-host'; +import Note from '../../../../models/note'; export const undoAnnounce = async (actor: IRemoteUser, activity: IAnnounce): Promise => { - const targetUri = getApId(activity.object); + const uri = getApId(activity); - let note: INote | undefined; + const note = await Note.findOne({ + uri + }); - if (isSelfOrigin(targetUri)) { - // 対象がローカルの場合 - const id = new mongo.ObjectID(targetUri.split('/').pop()); - note = await Note.findOne({ - userId: actor._id, - renoteId: id, - deletedAt: { $exists: false } - }); - - if (!note) { - return `skip: target renote is not found`; - } - } else { - // 対象がリモートの場合 - const targetNote = await Note.findOne({ - uri: targetUri - }); - - if (!targetNote) { - return `skip: target note is not found`; - } - - note = await Note.findOne({ - userId: actor._id, - renoteId: targetNote._id, - deletedAt: { $exists: false } - }); - - if (!note) { - return `skip: target renote is not found`; - } - } + if (!note) return 'skip: no such Announce'; await deleteNote(actor, note); - return `ok`; + + return 'ok: deleted'; };