2019-02-04 20:48:08 -06:00
|
|
|
import $ from 'cafy';
|
2021-08-19 07:55:45 -05:00
|
|
|
import define from '../../define';
|
|
|
|
import { ID } from '@/misc/cafy-id';
|
|
|
|
import { Users } from '@/models/index';
|
2018-10-31 10:11:21 -05:00
|
|
|
|
|
|
|
export const meta = {
|
2019-02-22 20:20:58 -06:00
|
|
|
tags: ['users'],
|
|
|
|
|
2020-02-15 06:33:32 -06:00
|
|
|
requireCredential: true as const,
|
2018-10-31 10:11:52 -05:00
|
|
|
|
2018-10-31 10:11:21 -05:00
|
|
|
params: {
|
2018-11-01 13:32:24 -05:00
|
|
|
userId: {
|
2019-02-22 20:20:58 -06:00
|
|
|
validator: $.either($.type(ID), $.arr($.type(ID)).unique()),
|
2021-12-09 08:58:30 -06:00
|
|
|
},
|
2021-03-06 07:34:11 -06:00
|
|
|
},
|
|
|
|
|
|
|
|
res: {
|
|
|
|
oneOf: [
|
|
|
|
{
|
|
|
|
type: 'object' as const,
|
|
|
|
optional: false as const, nullable: false as const,
|
|
|
|
properties: {
|
|
|
|
id: {
|
|
|
|
type: 'string' as const,
|
|
|
|
optional: false as const, nullable: false as const,
|
2021-12-09 08:58:30 -06:00
|
|
|
format: 'id',
|
2021-03-06 07:34:11 -06:00
|
|
|
},
|
|
|
|
isFollowing: {
|
|
|
|
type: 'boolean' as const,
|
2021-12-09 08:58:30 -06:00
|
|
|
optional: false as const, nullable: false as const,
|
2021-03-06 07:34:11 -06:00
|
|
|
},
|
|
|
|
hasPendingFollowRequestFromYou: {
|
|
|
|
type: 'boolean' as const,
|
2021-12-09 08:58:30 -06:00
|
|
|
optional: false as const, nullable: false as const,
|
2021-03-06 07:34:11 -06:00
|
|
|
},
|
|
|
|
hasPendingFollowRequestToYou: {
|
|
|
|
type: 'boolean' as const,
|
2021-12-09 08:58:30 -06:00
|
|
|
optional: false as const, nullable: false as const,
|
2021-03-06 07:34:11 -06:00
|
|
|
},
|
|
|
|
isFollowed: {
|
|
|
|
type: 'boolean' as const,
|
2021-12-09 08:58:30 -06:00
|
|
|
optional: false as const, nullable: false as const,
|
2021-03-06 07:34:11 -06:00
|
|
|
},
|
|
|
|
isBlocking: {
|
|
|
|
type: 'boolean' as const,
|
2021-12-09 08:58:30 -06:00
|
|
|
optional: false as const, nullable: false as const,
|
2021-03-06 07:34:11 -06:00
|
|
|
},
|
|
|
|
isBlocked: {
|
|
|
|
type: 'boolean' as const,
|
2021-12-09 08:58:30 -06:00
|
|
|
optional: false as const, nullable: false as const,
|
2021-03-06 07:34:11 -06:00
|
|
|
},
|
|
|
|
isMuted: {
|
|
|
|
type: 'boolean' as const,
|
2021-12-09 08:58:30 -06:00
|
|
|
optional: false as const, nullable: false as const,
|
|
|
|
},
|
|
|
|
},
|
2021-03-06 07:34:11 -06:00
|
|
|
},
|
|
|
|
{
|
|
|
|
type: 'array' as const,
|
|
|
|
optional: false as const, nullable: false as const,
|
|
|
|
items: {
|
|
|
|
type: 'object' as const,
|
|
|
|
optional: false as const, nullable: false as const,
|
|
|
|
properties: {
|
|
|
|
id: {
|
|
|
|
type: 'string' as const,
|
|
|
|
optional: false as const, nullable: false as const,
|
2021-12-09 08:58:30 -06:00
|
|
|
format: 'id',
|
2021-03-06 07:34:11 -06:00
|
|
|
},
|
|
|
|
isFollowing: {
|
|
|
|
type: 'boolean' as const,
|
2021-12-09 08:58:30 -06:00
|
|
|
optional: false as const, nullable: false as const,
|
2021-03-06 07:34:11 -06:00
|
|
|
},
|
|
|
|
hasPendingFollowRequestFromYou: {
|
|
|
|
type: 'boolean' as const,
|
2021-12-09 08:58:30 -06:00
|
|
|
optional: false as const, nullable: false as const,
|
2021-03-06 07:34:11 -06:00
|
|
|
},
|
|
|
|
hasPendingFollowRequestToYou: {
|
|
|
|
type: 'boolean' as const,
|
2021-12-09 08:58:30 -06:00
|
|
|
optional: false as const, nullable: false as const,
|
2021-03-06 07:34:11 -06:00
|
|
|
},
|
|
|
|
isFollowed: {
|
|
|
|
type: 'boolean' as const,
|
2021-12-09 08:58:30 -06:00
|
|
|
optional: false as const, nullable: false as const,
|
2021-03-06 07:34:11 -06:00
|
|
|
},
|
|
|
|
isBlocking: {
|
|
|
|
type: 'boolean' as const,
|
2021-12-09 08:58:30 -06:00
|
|
|
optional: false as const, nullable: false as const,
|
2021-03-06 07:34:11 -06:00
|
|
|
},
|
|
|
|
isBlocked: {
|
|
|
|
type: 'boolean' as const,
|
2021-12-09 08:58:30 -06:00
|
|
|
optional: false as const, nullable: false as const,
|
2021-03-06 07:34:11 -06:00
|
|
|
},
|
|
|
|
isMuted: {
|
|
|
|
type: 'boolean' as const,
|
2021-12-09 08:58:30 -06:00
|
|
|
optional: false as const, nullable: false as const,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
2018-10-31 10:11:21 -05:00
|
|
|
};
|
|
|
|
|
2019-02-21 20:46:58 -06:00
|
|
|
export default define(meta, async (ps, me) => {
|
2018-10-31 10:11:21 -05:00
|
|
|
const ids = Array.isArray(ps.userId) ? ps.userId : [ps.userId];
|
|
|
|
|
2019-04-07 07:50:36 -05:00
|
|
|
const relations = await Promise.all(ids.map(id => Users.getRelation(me.id, id)));
|
2018-10-31 10:11:21 -05:00
|
|
|
|
2019-02-21 20:46:58 -06:00
|
|
|
return Array.isArray(ps.userId) ? relations : relations[0];
|
|
|
|
});
|