wip following
This commit is contained in:
parent
535e778033
commit
a97d379c84
|
@ -9,70 +9,10 @@ import { DI } from '@/di-symbols.js';
|
||||||
import { GetterService } from '@/server/api/GetterService.js';
|
import { GetterService } from '@/server/api/GetterService.js';
|
||||||
import { ApiError } from '../../error.js';
|
import { ApiError } from '../../error.js';
|
||||||
|
|
||||||
export const meta = {
|
|
||||||
tags: ['following', 'users'],
|
|
||||||
|
|
||||||
limit: {
|
|
||||||
duration: ms('1hour'),
|
|
||||||
max: 50,
|
|
||||||
},
|
|
||||||
|
|
||||||
requireCredential: true,
|
|
||||||
|
|
||||||
prohibitMoved: true,
|
|
||||||
|
|
||||||
kind: 'write:following',
|
|
||||||
|
|
||||||
errors: {
|
|
||||||
noSuchUser: {
|
|
||||||
message: 'No such user.',
|
|
||||||
code: 'NO_SUCH_USER',
|
|
||||||
id: 'fcd2eef9-a9b2-4c4f-8624-038099e90aa5',
|
|
||||||
},
|
|
||||||
|
|
||||||
followeeIsYourself: {
|
|
||||||
message: 'Followee is yourself.',
|
|
||||||
code: 'FOLLOWEE_IS_YOURSELF',
|
|
||||||
id: '26fbe7bb-a331-4857-af17-205b426669a9',
|
|
||||||
},
|
|
||||||
|
|
||||||
alreadyFollowing: {
|
|
||||||
message: 'You are already following that user.',
|
|
||||||
code: 'ALREADY_FOLLOWING',
|
|
||||||
id: '35387507-38c7-4cb9-9197-300b93783fa0',
|
|
||||||
},
|
|
||||||
|
|
||||||
blocking: {
|
|
||||||
message: 'You are blocking that user.',
|
|
||||||
code: 'BLOCKING',
|
|
||||||
id: '4e2206ec-aa4f-4960-b865-6c23ac38e2d9',
|
|
||||||
},
|
|
||||||
|
|
||||||
blocked: {
|
|
||||||
message: 'You are blocked by that user.',
|
|
||||||
code: 'BLOCKED',
|
|
||||||
id: 'c4ab57cc-4e41-45e9-bfd9-584f61e35ce0',
|
|
||||||
},
|
|
||||||
},
|
|
||||||
|
|
||||||
res: {
|
|
||||||
type: 'object',
|
|
||||||
optional: false, nullable: false,
|
|
||||||
ref: 'UserLite',
|
|
||||||
},
|
|
||||||
} as const;
|
|
||||||
|
|
||||||
export const paramDef = {
|
|
||||||
type: 'object',
|
|
||||||
properties: {
|
|
||||||
userId: { type: 'string', format: 'misskey:id' },
|
|
||||||
},
|
|
||||||
required: ['userId'],
|
|
||||||
} as const;
|
|
||||||
|
|
||||||
// eslint-disable-next-line import/no-default-export
|
// eslint-disable-next-line import/no-default-export
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export default class extends Endpoint<typeof meta, typeof paramDef> {
|
export default class extends Endpoint<'following/create'> {
|
||||||
|
name = 'following/create' as const;
|
||||||
constructor(
|
constructor(
|
||||||
@Inject(DI.usersRepository)
|
@Inject(DI.usersRepository)
|
||||||
private usersRepository: UsersRepository,
|
private usersRepository: UsersRepository,
|
||||||
|
@ -84,17 +24,17 @@ export default class extends Endpoint<typeof meta, typeof paramDef> {
|
||||||
private getterService: GetterService,
|
private getterService: GetterService,
|
||||||
private userFollowingService: UserFollowingService,
|
private userFollowingService: UserFollowingService,
|
||||||
) {
|
) {
|
||||||
super(meta, paramDef, async (ps, me) => {
|
super(async (ps, me) => {
|
||||||
const follower = me;
|
const follower = me;
|
||||||
|
|
||||||
// 自分自身
|
// 自分自身
|
||||||
if (me.id === ps.userId) {
|
if (me.id === ps.userId) {
|
||||||
throw new ApiError(meta.errors.followeeIsYourself);
|
throw new ApiError(this.meta.errors.followeeIsYourself);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get followee
|
// Get followee
|
||||||
const followee = await this.getterService.getUser(ps.userId).catch(err => {
|
const followee = await this.getterService.getUser(ps.userId).catch(err => {
|
||||||
if (err.id === '15348ddd-432d-49c2-8a5a-8069753becff') throw new ApiError(meta.errors.noSuchUser);
|
if (err.id === '15348ddd-432d-49c2-8a5a-8069753becff') throw new ApiError(this.meta.errors.noSuchUser);
|
||||||
throw err;
|
throw err;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -105,15 +45,15 @@ export default class extends Endpoint<typeof meta, typeof paramDef> {
|
||||||
});
|
});
|
||||||
|
|
||||||
if (exist != null) {
|
if (exist != null) {
|
||||||
throw new ApiError(meta.errors.alreadyFollowing);
|
throw new ApiError(this.meta.errors.alreadyFollowing);
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await this.userFollowingService.follow(follower, followee);
|
await this.userFollowingService.follow(follower, followee);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
if (e instanceof IdentifiableError) {
|
if (e instanceof IdentifiableError) {
|
||||||
if (e.id === '710e8fb0-b8c3-4922-be49-d5d93d8e6a6e') throw new ApiError(meta.errors.blocking);
|
if (e.id === '710e8fb0-b8c3-4922-be49-d5d93d8e6a6e') throw new ApiError(this.meta.errors.blocking);
|
||||||
if (e.id === '3338392a-f764-498d-8855-db939dcf8c48') throw new ApiError(meta.errors.blocked);
|
if (e.id === '3338392a-f764-498d-8855-db939dcf8c48') throw new ApiError(this.meta.errors.blocked);
|
||||||
}
|
}
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,56 +8,10 @@ import { DI } from '@/di-symbols.js';
|
||||||
import { ApiError } from '../../error.js';
|
import { ApiError } from '../../error.js';
|
||||||
import { GetterService } from '@/server/api/GetterService.js';
|
import { GetterService } from '@/server/api/GetterService.js';
|
||||||
|
|
||||||
export const meta = {
|
|
||||||
tags: ['following', 'users'],
|
|
||||||
|
|
||||||
limit: {
|
|
||||||
duration: ms('1hour'),
|
|
||||||
max: 100,
|
|
||||||
},
|
|
||||||
|
|
||||||
requireCredential: true,
|
|
||||||
|
|
||||||
kind: 'write:following',
|
|
||||||
|
|
||||||
errors: {
|
|
||||||
noSuchUser: {
|
|
||||||
message: 'No such user.',
|
|
||||||
code: 'NO_SUCH_USER',
|
|
||||||
id: '5b12c78d-2b28-4dca-99d2-f56139b42ff8',
|
|
||||||
},
|
|
||||||
|
|
||||||
followeeIsYourself: {
|
|
||||||
message: 'Followee is yourself.',
|
|
||||||
code: 'FOLLOWEE_IS_YOURSELF',
|
|
||||||
id: 'd9e400b9-36b0-4808-b1d8-79e707f1296c',
|
|
||||||
},
|
|
||||||
|
|
||||||
notFollowing: {
|
|
||||||
message: 'You are not following that user.',
|
|
||||||
code: 'NOT_FOLLOWING',
|
|
||||||
id: '5dbf82f5-c92b-40b1-87d1-6c8c0741fd09',
|
|
||||||
},
|
|
||||||
},
|
|
||||||
|
|
||||||
res: {
|
|
||||||
type: 'object',
|
|
||||||
optional: false, nullable: false,
|
|
||||||
ref: 'UserLite',
|
|
||||||
},
|
|
||||||
} as const;
|
|
||||||
|
|
||||||
export const paramDef = {
|
|
||||||
type: 'object',
|
|
||||||
properties: {
|
|
||||||
userId: { type: 'string', format: 'misskey:id' },
|
|
||||||
},
|
|
||||||
required: ['userId'],
|
|
||||||
} as const;
|
|
||||||
|
|
||||||
// eslint-disable-next-line import/no-default-export
|
// eslint-disable-next-line import/no-default-export
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export default class extends Endpoint<typeof meta, typeof paramDef> {
|
export default class extends Endpoint<'following/delete'> {
|
||||||
|
name = 'following/delete' as const;
|
||||||
constructor(
|
constructor(
|
||||||
@Inject(DI.usersRepository)
|
@Inject(DI.usersRepository)
|
||||||
private usersRepository: UsersRepository,
|
private usersRepository: UsersRepository,
|
||||||
|
@ -69,17 +23,17 @@ export default class extends Endpoint<typeof meta, typeof paramDef> {
|
||||||
private getterService: GetterService,
|
private getterService: GetterService,
|
||||||
private userFollowingService: UserFollowingService,
|
private userFollowingService: UserFollowingService,
|
||||||
) {
|
) {
|
||||||
super(meta, paramDef, async (ps, me) => {
|
super(async (ps, me) => {
|
||||||
const follower = me;
|
const follower = me;
|
||||||
|
|
||||||
// Check if the followee is yourself
|
// Check if the followee is yourself
|
||||||
if (me.id === ps.userId) {
|
if (me.id === ps.userId) {
|
||||||
throw new ApiError(meta.errors.followeeIsYourself);
|
throw new ApiError(this.meta.errors.followeeIsYourself);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get followee
|
// Get followee
|
||||||
const followee = await this.getterService.getUser(ps.userId).catch(err => {
|
const followee = await this.getterService.getUser(ps.userId).catch(err => {
|
||||||
if (err.id === '15348ddd-432d-49c2-8a5a-8069753becff') throw new ApiError(meta.errors.noSuchUser);
|
if (err.id === '15348ddd-432d-49c2-8a5a-8069753becff') throw new ApiError(this.meta.errors.noSuchUser);
|
||||||
throw err;
|
throw err;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -90,7 +44,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> {
|
||||||
});
|
});
|
||||||
|
|
||||||
if (exist == null) {
|
if (exist == null) {
|
||||||
throw new ApiError(meta.errors.notFollowing);
|
throw new ApiError(this.meta.errors.notFollowing);
|
||||||
}
|
}
|
||||||
|
|
||||||
await this.userFollowingService.unfollow(follower, followee);
|
await this.userFollowingService.unfollow(follower, followee);
|
||||||
|
|
|
@ -8,56 +8,10 @@ import { DI } from '@/di-symbols.js';
|
||||||
import { ApiError } from '../../error.js';
|
import { ApiError } from '../../error.js';
|
||||||
import { GetterService } from '@/server/api/GetterService.js';
|
import { GetterService } from '@/server/api/GetterService.js';
|
||||||
|
|
||||||
export const meta = {
|
|
||||||
tags: ['following', 'users'],
|
|
||||||
|
|
||||||
limit: {
|
|
||||||
duration: ms('1hour'),
|
|
||||||
max: 100,
|
|
||||||
},
|
|
||||||
|
|
||||||
requireCredential: true,
|
|
||||||
|
|
||||||
kind: 'write:following',
|
|
||||||
|
|
||||||
errors: {
|
|
||||||
noSuchUser: {
|
|
||||||
message: 'No such user.',
|
|
||||||
code: 'NO_SUCH_USER',
|
|
||||||
id: '5b12c78d-2b28-4dca-99d2-f56139b42ff8',
|
|
||||||
},
|
|
||||||
|
|
||||||
followerIsYourself: {
|
|
||||||
message: 'Follower is yourself.',
|
|
||||||
code: 'FOLLOWER_IS_YOURSELF',
|
|
||||||
id: '07dc03b9-03da-422d-885b-438313707662',
|
|
||||||
},
|
|
||||||
|
|
||||||
notFollowing: {
|
|
||||||
message: 'The other use is not following you.',
|
|
||||||
code: 'NOT_FOLLOWING',
|
|
||||||
id: '5dbf82f5-c92b-40b1-87d1-6c8c0741fd09',
|
|
||||||
},
|
|
||||||
},
|
|
||||||
|
|
||||||
res: {
|
|
||||||
type: 'object',
|
|
||||||
optional: false, nullable: false,
|
|
||||||
ref: 'UserLite',
|
|
||||||
},
|
|
||||||
} as const;
|
|
||||||
|
|
||||||
export const paramDef = {
|
|
||||||
type: 'object',
|
|
||||||
properties: {
|
|
||||||
userId: { type: 'string', format: 'misskey:id' },
|
|
||||||
},
|
|
||||||
required: ['userId'],
|
|
||||||
} as const;
|
|
||||||
|
|
||||||
// eslint-disable-next-line import/no-default-export
|
// eslint-disable-next-line import/no-default-export
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export default class extends Endpoint<typeof meta, typeof paramDef> {
|
export default class extends Endpoint<'following/invalidate'> {
|
||||||
|
name = 'following/invalidate' as const;
|
||||||
constructor(
|
constructor(
|
||||||
@Inject(DI.usersRepository)
|
@Inject(DI.usersRepository)
|
||||||
private usersRepository: UsersRepository,
|
private usersRepository: UsersRepository,
|
||||||
|
@ -69,17 +23,17 @@ export default class extends Endpoint<typeof meta, typeof paramDef> {
|
||||||
private getterService: GetterService,
|
private getterService: GetterService,
|
||||||
private userFollowingService: UserFollowingService,
|
private userFollowingService: UserFollowingService,
|
||||||
) {
|
) {
|
||||||
super(meta, paramDef, async (ps, me) => {
|
super(async (ps, me) => {
|
||||||
const followee = me;
|
const followee = me;
|
||||||
|
|
||||||
// Check if the follower is yourself
|
// Check if the follower is yourself
|
||||||
if (me.id === ps.userId) {
|
if (me.id === ps.userId) {
|
||||||
throw new ApiError(meta.errors.followerIsYourself);
|
throw new ApiError(this.meta.errors.followerIsYourself);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get follower
|
// Get follower
|
||||||
const follower = await this.getterService.getUser(ps.userId).catch(err => {
|
const follower = await this.getterService.getUser(ps.userId).catch(err => {
|
||||||
if (err.id === '15348ddd-432d-49c2-8a5a-8069753becff') throw new ApiError(meta.errors.noSuchUser);
|
if (err.id === '15348ddd-432d-49c2-8a5a-8069753becff') throw new ApiError(this.meta.errors.noSuchUser);
|
||||||
throw err;
|
throw err;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -90,7 +44,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> {
|
||||||
});
|
});
|
||||||
|
|
||||||
if (exist == null) {
|
if (exist == null) {
|
||||||
throw new ApiError(meta.errors.notFollowing);
|
throw new ApiError(this.meta.errors.notFollowing);
|
||||||
}
|
}
|
||||||
|
|
||||||
await this.userFollowingService.unfollow(follower, followee);
|
await this.userFollowingService.unfollow(follower, followee);
|
||||||
|
|
|
@ -4822,6 +4822,155 @@ export const endpoints = {
|
||||||
res: undefined,
|
res: undefined,
|
||||||
}],
|
}],
|
||||||
},
|
},
|
||||||
|
'following/create': {
|
||||||
|
tags: ['following', 'users'],
|
||||||
|
|
||||||
|
limit: {
|
||||||
|
duration: ms('1hour'),
|
||||||
|
max: 50,
|
||||||
|
},
|
||||||
|
|
||||||
|
requireCredential: true,
|
||||||
|
|
||||||
|
prohibitMoved: true,
|
||||||
|
|
||||||
|
kind: 'write:following',
|
||||||
|
|
||||||
|
errors: {
|
||||||
|
noSuchUser: {
|
||||||
|
message: 'No such user.',
|
||||||
|
code: 'NO_SUCH_USER',
|
||||||
|
id: 'fcd2eef9-a9b2-4c4f-8624-038099e90aa5',
|
||||||
|
},
|
||||||
|
|
||||||
|
followeeIsYourself: {
|
||||||
|
message: 'Followee is yourself.',
|
||||||
|
code: 'FOLLOWEE_IS_YOURSELF',
|
||||||
|
id: '26fbe7bb-a331-4857-af17-205b426669a9',
|
||||||
|
},
|
||||||
|
|
||||||
|
alreadyFollowing: {
|
||||||
|
message: 'You are already following that user.',
|
||||||
|
code: 'ALREADY_FOLLOWING',
|
||||||
|
id: '35387507-38c7-4cb9-9197-300b93783fa0',
|
||||||
|
},
|
||||||
|
|
||||||
|
blocking: {
|
||||||
|
message: 'You are blocking that user.',
|
||||||
|
code: 'BLOCKING',
|
||||||
|
id: '4e2206ec-aa4f-4960-b865-6c23ac38e2d9',
|
||||||
|
},
|
||||||
|
|
||||||
|
blocked: {
|
||||||
|
message: 'You are blocked by that user.',
|
||||||
|
code: 'BLOCKED',
|
||||||
|
id: 'c4ab57cc-4e41-45e9-bfd9-584f61e35ce0',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
|
||||||
|
defines: [{
|
||||||
|
req: {
|
||||||
|
type: 'object',
|
||||||
|
properties: {
|
||||||
|
userId: { type: 'string', format: 'misskey:id' },
|
||||||
|
},
|
||||||
|
required: ['userId'],
|
||||||
|
},
|
||||||
|
res: {
|
||||||
|
$ref: 'https://misskey-hub.net/api/schemas/UserLite',
|
||||||
|
},
|
||||||
|
}],
|
||||||
|
},
|
||||||
|
'following/delete': {
|
||||||
|
tags: ['following', 'users'],
|
||||||
|
|
||||||
|
limit: {
|
||||||
|
duration: ms('1hour'),
|
||||||
|
max: 100,
|
||||||
|
},
|
||||||
|
|
||||||
|
requireCredential: true,
|
||||||
|
|
||||||
|
kind: 'write:following',
|
||||||
|
|
||||||
|
errors: {
|
||||||
|
noSuchUser: {
|
||||||
|
message: 'No such user.',
|
||||||
|
code: 'NO_SUCH_USER',
|
||||||
|
id: '5b12c78d-2b28-4dca-99d2-f56139b42ff8',
|
||||||
|
},
|
||||||
|
|
||||||
|
followeeIsYourself: {
|
||||||
|
message: 'Followee is yourself.',
|
||||||
|
code: 'FOLLOWEE_IS_YOURSELF',
|
||||||
|
id: 'd9e400b9-36b0-4808-b1d8-79e707f1296c',
|
||||||
|
},
|
||||||
|
|
||||||
|
notFollowing: {
|
||||||
|
message: 'You are not following that user.',
|
||||||
|
code: 'NOT_FOLLOWING',
|
||||||
|
id: '5dbf82f5-c92b-40b1-87d1-6c8c0741fd09',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
|
||||||
|
defines: [{
|
||||||
|
req: {
|
||||||
|
type: 'object',
|
||||||
|
properties: {
|
||||||
|
userId: { type: 'string', format: 'misskey:id' },
|
||||||
|
},
|
||||||
|
required: ['userId'],
|
||||||
|
},
|
||||||
|
res: {
|
||||||
|
$ref: 'https://misskey-hub.net/api/schemas/UserLite',
|
||||||
|
},
|
||||||
|
}],
|
||||||
|
},
|
||||||
|
'following/invalidate': {
|
||||||
|
tags: ['following', 'users'],
|
||||||
|
|
||||||
|
limit: {
|
||||||
|
duration: ms('1hour'),
|
||||||
|
max: 100,
|
||||||
|
},
|
||||||
|
|
||||||
|
requireCredential: true,
|
||||||
|
|
||||||
|
kind: 'write:following',
|
||||||
|
|
||||||
|
errors: {
|
||||||
|
noSuchUser: {
|
||||||
|
message: 'No such user.',
|
||||||
|
code: 'NO_SUCH_USER',
|
||||||
|
id: '5b12c78d-2b28-4dca-99d2-f56139b42ff8',
|
||||||
|
},
|
||||||
|
|
||||||
|
followerIsYourself: {
|
||||||
|
message: 'Follower is yourself.',
|
||||||
|
code: 'FOLLOWER_IS_YOURSELF',
|
||||||
|
id: '07dc03b9-03da-422d-885b-438313707662',
|
||||||
|
},
|
||||||
|
|
||||||
|
notFollowing: {
|
||||||
|
message: 'The other use is not following you.',
|
||||||
|
code: 'NOT_FOLLOWING',
|
||||||
|
id: '5dbf82f5-c92b-40b1-87d1-6c8c0741fd09',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
|
||||||
|
defines: [{
|
||||||
|
req: {
|
||||||
|
type: 'object',
|
||||||
|
properties: {
|
||||||
|
userId: { type: 'string', format: 'misskey:id' },
|
||||||
|
},
|
||||||
|
required: ['userId'],
|
||||||
|
},
|
||||||
|
res: {
|
||||||
|
$ref: 'https://misskey-hub.net/api/schemas/UserLite',
|
||||||
|
},
|
||||||
|
}],
|
||||||
|
},
|
||||||
//#endregion
|
//#endregion
|
||||||
} as const satisfies { [x: string]: IEndpointMeta; };
|
} as const satisfies { [x: string]: IEndpointMeta; };
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue