diff options
| author | MeiMei <30769358+mei23@users.noreply.github.com> | 2019-07-18 02:03:28 +0900 |
|---|---|---|
| committer | syuilo <Syuilotan@yahoo.co.jp> | 2019-07-18 02:03:28 +0900 |
| commit | 9c4e64b7b54886f97a9770b9d4904be29ba68eec (patch) | |
| tree | 481c26336b7f9b38f6b3834231e4cffe530264b5 /src/services | |
| parent | Mastodonのリンクの所有者認証に対応 (#5161) (diff) | |
| download | sharkey-9c4e64b7b54886f97a9770b9d4904be29ba68eec.tar.gz sharkey-9c4e64b7b54886f97a9770b9d4904be29ba68eec.tar.bz2 sharkey-9c4e64b7b54886f97a9770b9d4904be29ba68eec.zip | |
Send Delete activity on suspend (#5165)
* Send Delete Person activity
* Delete activityの後にフォロー解除する
* アカウント削除でもDelete activity
Diffstat (limited to 'src/services')
| -rw-r--r-- | src/services/suspend-user.ts | 34 | ||||
| -rw-r--r-- | src/services/unsuspend-user.ts | 35 |
2 files changed, 69 insertions, 0 deletions
diff --git a/src/services/suspend-user.ts b/src/services/suspend-user.ts new file mode 100644 index 0000000000..a85188acbe --- /dev/null +++ b/src/services/suspend-user.ts @@ -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); + } + } +} diff --git a/src/services/unsuspend-user.ts b/src/services/unsuspend-user.ts new file mode 100644 index 0000000000..6cab375821 --- /dev/null +++ b/src/services/unsuspend-user.ts @@ -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); + } + } +} |