フォロワーではないリモートユーザーに削除通知が配信されない問題を修正 (#6475)

* フォロワーではないリモートユーザーに削除通知が配信されない問題を修正

* 同じ処理を一つにまとめた

* Inのエラー修正, Renote/Quote対応

Co-authored-by: mei23 <m@m544.net>
This commit is contained in:
fuyu 2020-07-12 00:44:31 +09:00 committed by GitHub
parent 66d6e71f06
commit 91648d1bd4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 40 additions and 8 deletions

View File

@ -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);
}
}