From c5bdee086da27c2c0b5e1119603b6d0783b1708e Mon Sep 17 00:00:00 2001 From: MeiMei <30769358+mei23@users.noreply.github.com> Date: Sat, 26 Dec 2020 15:31:28 +0900 Subject: [PATCH] =?UTF-8?q?=E3=83=95=E3=82=A9=E3=83=AD=E3=83=BC=E3=83=AA?= =?UTF-8?q?=E3=82=AF=E3=82=A8=E3=82=B9=E3=83=88=E3=81=8C=E3=81=AA=E3=81=8F?= =?UTF-8?q?=E3=81=A6=E3=82=82=E3=83=95=E3=82=A9=E3=83=AD=E3=83=BC=E6=89=BF?= =?UTF-8?q?=E8=AA=8D=E3=81=8C=E5=87=BA=E6=9D=A5=E3=81=A6=E3=81=97=E3=81=BE?= =?UTF-8?q?=E3=81=86=E3=81=AE=E3=82=92=E4=BF=AE=E6=AD=A3=20(#7013)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * フォローリクエストがなくてもフォロー承認が出来てしまうのを修正 * プロキシアカウントがDB処理をせずにフォローを飛ばしているのを修正 --- src/server/api/endpoints/following/requests/accept.ts | 10 +++++++++- src/services/following/requests/accept.ts | 7 ++++++- src/services/user-list/push.ts | 7 ++----- 3 files changed, 17 insertions(+), 7 deletions(-) diff --git a/src/server/api/endpoints/following/requests/accept.ts b/src/server/api/endpoints/following/requests/accept.ts index 6f3a0510a..6dd93c0d4 100644 --- a/src/server/api/endpoints/following/requests/accept.ts +++ b/src/server/api/endpoints/following/requests/accept.ts @@ -33,6 +33,11 @@ export const meta = { code: 'NO_SUCH_USER', id: '66ce1645-d66c-46bb-8b79-96739af885bd' }, + noFollowRequest: { + message: 'No follow request.', + code: 'NO_FOLLOW_REQUEST', + id: 'bcde4f8b-0913-4614-8881-614e522fb041' + }, } }; @@ -43,7 +48,10 @@ export default define(meta, async (ps, user) => { throw e; }); - await acceptFollowRequest(user, follower); + await acceptFollowRequest(user, follower).catch(e => { + if (e.id === '8884c2dd-5795-4ac9-b27e-6a01d38190f9') throw new ApiError(meta.errors.noFollowRequest); + throw e; + }); return; }); diff --git a/src/services/following/requests/accept.ts b/src/services/following/requests/accept.ts index 1397514ad..6a072126b 100644 --- a/src/services/following/requests/accept.ts +++ b/src/services/following/requests/accept.ts @@ -6,6 +6,7 @@ import { publishMainStream } from '../../stream'; import { insertFollowingDoc } from '../create'; import { User, ILocalUser } from '../../../models/entities/user'; import { FollowRequests, Users } from '../../../models'; +import { IdentifiableError } from '../../../misc/identifiable-error'; export default async function(followee: User, follower: User) { const request = await FollowRequests.findOne({ @@ -13,9 +14,13 @@ export default async function(followee: User, follower: User) { followerId: follower.id }); + if (request == null) { + throw new IdentifiableError('8884c2dd-5795-4ac9-b27e-6a01d38190f9', 'No follow request.'); + } + await insertFollowingDoc(followee, follower); - if (Users.isRemoteUser(follower) && request) { + if (Users.isRemoteUser(follower)) { const content = renderActivity(renderAccept(renderFollow(follower, followee, request.requestId!), followee as ILocalUser)); deliver(followee as ILocalUser, content, follower.inbox); } diff --git a/src/services/user-list/push.ts b/src/services/user-list/push.ts index 0fbeae79f..e67be4b02 100644 --- a/src/services/user-list/push.ts +++ b/src/services/user-list/push.ts @@ -1,6 +1,3 @@ -import { renderActivity } from '../../remote/activitypub/renderer'; -import { deliver } from '../../queue'; -import renderFollow from '../../remote/activitypub/renderer/follow'; import { publishUserListStream } from '../stream'; import { User } from '../../models/entities/user'; import { UserList } from '../../models/entities/user-list'; @@ -8,6 +5,7 @@ import { UserListJoinings, Users } from '../../models'; import { UserListJoining } from '../../models/entities/user-list-joining'; import { genId } from '../../misc/gen-id'; import { fetchProxyAccount } from '../../misc/fetch-proxy-account'; +import createFollowing from '../following/create'; export async function pushUserToUserList(target: User, list: UserList) { await UserListJoinings.save({ @@ -23,8 +21,7 @@ export async function pushUserToUserList(target: User, list: UserList) { if (Users.isRemoteUser(target)) { const proxy = await fetchProxyAccount(); if (proxy) { - const content = renderActivity(renderFollow(proxy, target)); - deliver(proxy, content, target.inbox); + createFollowing(proxy, target); } } }