Send Delete activity on suspend (#5165)

* Send Delete Person activity

* Delete activityの後にフォロー解除する

* アカウント削除でもDelete activity
This commit is contained in:
MeiMei 2019-07-18 02:03:28 +09:00 committed by syuilo
parent ef44eda69e
commit 9c4e64b7b5
5 changed files with 81 additions and 1 deletions

View File

@ -5,6 +5,7 @@ import deleteFollowing from '../../../../services/following/delete';
import { Users, Followings } from '../../../../models'; import { Users, Followings } from '../../../../models';
import { User } from '../../../../models/entities/user'; import { User } from '../../../../models/entities/user';
import { insertModerationLog } from '../../../../services/insert-moderation-log'; import { insertModerationLog } from '../../../../services/insert-moderation-log';
import { doPostSuspend } from '../../../../services/suspend-user';
export const meta = { export const meta = {
desc: { desc: {
@ -51,7 +52,10 @@ export default define(meta, async (ps, me) => {
targetId: user.id, targetId: user.id,
}); });
unFollowAll(user); (async () => {
await doPostSuspend(user).catch(e => {});
await unFollowAll(user).catch(e => {});
})();
}); });
async function unFollowAll(follower: User) { async function unFollowAll(follower: User) {

View File

@ -3,6 +3,7 @@ import { ID } from '../../../../misc/cafy-id';
import define from '../../define'; import define from '../../define';
import { Users } from '../../../../models'; import { Users } from '../../../../models';
import { insertModerationLog } from '../../../../services/insert-moderation-log'; import { insertModerationLog } from '../../../../services/insert-moderation-log';
import { doPostUnsuspend } from '../../../../services/unsuspend-user';
export const meta = { export const meta = {
desc: { desc: {
@ -40,4 +41,6 @@ export default define(meta, async (ps, me) => {
insertModerationLog(me, 'unsuspend', { insertModerationLog(me, 'unsuspend', {
targetId: user.id, targetId: user.id,
}); });
doPostUnsuspend(user);
}); });

View File

@ -3,6 +3,7 @@ import * as bcrypt from 'bcryptjs';
import define from '../../define'; import define from '../../define';
import { Users, UserProfiles } from '../../../../models'; import { Users, UserProfiles } from '../../../../models';
import { ensure } from '../../../../prelude/ensure'; import { ensure } from '../../../../prelude/ensure';
import { doPostSuspend } from '../../../../services/suspend-user';
export const meta = { export const meta = {
requireCredential: true, requireCredential: true,
@ -26,5 +27,8 @@ export default define(meta, async (ps, user) => {
throw new Error('incorrect password'); throw new Error('incorrect password');
} }
// 物理削除する前にDelete activityを送信する
await doPostSuspend(user).catch(e => {});
await Users.delete(user.id); await Users.delete(user.id);
}); });

View File

@ -0,0 +1,34 @@
import renderDelete from '../remote/activitypub/renderer/delete';
import { renderActivity } from '../remote/activitypub/renderer';
import { deliver } from '../queue';
import config from '../config';
import { User } from '../models/entities/user';
import { Users, Followings } from '../models';
import { Not, IsNull } from 'typeorm';
export async function doPostSuspend(user: User) {
if (Users.isLocalUser(user)) {
// 知り得る全SharedInboxにDelete配信
const content = renderActivity(renderDelete(`${config.url}/users/${user.id}`, user));
const queue: string[] = [];
const followings = await Followings.find({
where: [
{ followerSharedInbox: Not(IsNull()) },
{ followeeSharedInbox: Not(IsNull()) }
],
select: ['followerSharedInbox', 'followeeSharedInbox']
});
const inboxes = followings.map(x => x.followerSharedInbox || x.followeeSharedInbox);
for (const inbox of inboxes) {
if (inbox != null && !queue.includes(inbox)) queue.push(inbox);
}
for (const inbox of queue) {
deliver(user as any, content, inbox);
}
}
}

View File

@ -0,0 +1,35 @@
import renderDelete from '../remote/activitypub/renderer/delete';
import renderUndo from '../remote/activitypub/renderer/undo';
import { renderActivity } from '../remote/activitypub/renderer';
import { deliver } from '../queue';
import config from '../config';
import { User } from '../models/entities/user';
import { Users, Followings } from '../models';
import { Not, IsNull } from 'typeorm';
export async function doPostUnsuspend(user: User) {
if (Users.isLocalUser(user)) {
// 知り得る全SharedInboxにUndo Delete配信
const content = renderActivity(renderUndo(renderDelete(`${config.url}/users/${user.id}`, user), user));
const queue: string[] = [];
const followings = await Followings.find({
where: [
{ followerSharedInbox: Not(IsNull()) },
{ followeeSharedInbox: Not(IsNull()) }
],
select: ['followerSharedInbox', 'followeeSharedInbox']
});
const inboxes = followings.map(x => x.followerSharedInbox || x.followeeSharedInbox);
for (const inbox of inboxes) {
if (inbox != null && !queue.includes(inbox)) queue.push(inbox);
}
for (const inbox of queue) {
deliver(user as any, content, inbox);
}
}
}