WIP move api call

This commit is contained in:
cutestnekoaqua 2022-12-08 01:05:07 +01:00
parent 635290bd33
commit 0855b6720d
3 changed files with 63 additions and 12 deletions

View file

@ -0,0 +1,51 @@
import { In } from 'typeorm';
import create from '@/services/note/create.js';
import { User } from '@/models/entities/user.js';
import { Users, DriveFiles, Notes, Channels, Blockings } from '@/models/index.js';
import { DriveFile } from '@/models/entities/drive-file.js';
import { Note } from '@/models/entities/note.js';
import { Channel } from '@/models/entities/channel.js';
import { ApiError } from '../../error.js';
import define from '../../define.js';
import { DAY } from '@/const.js';
import { getNote } from '../../common/getters.js';
export const meta = {
tags: ['notes'],
secure: true,
requireCredential: true,
limit: {
duration: DAY,
max: 1,
},
errors: {
noSuchMoveTarget: {
message: 'No such move target.',
code: 'NO_SUCH_MOVE_TARGET',
id: 'b5c90186-4ab0-49c8-9bba-a1f76c202ba4',
},
remoteAccountForbids: {
message: 'Remote account doesn\'t have proper known As.',
code: 'REMOTE_ACCOUNT_FORBIDS',
id: 'b5c90186-4ab0-49c8-9bba-a1f766282ba4',
},
},
} as const;
export const paramDef = {
type: 'object',
properties: {
alsoKnownAs: { type: 'string' },
},
required: ['alsoKnownAs'],
} as const;
// eslint-disable-next-line import/no-default-export
export default define(meta, paramDef, async (ps, user) => {
return;
});

View file

@ -250,7 +250,7 @@ export default define(meta, paramDef, async (ps, user) => {
}
}
// 投稿を作成
// Create a post
const note = await create(user, {
createdAt: new Date(),
files: files,

View file

@ -127,8 +127,8 @@ type Option = {
};
export default async (user: { id: User['id']; username: User['username']; host: User['host']; isSilenced: User['isSilenced']; createdAt: User['createdAt']; }, data: Option, silent = false) => new Promise<Note>(async (res, rej) => {
// チャンネル外にリプライしたら対象のスコープに合わせる
// (クライアントサイドでやっても良い処理だと思うけどとりあえずサーバーサイドで)
// If you reply outside the channel, match the scope of the target.
// TODO (I think it's a process that could be done on the client side, but it's server side for now.)
if (data.reply && data.channel && data.reply.channelId !== data.channel.id) {
if (data.reply.channelId) {
data.channel = await Channels.findOneBy({ id: data.reply.channelId });
@ -137,8 +137,8 @@ export default async (user: { id: User['id']; username: User['username']; host:
}
}
// チャンネル内にリプライしたら対象のスコープに合わせる
// (クライアントサイドでやっても良い処理だと思うけどとりあえずサーバーサイドで)
// When you reply in a channel, match the scope of the target
// TODO (I think it's a process that could be done on the client side, but it's server side for now.)
if (data.reply && (data.channel == null) && data.reply.channelId) {
data.channel = await Channels.findOneBy({ id: data.reply.channelId });
}
@ -150,37 +150,37 @@ export default async (user: { id: User['id']; username: User['username']; host:
if (data.channel != null) data.visibleUsers = [];
if (data.channel != null) data.localOnly = true;
// サイレンス
// enforce silent clients on server
if (user.isSilenced && data.visibility === 'public' && data.channel == null) {
data.visibility = 'home';
}
// Renote対象が「ホームまたは全体」以外の公開範囲ならreject
// Reject if the target of the renote is a public range other than "Home or Entire".
if (data.renote && data.renote.visibility !== 'public' && data.renote.visibility !== 'home' && data.renote.userId !== user.id) {
return rej('Renote target is not public or home');
}
// Renote対象がpublicではないならhomeにする
// If the target of the renote is not public, make it home.
if (data.renote && data.renote.visibility !== 'public' && data.visibility === 'public') {
data.visibility = 'home';
}
// Renote対象がfollowersならfollowersにする
// If the target of Renote is followers, make it followers.
if (data.renote && data.renote.visibility === 'followers') {
data.visibility = 'followers';
}
// 返信対象がpublicではないならhomeにする
// If the reply target is not public, make it home.
if (data.reply && data.reply.visibility !== 'public' && data.visibility === 'public') {
data.visibility = 'home';
}
// ローカルのみをRenoteしたらローカルのみにする
// Renote local only if you Renote local only.
if (data.renote && data.renote.localOnly && data.channel == null) {
data.localOnly = true;
}
// ローカルのみにリプライしたらローカルのみにする
// If you reply to local only, make it local only.
if (data.reply && data.reply.localOnly && data.channel == null) {
data.localOnly = true;
}