2023-01-13 05:40:33 +01:00
|
|
|
import { Users } from "@/models/index.js";
|
|
|
|
import define from "../define.js";
|
|
|
|
import { generateMutedUserQueryForUsers } from "../common/generate-muted-user-query.js";
|
|
|
|
import { generateBlockQueryForUsers } from "../common/generate-block-query.js";
|
2016-12-28 23:49:51 +01:00
|
|
|
|
2018-11-02 04:49:08 +01:00
|
|
|
export const meta = {
|
2023-01-13 05:40:33 +01:00
|
|
|
tags: ["users"],
|
2019-02-23 03:20:58 +01:00
|
|
|
|
2022-10-26 04:22:30 +02:00
|
|
|
requireCredential: true,
|
2021-07-20 20:51:59 +02:00
|
|
|
requireCredentialPrivateMode: true,
|
2018-11-02 04:49:08 +01:00
|
|
|
|
2019-02-24 11:42:26 +01:00
|
|
|
res: {
|
2023-01-13 05:40:33 +01:00
|
|
|
type: "array",
|
|
|
|
optional: false,
|
|
|
|
nullable: false,
|
2019-02-24 11:42:26 +01:00
|
|
|
items: {
|
2023-01-13 05:40:33 +01:00
|
|
|
type: "object",
|
|
|
|
optional: false,
|
|
|
|
nullable: false,
|
|
|
|
ref: "UserDetailed",
|
2021-12-09 15:58:30 +01:00
|
|
|
},
|
2019-02-24 11:42:26 +01:00
|
|
|
},
|
2022-01-18 14:27:10 +01:00
|
|
|
} as const;
|
2017-03-03 20:28:38 +01:00
|
|
|
|
2022-02-20 05:15:40 +01:00
|
|
|
export const paramDef = {
|
2023-01-13 05:40:33 +01:00
|
|
|
type: "object",
|
2022-02-19 06:05:32 +01:00
|
|
|
properties: {
|
2023-01-13 05:40:33 +01:00
|
|
|
limit: { type: "integer", minimum: 1, maximum: 100, default: 10 },
|
|
|
|
offset: { type: "integer", default: 0 },
|
|
|
|
sort: {
|
|
|
|
type: "string",
|
|
|
|
enum: [
|
|
|
|
"+follower",
|
|
|
|
"-follower",
|
|
|
|
"+createdAt",
|
|
|
|
"-createdAt",
|
|
|
|
"+updatedAt",
|
|
|
|
"-updatedAt",
|
|
|
|
],
|
|
|
|
},
|
|
|
|
state: {
|
|
|
|
type: "string",
|
|
|
|
enum: ["all", "admin", "moderator", "adminOrModerator", "alive"],
|
|
|
|
default: "all",
|
|
|
|
},
|
|
|
|
origin: {
|
|
|
|
type: "string",
|
|
|
|
enum: ["combined", "local", "remote"],
|
|
|
|
default: "local",
|
|
|
|
},
|
2022-06-30 08:32:11 +02:00
|
|
|
hostname: {
|
2023-01-13 05:40:33 +01:00
|
|
|
type: "string",
|
2022-06-30 08:32:11 +02:00
|
|
|
nullable: true,
|
|
|
|
default: null,
|
2023-01-13 05:40:33 +01:00
|
|
|
description: "The local host is represented with `null`.",
|
2022-06-30 08:32:11 +02:00
|
|
|
},
|
2022-02-19 06:05:32 +01:00
|
|
|
},
|
|
|
|
required: [],
|
|
|
|
} as const;
|
|
|
|
|
|
|
|
export default define(meta, paramDef, async (ps, me) => {
|
2023-01-13 05:40:33 +01:00
|
|
|
const query = Users.createQueryBuilder("user");
|
|
|
|
query.where("user.isExplorable = TRUE");
|
2019-02-15 22:50:58 +01:00
|
|
|
|
2019-04-07 14:50:36 +02:00
|
|
|
switch (ps.state) {
|
2023-01-13 05:40:33 +01:00
|
|
|
case "admin":
|
|
|
|
query.andWhere("user.isAdmin = TRUE");
|
|
|
|
break;
|
|
|
|
case "moderator":
|
|
|
|
query.andWhere("user.isModerator = TRUE");
|
|
|
|
break;
|
|
|
|
case "adminOrModerator":
|
|
|
|
query.andWhere("user.isAdmin = TRUE OR user.isModerator = TRUE");
|
|
|
|
break;
|
|
|
|
case "alive":
|
|
|
|
query.andWhere("user.updatedAt > :date", {
|
|
|
|
date: new Date(Date.now() - 1000 * 60 * 60 * 24 * 5),
|
|
|
|
});
|
|
|
|
break;
|
2019-04-07 14:50:36 +02:00
|
|
|
}
|
2019-02-15 22:50:58 +01:00
|
|
|
|
2019-04-07 14:50:36 +02:00
|
|
|
switch (ps.origin) {
|
2023-01-13 05:40:33 +01:00
|
|
|
case "local":
|
|
|
|
query.andWhere("user.host IS NULL");
|
|
|
|
break;
|
|
|
|
case "remote":
|
|
|
|
query.andWhere("user.host IS NOT NULL");
|
|
|
|
break;
|
2019-04-07 14:50:36 +02:00
|
|
|
}
|
2018-11-23 00:01:14 +01:00
|
|
|
|
2022-06-30 08:32:11 +02:00
|
|
|
if (ps.hostname) {
|
2023-01-13 05:40:33 +01:00
|
|
|
query.andWhere("user.host = :hostname", {
|
|
|
|
hostname: ps.hostname.toLowerCase(),
|
|
|
|
});
|
2022-06-30 08:32:11 +02:00
|
|
|
}
|
|
|
|
|
2019-04-07 14:50:36 +02:00
|
|
|
switch (ps.sort) {
|
2023-01-13 05:40:33 +01:00
|
|
|
case "+follower":
|
|
|
|
query.orderBy("user.followersCount", "DESC");
|
|
|
|
break;
|
|
|
|
case "-follower":
|
|
|
|
query.orderBy("user.followersCount", "ASC");
|
|
|
|
break;
|
|
|
|
case "+createdAt":
|
|
|
|
query.orderBy("user.createdAt", "DESC");
|
|
|
|
break;
|
|
|
|
case "-createdAt":
|
|
|
|
query.orderBy("user.createdAt", "ASC");
|
|
|
|
break;
|
|
|
|
case "+updatedAt":
|
|
|
|
query
|
|
|
|
.andWhere("user.updatedAt IS NOT NULL")
|
|
|
|
.orderBy("user.updatedAt", "DESC");
|
|
|
|
break;
|
|
|
|
case "-updatedAt":
|
|
|
|
query
|
|
|
|
.andWhere("user.updatedAt IS NOT NULL")
|
|
|
|
.orderBy("user.updatedAt", "ASC");
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
query.orderBy("user.id", "ASC");
|
|
|
|
break;
|
2019-04-07 14:50:36 +02:00
|
|
|
}
|
|
|
|
|
2020-07-28 02:38:41 +02:00
|
|
|
if (me) generateMutedUserQueryForUsers(query, me);
|
2021-08-20 13:55:12 +02:00
|
|
|
if (me) generateBlockQueryForUsers(query, me);
|
2019-04-07 14:50:36 +02:00
|
|
|
|
2022-02-19 06:05:32 +01:00
|
|
|
query.take(ps.limit);
|
2019-04-07 14:50:36 +02:00
|
|
|
query.skip(ps.offset);
|
|
|
|
|
|
|
|
const users = await query.getMany();
|
|
|
|
|
|
|
|
return await Users.packMany(users, me, { detail: true });
|
2019-02-22 03:46:58 +01:00
|
|
|
});
|