From c033464b924a91c8e80bd8a315153037450dcf96 Mon Sep 17 00:00:00 2001 From: MeiMei <30769358+mei23@users.noreply.github.com> Date: Sun, 8 Sep 2019 11:30:44 +0900 Subject: [PATCH] AP Undo Announce (#5400) * AP Undo Announce * Use activity id --- src/remote/activitypub/kernel/undo/announce.ts | 16 ++++++++++++++++ src/remote/activitypub/kernel/undo/index.ts | 6 +++++- src/services/note/delete.ts | 14 +++++++++++++- 3 files changed, 34 insertions(+), 2 deletions(-) create mode 100644 src/remote/activitypub/kernel/undo/announce.ts diff --git a/src/remote/activitypub/kernel/undo/announce.ts b/src/remote/activitypub/kernel/undo/announce.ts new file mode 100644 index 000000000..38ce5b6c5 --- /dev/null +++ b/src/remote/activitypub/kernel/undo/announce.ts @@ -0,0 +1,16 @@ +import { Notes } from '../../../../models'; +import { IRemoteUser } from '../../../../models/entities/user'; +import { IAnnounce, getApId } from '../../type'; +import deleteNote from '../../../../services/note/delete'; + +export const undoAnnounce = async (actor: IRemoteUser, activity: IAnnounce): Promise => { + const uri = getApId(activity); + + const note = await Notes.findOne({ + uri + }); + + if (!note) return; + + await deleteNote(actor, note); +}; diff --git a/src/remote/activitypub/kernel/undo/index.ts b/src/remote/activitypub/kernel/undo/index.ts index 5f2e58c3b..f49f66cc6 100644 --- a/src/remote/activitypub/kernel/undo/index.ts +++ b/src/remote/activitypub/kernel/undo/index.ts @@ -1,8 +1,9 @@ import { IRemoteUser } from '../../../../models/entities/user'; -import { IUndo, IFollow, IBlock, ILike } from '../../type'; +import { IUndo, IFollow, IBlock, ILike, IAnnounce } from '../../type'; import unfollow from './follow'; import unblock from './block'; import undoLike from './like'; +import { undoAnnounce } from './announce'; import Resolver from '../../resolver'; import { apLogger } from '../../logger'; @@ -38,5 +39,8 @@ export default async (actor: IRemoteUser, activity: IUndo): Promise => { case 'Like': undoLike(actor, object as ILike); break; + case 'Announce': + undoAnnounce(actor, object as IAnnounce); + break; } }; diff --git a/src/services/note/delete.ts b/src/services/note/delete.ts index 95776f728..0f087de42 100644 --- a/src/services/note/delete.ts +++ b/src/services/note/delete.ts @@ -1,5 +1,7 @@ import { publishNoteStream } from '../stream'; import renderDelete from '../../remote/activitypub/renderer/delete'; +import renderAnnounce from '../../remote/activitypub/renderer/announce'; +import renderUndo from '../../remote/activitypub/renderer/undo'; import { renderActivity } from '../../remote/activitypub/renderer'; import { deliver } from '../../queue'; import renderTombstone from '../../remote/activitypub/renderer/tombstone'; @@ -35,7 +37,17 @@ export default async function(user: User, note: Note, quiet = false) { //#region ローカルの投稿なら削除アクティビティを配送 if (Users.isLocalUser(user)) { - const content = renderActivity(renderDelete(renderTombstone(`${config.url}/notes/${note.id}`), user)); + let renote: Note | undefined; + + if (note.renoteId && note.text == null && !note.hasPoll && (note.fileIds == null || note.fileIds.length == 0)) { + renote = await Notes.findOne({ + id: note.renoteId + }); + } + + const content = renderActivity(renote + ? renderUndo(renderAnnounce(renote.uri || `${config.url}/notes/${renote.id}`, note), user) + : renderDelete(renderTombstone(`${config.url}/notes/${note.id}`), user)); const queue: string[] = [];