Fixed 267U.pre2
This commit is contained in:
@@ -0,0 +1,63 @@
|
||||
import { genId } from "../../../../misc/gen-id.js";
|
||||
import { RenoteMutings } from "../../../../models/index.js";
|
||||
import define from "../../define.js";
|
||||
import { ApiError } from "../../error.js";
|
||||
import { getUser } from "../../common/getters.js";
|
||||
export const meta = {
|
||||
tags: [
|
||||
"account"
|
||||
],
|
||||
requireCredential: true,
|
||||
kind: "write:mutes",
|
||||
errors: {
|
||||
noSuchUser: {
|
||||
message: "No such user.",
|
||||
code: "NO_SUCH_USER",
|
||||
id: "6fef56f3-e765-4957-88e5-c6f65329b8a5"
|
||||
},
|
||||
alreadyMuting: {
|
||||
message: "You are already muting that user.",
|
||||
code: "ALREADY_MUTING",
|
||||
id: "7e7359cb-160c-4956-b08f-4d1c653cd007"
|
||||
}
|
||||
}
|
||||
};
|
||||
export const paramDef = {
|
||||
type: "object",
|
||||
properties: {
|
||||
userId: {
|
||||
type: "string",
|
||||
format: "misskey:id"
|
||||
}
|
||||
},
|
||||
required: [
|
||||
"userId"
|
||||
]
|
||||
};
|
||||
// eslint-disable-next-line import/no-default-export
|
||||
export default define(meta, paramDef, async (ps, user)=>{
|
||||
const muter = user;
|
||||
// Get mutee
|
||||
const mutee = await getUser(ps.userId).catch((e)=>{
|
||||
if (e.id === "15348ddd-432d-49c2-8a5a-8069753becff") throw new ApiError(meta.errors.noSuchUser);
|
||||
throw e;
|
||||
});
|
||||
// Check if already muting
|
||||
const exist = await RenoteMutings.exist({
|
||||
where: {
|
||||
muterId: muter.id,
|
||||
muteeId: mutee.id
|
||||
}
|
||||
});
|
||||
if (exist) {
|
||||
throw new ApiError(meta.errors.alreadyMuting);
|
||||
}
|
||||
// Create mute
|
||||
await RenoteMutings.insert({
|
||||
id: genId(),
|
||||
createdAt: new Date(),
|
||||
muterId: muter.id,
|
||||
muteeId: mutee.id
|
||||
});
|
||||
// publishUserEvent(user.id, "mute", mutee);
|
||||
});
|
||||
@@ -0,0 +1,57 @@
|
||||
import { RenoteMutings } from "../../../../models/index.js";
|
||||
import define from "../../define.js";
|
||||
import { ApiError } from "../../error.js";
|
||||
import { getUser } from "../../common/getters.js";
|
||||
export const meta = {
|
||||
tags: [
|
||||
"account"
|
||||
],
|
||||
requireCredential: true,
|
||||
kind: "write:mutes",
|
||||
errors: {
|
||||
noSuchUser: {
|
||||
message: "No such user.",
|
||||
code: "NO_SUCH_USER",
|
||||
id: "b851d00b-8ab1-4a56-8b1b-e24187cb48ef"
|
||||
},
|
||||
notMuting: {
|
||||
message: "You are not muting that user.",
|
||||
code: "NOT_MUTING",
|
||||
id: "5467d020-daa9-4553-81e1-135c0c35a96d"
|
||||
}
|
||||
}
|
||||
};
|
||||
export const paramDef = {
|
||||
type: "object",
|
||||
properties: {
|
||||
userId: {
|
||||
type: "string",
|
||||
format: "misskey:id"
|
||||
}
|
||||
},
|
||||
required: [
|
||||
"userId"
|
||||
]
|
||||
};
|
||||
// eslint-disable-next-line import/no-default-export
|
||||
export default define(meta, paramDef, async (ps, user)=>{
|
||||
const muter = user;
|
||||
// Get mutee
|
||||
const mutee = await getUser(ps.userId).catch((e)=>{
|
||||
if (e.id === "15348ddd-432d-49c2-8a5a-8069753becff") throw new ApiError(meta.errors.noSuchUser);
|
||||
throw e;
|
||||
});
|
||||
// Check not muting
|
||||
const muting = await RenoteMutings.findOneBy({
|
||||
muterId: muter.id,
|
||||
muteeId: mutee.id
|
||||
});
|
||||
if (muting == null) {
|
||||
throw new ApiError(meta.errors.notMuting);
|
||||
}
|
||||
// Delete mute
|
||||
await RenoteMutings.delete({
|
||||
id: muting.id
|
||||
});
|
||||
// publishUserEvent(user.id, "unmute", mutee);
|
||||
});
|
||||
@@ -0,0 +1,49 @@
|
||||
import { RenoteMutings } from "../../../../models/index.js";
|
||||
import define from "../../define.js";
|
||||
import { makePaginationQuery } from "../../common/make-pagination-query.js";
|
||||
export const meta = {
|
||||
tags: [
|
||||
"account"
|
||||
],
|
||||
requireCredential: true,
|
||||
kind: "read:mutes",
|
||||
res: {
|
||||
type: "array",
|
||||
optional: false,
|
||||
nullable: false,
|
||||
items: {
|
||||
type: "object",
|
||||
optional: false,
|
||||
nullable: false,
|
||||
ref: "RenoteMuting"
|
||||
}
|
||||
}
|
||||
};
|
||||
export const paramDef = {
|
||||
type: "object",
|
||||
properties: {
|
||||
limit: {
|
||||
type: "integer",
|
||||
minimum: 1,
|
||||
maximum: 100,
|
||||
default: 30
|
||||
},
|
||||
sinceId: {
|
||||
type: "string",
|
||||
format: "misskey:id"
|
||||
},
|
||||
untilId: {
|
||||
type: "string",
|
||||
format: "misskey:id"
|
||||
}
|
||||
},
|
||||
required: []
|
||||
};
|
||||
// eslint-disable-next-line import/no-default-export
|
||||
export default define(meta, paramDef, async (ps, me)=>{
|
||||
const query = makePaginationQuery(RenoteMutings.createQueryBuilder("muting"), ps.sinceId, ps.untilId).andWhere("muting.muterId = :meId", {
|
||||
meId: me.id
|
||||
});
|
||||
const mutings = await query.take(ps.limit).getMany();
|
||||
return await RenoteMutings.packMany(mutings, me);
|
||||
});
|
||||
Reference in New Issue
Block a user