From 452d298a1f16da3924b7ce206c031007c2a5cf86 Mon Sep 17 00:00:00 2001 From: fuyu <54523771+mfmfuyu@users.noreply.github.com> Date: Sun, 12 Jul 2020 00:44:31 +0900 Subject: [PATCH] =?UTF-8?q?=E3=83=95=E3=82=A9=E3=83=AD=E3=83=AF=E3=83=BC?= =?UTF-8?q?=E3=81=A7=E3=81=AF=E3=81=AA=E3=81=84=E3=83=AA=E3=83=A2=E3=83=BC?= =?UTF-8?q?=E3=83=88=E3=83=A6=E3=83=BC=E3=82=B6=E3=83=BC=E3=81=AB=E5=89=8A?= =?UTF-8?q?=E9=99=A4=E9=80=9A=E7=9F=A5=E3=81=8C=E9=85=8D=E4=BF=A1=E3=81=95?= =?UTF-8?q?=E3=82=8C=E3=81=AA=E3=81=84=E5=95=8F=E9=A1=8C=E3=82=92=E4=BF=AE?= =?UTF-8?q?=E6=AD=A3=20(#6475)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * フォロワーではないリモートユーザーに削除通知が配信されない問題を修正 * 同じ処理を一つにまとめた * Inのエラー修正, Renote/Quote対応 Co-authored-by: mei23 --- src/services/note/delete.ts | 48 ++++++++++++++++++++++++++++++------- 1 file changed, 40 insertions(+), 8 deletions(-) diff --git a/src/services/note/delete.ts b/src/services/note/delete.ts index 1972801ab..552630260 100644 --- a/src/services/note/delete.ts +++ b/src/services/note/delete.ts @@ -6,14 +6,14 @@ import { renderActivity } from '../../remote/activitypub/renderer'; import renderTombstone from '../../remote/activitypub/renderer/tombstone'; import config from '../../config'; import { registerOrFetchInstanceDoc } from '../register-or-fetch-instance-doc'; -import { User } from '../../models/entities/user'; -import { Note } from '../../models/entities/note'; +import { User, ILocalUser, IRemoteUser } from '../../models/entities/user'; +import { Note, IMentionedRemoteUsers } from '../../models/entities/note'; import { Notes, Users, Instances } from '../../models'; import { notesChart, perUserNotesChart, instanceChart } from '../chart'; -import { deliverToFollowers } from '../../remote/activitypub/deliver-manager'; +import { deliverToFollowers, deliverToUser } from '../../remote/activitypub/deliver-manager'; import { countSameRenotes } from '../../misc/count-same-renotes'; import { deliverToRelays } from '../relay'; -import { Brackets } from 'typeorm'; +import { Brackets, In } from 'typeorm'; /** * 投稿を削除します。 @@ -49,8 +49,7 @@ export default async function(user: User, note: Note, quiet = false) { ? renderUndo(renderAnnounce(renote.uri || `${config.url}/notes/${renote.id}`, note), user) : renderDelete(renderTombstone(`${config.url}/notes/${note.id}`), user)); - deliverToFollowers(user, content); - deliverToRelays(user, content); + deliverToConcerned(user, note, content); } // also deliever delete activity to cascaded notes @@ -59,8 +58,7 @@ export default async function(user: User, note: Note, quiet = false) { if (!cascadingNote.user) continue; if (!Users.isLocalUser(cascadingNote.user)) continue; const content = renderActivity(renderDelete(renderTombstone(`${config.url}/notes/${cascadingNote.id}`), cascadingNote.user)); - deliverToFollowers(cascadingNote.user, content); - deliverToRelays(cascadingNote.user, content); + deliverToConcerned(cascadingNote.user, cascadingNote, content); } //#endregion @@ -103,3 +101,37 @@ async function findCascadingNotes(note: Note) { return cascadingNotes.filter(note => note.userHost === null); // filter out non-local users } + +async function getMentionedRemoteUsers(note: Note) { + const where = [] as any[]; + + // mention / reply / dm + const uris = (JSON.parse(note.mentionedRemoteUsers) as IMentionedRemoteUsers).map(x => x.uri); + if (uris.length > 0) { + where.push( + { uri: In(uris) } + ); + } + + // renote / quote + if (note.renoteUserId) { + where.push({ + id: note.renoteUserId + }); + } + + if (where.length === 0) return []; + + return await Users.find({ + where + }) as IRemoteUser[]; +} + +async function deliverToConcerned(user: ILocalUser, note: Note, content: any) { + deliverToFollowers(user, content); + deliverToRelays(user, content); + const remoteUsers = await getMentionedRemoteUsers(note); + for (const remoteUser of remoteUsers) { + deliverToUser(user, content, remoteUser); + } +}