forked from FoundKeyGang/FoundKey
Johann150
7b8333a21f
Instead of throwing an IdentifiableError which then just always gets converted into an ApiError, the getter can just throw the same ApiError directly. This makes it more convenient to use and thus more endpoints have been refactored to use it to reduce code repetition.
50 lines
1.1 KiB
TypeScript
50 lines
1.1 KiB
TypeScript
import { Mutings } from '@/models/index.js';
|
|
import { publishUserEvent } from '@/services/stream.js';
|
|
import define from '@/server/api/define.js';
|
|
import { ApiError } from '@/server/api/error.js';
|
|
import { getUser } from '@/server/api/common/getters.js';
|
|
|
|
export const meta = {
|
|
tags: ['account'],
|
|
|
|
requireCredential: true,
|
|
|
|
kind: 'write:mutes',
|
|
|
|
errors: ['NO_SUCH_USER', 'MUTEE_IS_YOURSELF', 'NOT_MUTING'],
|
|
} 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
|
|
export default define(meta, paramDef, async (ps, user) => {
|
|
const muter = user;
|
|
|
|
// Check if the mutee is yourself
|
|
if (user.id === ps.userId) throw new ApiError('MUTEE_IS_YOURSELF');
|
|
|
|
// Get mutee
|
|
const mutee = await getUser(ps.userId);
|
|
|
|
// Check not muting
|
|
const exist = await Mutings.findOneBy({
|
|
muterId: muter.id,
|
|
muteeId: mutee.id,
|
|
});
|
|
|
|
if (exist == null) throw new ApiError('NOT_MUTING');
|
|
|
|
// Delete mute
|
|
await Mutings.delete({
|
|
id: exist.id,
|
|
});
|
|
|
|
publishUserEvent(user.id, 'unmute', mutee);
|
|
});
|