Refactor API (#4770)
* wip * wip * wip * wip * wip * wip * wip * wip * wip * wip * wip * wip * wip * wip * Update description.ts * wip
This commit is contained in:
@@ -4,8 +4,11 @@ import { User } from '../entities/user';
|
||||
import { unique, concat } from '../../prelude/array';
|
||||
import { nyaize } from '../../misc/nyaize';
|
||||
import { Emojis, Users, Apps, PollVotes, DriveFiles, NoteReactions, Followings, Polls } from '..';
|
||||
import rap from '@prezzemolo/rap';
|
||||
import { ensure } from '../../prelude/ensure';
|
||||
import { SchemaType, types, bool } from '../../misc/schema';
|
||||
import { awaitAll } from '../../prelude/await-all';
|
||||
|
||||
export type PackedNote = SchemaType<typeof packedNoteSchema>;
|
||||
|
||||
@EntityRepository(Note)
|
||||
export class NoteRepository extends Repository<Note> {
|
||||
@@ -13,18 +16,18 @@ export class NoteRepository extends Repository<Note> {
|
||||
return x.trim().length <= 100;
|
||||
}
|
||||
|
||||
private async hideNote(packedNote: any, meId: User['id'] | null) {
|
||||
private async hideNote(packedNote: PackedNote, meId: User['id'] | null) {
|
||||
let hide = false;
|
||||
|
||||
// visibility が specified かつ自分が指定されていなかったら非表示
|
||||
if (packedNote.visibility == 'specified') {
|
||||
if (packedNote.visibility === 'specified') {
|
||||
if (meId == null) {
|
||||
hide = true;
|
||||
} else if (meId === packedNote.userId) {
|
||||
hide = false;
|
||||
} else {
|
||||
// 指定されているかどうか
|
||||
const specified = packedNote.visibleUserIds.some((id: any) => meId === id);
|
||||
const specified = packedNote.visibleUserIds!.some((id: any) => meId === id);
|
||||
|
||||
if (specified) {
|
||||
hide = false;
|
||||
@@ -40,10 +43,10 @@ export class NoteRepository extends Repository<Note> {
|
||||
hide = true;
|
||||
} else if (meId === packedNote.userId) {
|
||||
hide = false;
|
||||
} else if (packedNote.reply && (meId === packedNote.reply.userId)) {
|
||||
} else if (packedNote.reply && (meId === (packedNote.reply as PackedNote).userId)) {
|
||||
// 自分の投稿に対するリプライ
|
||||
hide = false;
|
||||
} else if (packedNote.mentions && packedNote.mentions.some((id: any) => meId === id)) {
|
||||
} else if (packedNote.mentions && packedNote.mentions.some(id => meId === id)) {
|
||||
// 自分へのメンション
|
||||
hide = false;
|
||||
} else {
|
||||
@@ -62,14 +65,13 @@ export class NoteRepository extends Repository<Note> {
|
||||
}
|
||||
|
||||
if (hide) {
|
||||
packedNote.visibleUserIds = null;
|
||||
packedNote.visibleUserIds = undefined;
|
||||
packedNote.fileIds = [];
|
||||
packedNote.files = [];
|
||||
packedNote.text = null;
|
||||
packedNote.poll = null;
|
||||
packedNote.poll = undefined;
|
||||
packedNote.cw = null;
|
||||
packedNote.tags = [];
|
||||
packedNote.geo = null;
|
||||
packedNote.geo = undefined;
|
||||
packedNote.isHidden = true;
|
||||
}
|
||||
}
|
||||
@@ -92,7 +94,7 @@ export class NoteRepository extends Repository<Note> {
|
||||
detail?: boolean;
|
||||
skipHide?: boolean;
|
||||
}
|
||||
): Promise<Record<string, any>> {
|
||||
): Promise<PackedNote> {
|
||||
const opts = Object.assign({
|
||||
detail: true,
|
||||
skipHide: false
|
||||
@@ -159,9 +161,9 @@ export class NoteRepository extends Repository<Note> {
|
||||
|
||||
const reactionEmojis = unique(concat([note.emojis, Object.keys(note.reactions)]));
|
||||
|
||||
const packed = await rap({
|
||||
const packed = await awaitAll({
|
||||
id: note.id,
|
||||
createdAt: note.createdAt,
|
||||
createdAt: note.createdAt.toISOString(),
|
||||
app: note.appId ? Apps.pack(note.appId) : undefined,
|
||||
userId: note.userId,
|
||||
user: Users.pack(note.user || note.userId, meId),
|
||||
@@ -213,3 +215,127 @@ export class NoteRepository extends Repository<Note> {
|
||||
return packed;
|
||||
}
|
||||
}
|
||||
|
||||
export const packedNoteSchema = {
|
||||
type: types.object,
|
||||
optional: bool.false, nullable: bool.false,
|
||||
properties: {
|
||||
id: {
|
||||
type: types.string,
|
||||
optional: bool.false, nullable: bool.false,
|
||||
format: 'id',
|
||||
description: 'The unique identifier for this Note.',
|
||||
example: 'xxxxxxxxxx',
|
||||
},
|
||||
createdAt: {
|
||||
type: types.string,
|
||||
optional: bool.false, nullable: bool.false,
|
||||
format: 'date-time',
|
||||
description: 'The date that the Note was created on Misskey.'
|
||||
},
|
||||
text: {
|
||||
type: types.string,
|
||||
optional: bool.false, nullable: bool.true,
|
||||
},
|
||||
cw: {
|
||||
type: types.string,
|
||||
optional: bool.true, nullable: bool.true,
|
||||
},
|
||||
userId: {
|
||||
type: types.string,
|
||||
optional: bool.false, nullable: bool.false,
|
||||
format: 'id',
|
||||
},
|
||||
user: {
|
||||
type: types.object,
|
||||
ref: 'User',
|
||||
optional: bool.false, nullable: bool.false,
|
||||
},
|
||||
replyId: {
|
||||
type: types.string,
|
||||
optional: bool.true, nullable: bool.true,
|
||||
format: 'id',
|
||||
example: 'xxxxxxxxxx',
|
||||
},
|
||||
renoteId: {
|
||||
type: types.string,
|
||||
optional: bool.true, nullable: bool.true,
|
||||
format: 'id',
|
||||
example: 'xxxxxxxxxx',
|
||||
},
|
||||
reply: {
|
||||
type: types.object,
|
||||
optional: bool.true, nullable: bool.true,
|
||||
ref: 'Note'
|
||||
},
|
||||
renote: {
|
||||
type: types.object,
|
||||
optional: bool.true, nullable: bool.true,
|
||||
ref: 'Note'
|
||||
},
|
||||
viaMobile: {
|
||||
type: types.boolean,
|
||||
optional: bool.true, nullable: bool.false,
|
||||
},
|
||||
isHidden: {
|
||||
type: types.boolean,
|
||||
optional: bool.true, nullable: bool.false,
|
||||
},
|
||||
visibility: {
|
||||
type: types.string,
|
||||
optional: bool.false, nullable: bool.false,
|
||||
},
|
||||
mentions: {
|
||||
type: types.array,
|
||||
optional: bool.true, nullable: bool.false,
|
||||
items: {
|
||||
type: types.string,
|
||||
optional: bool.false, nullable: bool.false,
|
||||
format: 'id'
|
||||
}
|
||||
},
|
||||
visibleUserIds: {
|
||||
type: types.array,
|
||||
optional: bool.true, nullable: bool.false,
|
||||
items: {
|
||||
type: types.string,
|
||||
optional: bool.false, nullable: bool.false,
|
||||
format: 'id'
|
||||
}
|
||||
},
|
||||
fileIds: {
|
||||
type: types.array,
|
||||
optional: bool.true, nullable: bool.false,
|
||||
items: {
|
||||
type: types.string,
|
||||
optional: bool.false, nullable: bool.false,
|
||||
format: 'id'
|
||||
}
|
||||
},
|
||||
files: {
|
||||
type: types.array,
|
||||
optional: bool.true, nullable: bool.false,
|
||||
items: {
|
||||
type: types.object,
|
||||
optional: bool.false, nullable: bool.false,
|
||||
ref: 'DriveFile'
|
||||
}
|
||||
},
|
||||
tags: {
|
||||
type: types.array,
|
||||
optional: bool.true, nullable: bool.false,
|
||||
items: {
|
||||
type: types.string,
|
||||
optional: bool.false, nullable: bool.false,
|
||||
}
|
||||
},
|
||||
poll: {
|
||||
type: types.object,
|
||||
optional: bool.true, nullable: bool.true,
|
||||
},
|
||||
geo: {
|
||||
type: types.object,
|
||||
optional: bool.true, nullable: bool.true,
|
||||
},
|
||||
},
|
||||
};
|
||||
|
Reference in New Issue
Block a user