2023-07-27 00:31:52 -05:00
|
|
|
/*
|
|
|
|
* SPDX-FileCopyrightText: syuilo and other misskey contributors
|
|
|
|
* SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
*/
|
|
|
|
|
2021-11-12 04:47:04 -06:00
|
|
|
import ms from 'ms';
|
2022-09-17 13:27:08 -05:00
|
|
|
import { Inject, Injectable } from '@nestjs/common';
|
|
|
|
import { Endpoint } from '@/server/api/endpoint-base.js';
|
2023-09-15 00:28:29 -05:00
|
|
|
import type { FollowingsRepository } from '@/models/_.js';
|
2022-02-26 20:07:39 -06:00
|
|
|
import { IdentifiableError } from '@/misc/identifiable-error.js';
|
2022-09-17 13:27:08 -05:00
|
|
|
import { UserEntityService } from '@/core/entities/UserEntityService.js';
|
|
|
|
import { UserFollowingService } from '@/core/UserFollowingService.js';
|
|
|
|
import { DI } from '@/di-symbols.js';
|
2022-09-23 17:15:16 -05:00
|
|
|
import { GetterService } from '@/server/api/GetterService.js';
|
2023-01-14 05:21:03 -06:00
|
|
|
import { ApiError } from '../../error.js';
|
2016-12-28 16:49:51 -06:00
|
|
|
|
2018-07-16 14:36:44 -05:00
|
|
|
export const meta = {
|
2019-02-22 20:20:58 -06:00
|
|
|
tags: ['following', 'users'],
|
|
|
|
|
2018-07-16 14:36:44 -05:00
|
|
|
limit: {
|
|
|
|
duration: ms('1hour'),
|
2023-09-21 04:48:15 -05:00
|
|
|
max: 100,
|
2018-07-16 14:36:44 -05:00
|
|
|
},
|
|
|
|
|
2022-01-18 07:27:10 -06:00
|
|
|
requireCredential: true,
|
2018-07-16 14:36:44 -05:00
|
|
|
|
enhance: account migration (#10592)
* copy block and mute then create follow and unfollow jobs
* copy block and mute and update lists when detecting an account has moved
* no need to care promise orders
* refactor updating actor and target
* automatically accept if a locked account had accepted an old account
* fix exception format
* prevent the old account from calling some endpoints
* do not unfollow when moving
* adjust following and follower counts
* check movedToUri when receiving a follow request
* skip if no need to adjust
* Revert "disable account migration"
This reverts commit 2321214c98591bcfe1385c1ab5bf0ff7b471ae1d.
* fix translation specifier
* fix checking alsoKnownAs and uri
* fix updating account
* fix refollowing locked account
* decrease followersCount if followed by the old account
* adjust following and followers counts when unfollowing
* fix copying mutings
* prohibit moved account from moving again
* fix move service
* allow app creation after moving
* fix lint
* remove unnecessary field
* fix cache update
* add e2e test
* add e2e test of accepting the new account automatically
* force follow if any error happens
* remove unnecessary joins
* use Array.map instead of for const of
* ユーザーリストの移行は追加のみを行う
* nanka iroiro
* fix misskey-js?
* :v:
* 移行を行ったアカウントからのフォローリクエストの自動許可を調整
* newUriを外に出す
* newUriを外に出す2
* clean up
* fix newUri
* prevent moving if the destination account has already moved
* set alsoKnownAs via /i/update
* fix database initialization
* add return type
* prohibit updating alsoKnownAs after moving
* skip to add to alsoKnownAs if toUrl is known
* skip adding to the list if it already has
* use Acct.parse instead
* rename error code
* :art:
* 制限を5から10に緩和
* movedTo(Uri), alsoKnownAsはユーザーidを返すように
* test api res
* fix
* 元アカウントはミュートし続ける
* :art:
* unfollow
* fix
* getUserUriをUserEntityServiceに
* ?
* job!
* :art:
* instance => server
* accountMovedShort, forbiddenBecauseYouAreMigrated
* accountMovedShort
* fix test
* import, pin禁止
* 実績を凍結する
* clean up
* :v:
* change message
* ブロック, フォロー, ミュート, リストのインポートファイルの制限を32MiBに
* Revert "ブロック, フォロー, ミュート, リストのインポートファイルの制限を32MiBに"
This reverts commit 3bd7be35d8aa455cb01ae58f8172a71a50485db1.
* validateAlsoKnownAs
* 移行後2時間以内はインポート可能なファイルサイズを拡大
* clean up
* どうせactorをupdatePersonで更新するならupdatePersonしか移行処理を発行しないことにする
* handle error?
* リモートからの移行処理の条件を是正
* log, port
* fix
* fix
* enhance(dev): non-production環境でhttpサーバー間でもユーザー、ノートの連合が可能なように
* refactor (use checkHttps)
* MISSKEY_WEBFINGER_USE_HTTP
* Environment Variable readme
* NEVER USE IN PRODUCTION
* fix punyHost
* fix indent
* fix
* experimental
---------
Co-authored-by: tamaina <tamaina@hotmail.co.jp>
Co-authored-by: syuilo <Syuilotan@yahoo.co.jp>
2023-04-29 10:09:29 -05:00
|
|
|
prohibitMoved: true,
|
|
|
|
|
2019-04-07 07:50:36 -05:00
|
|
|
kind: 'write:following',
|
2018-10-21 15:16:27 -05:00
|
|
|
|
2019-02-21 20:46:58 -06:00
|
|
|
errors: {
|
|
|
|
noSuchUser: {
|
|
|
|
message: 'No such user.',
|
|
|
|
code: 'NO_SUCH_USER',
|
2021-12-09 08:58:30 -06:00
|
|
|
id: 'fcd2eef9-a9b2-4c4f-8624-038099e90aa5',
|
2019-02-21 20:46:58 -06:00
|
|
|
},
|
|
|
|
|
|
|
|
followeeIsYourself: {
|
|
|
|
message: 'Followee is yourself.',
|
|
|
|
code: 'FOLLOWEE_IS_YOURSELF',
|
2021-12-09 08:58:30 -06:00
|
|
|
id: '26fbe7bb-a331-4857-af17-205b426669a9',
|
2019-02-21 20:46:58 -06:00
|
|
|
},
|
|
|
|
|
|
|
|
alreadyFollowing: {
|
|
|
|
message: 'You are already following that user.',
|
|
|
|
code: 'ALREADY_FOLLOWING',
|
2021-12-09 08:58:30 -06:00
|
|
|
id: '35387507-38c7-4cb9-9197-300b93783fa0',
|
2019-02-21 20:46:58 -06:00
|
|
|
},
|
|
|
|
|
|
|
|
blocking: {
|
|
|
|
message: 'You are blocking that user.',
|
|
|
|
code: 'BLOCKING',
|
2021-12-09 08:58:30 -06:00
|
|
|
id: '4e2206ec-aa4f-4960-b865-6c23ac38e2d9',
|
2019-02-21 20:46:58 -06:00
|
|
|
},
|
|
|
|
|
|
|
|
blocked: {
|
|
|
|
message: 'You are blocked by that user.',
|
|
|
|
code: 'BLOCKED',
|
2021-12-09 08:58:30 -06:00
|
|
|
id: 'c4ab57cc-4e41-45e9-bfd9-584f61e35ce0',
|
2019-02-21 20:46:58 -06:00
|
|
|
},
|
2021-03-06 07:34:11 -06:00
|
|
|
},
|
|
|
|
|
|
|
|
res: {
|
2022-01-18 07:27:10 -06:00
|
|
|
type: 'object',
|
|
|
|
optional: false, nullable: false,
|
|
|
|
ref: 'UserLite',
|
2021-12-09 08:58:30 -06:00
|
|
|
},
|
2022-01-18 07:27:10 -06:00
|
|
|
} as const;
|
2018-07-16 14:36:44 -05:00
|
|
|
|
2022-02-19 22:15:40 -06:00
|
|
|
export const paramDef = {
|
2022-02-18 23:05:32 -06:00
|
|
|
type: 'object',
|
|
|
|
properties: {
|
|
|
|
userId: { type: 'string', format: 'misskey:id' },
|
|
|
|
},
|
|
|
|
required: ['userId'],
|
|
|
|
} as const;
|
|
|
|
|
2022-09-17 13:27:08 -05:00
|
|
|
@Injectable()
|
2023-08-17 07:20:58 -05:00
|
|
|
export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-disable-line import/no-default-export
|
2022-09-17 13:27:08 -05:00
|
|
|
constructor(
|
|
|
|
@Inject(DI.followingsRepository)
|
|
|
|
private followingsRepository: FollowingsRepository,
|
|
|
|
|
|
|
|
private userEntityService: UserEntityService,
|
|
|
|
private getterService: GetterService,
|
|
|
|
private userFollowingService: UserFollowingService,
|
|
|
|
) {
|
|
|
|
super(meta, paramDef, async (ps, me) => {
|
|
|
|
const follower = me;
|
|
|
|
|
|
|
|
// 自分自身
|
|
|
|
if (me.id === ps.userId) {
|
|
|
|
throw new ApiError(meta.errors.followeeIsYourself);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Get followee
|
|
|
|
const followee = await this.getterService.getUser(ps.userId).catch(err => {
|
|
|
|
if (err.id === '15348ddd-432d-49c2-8a5a-8069753becff') throw new ApiError(meta.errors.noSuchUser);
|
|
|
|
throw err;
|
|
|
|
});
|
|
|
|
|
|
|
|
// Check if already following
|
2023-07-11 00:58:58 -05:00
|
|
|
const exist = await this.followingsRepository.exist({
|
|
|
|
where: {
|
|
|
|
followerId: follower.id,
|
|
|
|
followeeId: followee.id,
|
|
|
|
},
|
2022-09-17 13:27:08 -05:00
|
|
|
});
|
|
|
|
|
2023-07-11 00:58:58 -05:00
|
|
|
if (exist) {
|
2022-09-17 13:27:08 -05:00
|
|
|
throw new ApiError(meta.errors.alreadyFollowing);
|
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
|
|
|
await this.userFollowingService.follow(follower, followee);
|
|
|
|
} catch (e) {
|
|
|
|
if (e instanceof IdentifiableError) {
|
|
|
|
if (e.id === '710e8fb0-b8c3-4922-be49-d5d93d8e6a6e') throw new ApiError(meta.errors.blocking);
|
|
|
|
if (e.id === '3338392a-f764-498d-8855-db939dcf8c48') throw new ApiError(meta.errors.blocked);
|
|
|
|
}
|
|
|
|
throw e;
|
|
|
|
}
|
|
|
|
|
|
|
|
return await this.userEntityService.pack(followee.id, me);
|
|
|
|
});
|
2016-12-28 16:49:51 -06:00
|
|
|
}
|
2022-09-17 13:27:08 -05:00
|
|
|
}
|