2021-11-12 12:47:04 +02:00
|
|
|
import ms from 'ms';
|
2022-09-17 21:27:08 +03:00
|
|
|
import { Inject, Injectable } from '@nestjs/common';
|
|
|
|
import { Endpoint } from '@/server/api/endpoint-base.js';
|
2022-09-20 23:33:11 +03:00
|
|
|
import type { UsersRepository, FollowingsRepository } from '@/models/index.js';
|
2022-02-27 04:07:39 +02:00
|
|
|
import { IdentifiableError } from '@/misc/identifiable-error.js';
|
2022-09-17 21:27:08 +03:00
|
|
|
import { UserEntityService } from '@/core/entities/UserEntityService.js';
|
|
|
|
import { UserFollowingService } from '@/core/UserFollowingService.js';
|
|
|
|
import { DI } from '@/di-symbols.js';
|
2022-09-24 01:15:16 +03:00
|
|
|
import { GetterService } from '@/server/api/GetterService.js';
|
2023-01-14 13:21:03 +02:00
|
|
|
import { ApiError } from '../../error.js';
|
2016-12-29 00:49:51 +02:00
|
|
|
|
2018-07-16 22:36:44 +03:00
|
|
|
export const meta = {
|
2019-02-23 04:20:58 +02:00
|
|
|
tags: ['following', 'users'],
|
|
|
|
|
2018-07-16 22:36:44 +03:00
|
|
|
limit: {
|
|
|
|
duration: ms('1hour'),
|
2023-01-14 13:21:03 +02:00
|
|
|
max: 50,
|
2018-07-16 22:36:44 +03:00
|
|
|
},
|
|
|
|
|
2022-01-18 15:27:10 +02:00
|
|
|
requireCredential: true,
|
2018-07-16 22:36:44 +03: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 18:09:29 +03:00
|
|
|
prohibitMoved: true,
|
|
|
|
|
2019-04-07 15:50:36 +03:00
|
|
|
kind: 'write:following',
|
2018-10-21 23:16:27 +03:00
|
|
|
|
2019-02-22 04:46:58 +02:00
|
|
|
errors: {
|
|
|
|
noSuchUser: {
|
|
|
|
message: 'No such user.',
|
|
|
|
code: 'NO_SUCH_USER',
|
2021-12-09 16:58:30 +02:00
|
|
|
id: 'fcd2eef9-a9b2-4c4f-8624-038099e90aa5',
|
2019-02-22 04:46:58 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
followeeIsYourself: {
|
|
|
|
message: 'Followee is yourself.',
|
|
|
|
code: 'FOLLOWEE_IS_YOURSELF',
|
2021-12-09 16:58:30 +02:00
|
|
|
id: '26fbe7bb-a331-4857-af17-205b426669a9',
|
2019-02-22 04:46:58 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
alreadyFollowing: {
|
|
|
|
message: 'You are already following that user.',
|
|
|
|
code: 'ALREADY_FOLLOWING',
|
2021-12-09 16:58:30 +02:00
|
|
|
id: '35387507-38c7-4cb9-9197-300b93783fa0',
|
2019-02-22 04:46:58 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
blocking: {
|
|
|
|
message: 'You are blocking that user.',
|
|
|
|
code: 'BLOCKING',
|
2021-12-09 16:58:30 +02:00
|
|
|
id: '4e2206ec-aa4f-4960-b865-6c23ac38e2d9',
|
2019-02-22 04:46:58 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
blocked: {
|
|
|
|
message: 'You are blocked by that user.',
|
|
|
|
code: 'BLOCKED',
|
2021-12-09 16:58:30 +02:00
|
|
|
id: 'c4ab57cc-4e41-45e9-bfd9-584f61e35ce0',
|
2019-02-22 04:46:58 +02:00
|
|
|
},
|
2021-03-06 15:34:11 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
res: {
|
2022-01-18 15:27:10 +02:00
|
|
|
type: 'object',
|
|
|
|
optional: false, nullable: false,
|
|
|
|
ref: 'UserLite',
|
2021-12-09 16:58:30 +02:00
|
|
|
},
|
2022-01-18 15:27:10 +02:00
|
|
|
} as const;
|
2018-07-16 22:36:44 +03:00
|
|
|
|
2022-02-20 06:15:40 +02:00
|
|
|
export const paramDef = {
|
2022-02-19 07:05:32 +02:00
|
|
|
type: 'object',
|
|
|
|
properties: {
|
|
|
|
userId: { type: 'string', format: 'misskey:id' },
|
|
|
|
},
|
|
|
|
required: ['userId'],
|
|
|
|
} as const;
|
|
|
|
|
2022-01-02 19:12:50 +02:00
|
|
|
// eslint-disable-next-line import/no-default-export
|
2022-09-17 21:27:08 +03:00
|
|
|
@Injectable()
|
|
|
|
export default class extends Endpoint<typeof meta, typeof paramDef> {
|
|
|
|
constructor(
|
|
|
|
@Inject(DI.usersRepository)
|
|
|
|
private usersRepository: UsersRepository,
|
|
|
|
|
|
|
|
@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 08:58:58 +03:00
|
|
|
const exist = await this.followingsRepository.exist({
|
|
|
|
where: {
|
|
|
|
followerId: follower.id,
|
|
|
|
followeeId: followee.id,
|
|
|
|
},
|
2022-09-17 21:27:08 +03:00
|
|
|
});
|
|
|
|
|
2023-07-11 08:58:58 +03:00
|
|
|
if (exist) {
|
2022-09-17 21:27:08 +03: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-29 00:49:51 +02:00
|
|
|
}
|
2022-09-17 21:27:08 +03:00
|
|
|
}
|