2023-07-27 00:31:52 -05:00
|
|
|
/*
|
2024-02-13 09:59:27 -06:00
|
|
|
* SPDX-FileCopyrightText: syuilo and misskey-project
|
2023-07-27 00:31:52 -05:00
|
|
|
* SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
*/
|
|
|
|
|
2019-04-07 07:50:36 -05:00
|
|
|
import { Entity, Index, JoinColumn, Column, PrimaryColumn, ManyToOne } from 'typeorm';
|
2023-09-19 21:40:17 -05:00
|
|
|
import { noteVisibilities } from '@/types.js';
|
2023-09-19 21:33:36 -05:00
|
|
|
import { id } from './util/id.js';
|
2023-08-16 03:51:28 -05:00
|
|
|
import { MiUser } from './User.js';
|
|
|
|
import { MiChannel } from './Channel.js';
|
|
|
|
import type { MiDriveFile } from './DriveFile.js';
|
2019-04-07 07:50:36 -05:00
|
|
|
|
2023-08-16 03:51:28 -05:00
|
|
|
@Entity('note')
|
|
|
|
export class MiNote {
|
2019-04-07 07:50:36 -05:00
|
|
|
@PrimaryColumn(id())
|
|
|
|
public id: string;
|
|
|
|
|
|
|
|
@Index()
|
|
|
|
@Column({
|
|
|
|
...id(),
|
|
|
|
nullable: true,
|
2021-12-09 08:58:30 -06:00
|
|
|
comment: 'The ID of reply target.',
|
2019-04-07 07:50:36 -05:00
|
|
|
})
|
2023-08-16 03:51:28 -05:00
|
|
|
public replyId: MiNote['id'] | null;
|
2019-04-07 07:50:36 -05:00
|
|
|
|
2023-08-16 03:51:28 -05:00
|
|
|
@ManyToOne(type => MiNote, {
|
2021-12-09 08:58:30 -06:00
|
|
|
onDelete: 'CASCADE',
|
2019-04-07 07:50:36 -05:00
|
|
|
})
|
|
|
|
@JoinColumn()
|
2023-08-16 03:51:28 -05:00
|
|
|
public reply: MiNote | null;
|
2019-04-07 07:50:36 -05:00
|
|
|
|
|
|
|
@Index()
|
|
|
|
@Column({
|
|
|
|
...id(),
|
|
|
|
nullable: true,
|
2021-12-09 08:58:30 -06:00
|
|
|
comment: 'The ID of renote target.',
|
2019-04-07 07:50:36 -05:00
|
|
|
})
|
2023-08-16 03:51:28 -05:00
|
|
|
public renoteId: MiNote['id'] | null;
|
2019-04-07 07:50:36 -05:00
|
|
|
|
2023-08-16 03:51:28 -05:00
|
|
|
@ManyToOne(type => MiNote, {
|
2021-12-09 08:58:30 -06:00
|
|
|
onDelete: 'CASCADE',
|
2019-04-07 07:50:36 -05:00
|
|
|
})
|
|
|
|
@JoinColumn()
|
2023-08-16 03:51:28 -05:00
|
|
|
public renote: MiNote | null;
|
2019-04-07 07:50:36 -05:00
|
|
|
|
2021-10-31 01:30:22 -05:00
|
|
|
@Index()
|
|
|
|
@Column('varchar', {
|
2021-12-09 08:58:30 -06:00
|
|
|
length: 256, nullable: true,
|
2021-10-31 01:30:22 -05:00
|
|
|
})
|
|
|
|
public threadId: string | null;
|
|
|
|
|
2022-12-24 23:22:23 -06:00
|
|
|
// TODO: varcharにしたい
|
2022-05-05 08:45:22 -05:00
|
|
|
@Column('text', {
|
|
|
|
nullable: true,
|
2019-04-07 07:50:36 -05:00
|
|
|
})
|
|
|
|
public text: string | null;
|
|
|
|
|
|
|
|
@Column('varchar', {
|
2021-12-09 08:58:30 -06:00
|
|
|
length: 256, nullable: true,
|
2019-04-07 07:50:36 -05:00
|
|
|
})
|
|
|
|
public name: string | null;
|
|
|
|
|
|
|
|
@Column('varchar', {
|
2021-12-09 08:58:30 -06:00
|
|
|
length: 512, nullable: true,
|
2019-04-07 07:50:36 -05:00
|
|
|
})
|
|
|
|
public cw: string | null;
|
|
|
|
|
|
|
|
@Index()
|
|
|
|
@Column({
|
|
|
|
...id(),
|
2021-12-09 08:58:30 -06:00
|
|
|
comment: 'The ID of author.',
|
2019-04-07 07:50:36 -05:00
|
|
|
})
|
2023-08-16 03:51:28 -05:00
|
|
|
public userId: MiUser['id'];
|
2019-04-07 07:50:36 -05:00
|
|
|
|
2023-08-16 03:51:28 -05:00
|
|
|
@ManyToOne(type => MiUser, {
|
2021-12-09 08:58:30 -06:00
|
|
|
onDelete: 'CASCADE',
|
2019-04-07 07:50:36 -05:00
|
|
|
})
|
|
|
|
@JoinColumn()
|
2023-08-16 03:51:28 -05:00
|
|
|
public user: MiUser | null;
|
2019-04-07 07:50:36 -05:00
|
|
|
|
|
|
|
@Column('boolean', {
|
2021-12-09 08:58:30 -06:00
|
|
|
default: false,
|
2019-04-07 07:50:36 -05:00
|
|
|
})
|
|
|
|
public localOnly: boolean;
|
|
|
|
|
2023-03-07 17:56:47 -06:00
|
|
|
@Column('varchar', {
|
|
|
|
length: 64, nullable: true,
|
|
|
|
})
|
2023-05-18 19:43:38 -05:00
|
|
|
public reactionAcceptance: 'likeOnly' | 'likeOnlyForRemote' | 'nonSensitiveOnly' | 'nonSensitiveOnlyForLocalLikeOnlyForRemote' | null;
|
2023-03-07 17:56:47 -06:00
|
|
|
|
2019-04-16 12:12:15 -05:00
|
|
|
@Column('smallint', {
|
2021-12-09 08:58:30 -06:00
|
|
|
default: 0,
|
2019-04-07 07:50:36 -05:00
|
|
|
})
|
|
|
|
public renoteCount: number;
|
|
|
|
|
2019-04-16 12:12:15 -05:00
|
|
|
@Column('smallint', {
|
2021-12-09 08:58:30 -06:00
|
|
|
default: 0,
|
2019-04-07 07:50:36 -05:00
|
|
|
})
|
|
|
|
public repliesCount: number;
|
|
|
|
|
2023-09-16 20:55:26 -05:00
|
|
|
@Column('smallint', {
|
|
|
|
default: 0,
|
|
|
|
})
|
|
|
|
public clippedCount: number;
|
|
|
|
|
2019-04-07 07:50:36 -05:00
|
|
|
@Column('jsonb', {
|
2021-12-09 08:58:30 -06:00
|
|
|
default: {},
|
2019-04-07 07:50:36 -05:00
|
|
|
})
|
|
|
|
public reactions: Record<string, number>;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* public ... 公開
|
|
|
|
* home ... ホームタイムライン(ユーザーページのタイムライン含む)のみに流す
|
|
|
|
* followers ... フォロワーのみ
|
|
|
|
* specified ... visibleUserIds で指定したユーザーのみ
|
|
|
|
*/
|
2020-05-26 00:33:55 -05:00
|
|
|
@Column('enum', { enum: noteVisibilities })
|
|
|
|
public visibility: typeof noteVisibilities[number];
|
2019-04-07 07:50:36 -05:00
|
|
|
|
|
|
|
@Index({ unique: true })
|
|
|
|
@Column('varchar', {
|
2019-04-11 05:03:49 -05:00
|
|
|
length: 512, nullable: true,
|
2021-12-09 08:58:30 -06:00
|
|
|
comment: 'The URI of a note. it will be null when the note is local.',
|
2019-04-07 07:50:36 -05:00
|
|
|
})
|
|
|
|
public uri: string | null;
|
|
|
|
|
2020-04-02 07:59:14 -05:00
|
|
|
@Column('varchar', {
|
|
|
|
length: 512, nullable: true,
|
2021-12-09 08:58:30 -06:00
|
|
|
comment: 'The human readable url of a note. it will be null when the note is local.',
|
2020-04-02 07:59:14 -05:00
|
|
|
})
|
|
|
|
public url: string | null;
|
|
|
|
|
2024-01-14 17:19:27 -06:00
|
|
|
@Index('IDX_NOTE_FILE_IDS', { synchronize: false })
|
2019-04-07 07:50:36 -05:00
|
|
|
@Column({
|
|
|
|
...id(),
|
2021-12-09 08:58:30 -06:00
|
|
|
array: true, default: '{}',
|
2019-04-07 07:50:36 -05:00
|
|
|
})
|
2023-08-16 03:51:28 -05:00
|
|
|
public fileIds: MiDriveFile['id'][];
|
2019-04-07 07:50:36 -05:00
|
|
|
|
|
|
|
@Column('varchar', {
|
2021-12-09 08:58:30 -06:00
|
|
|
length: 256, array: true, default: '{}',
|
2019-04-07 07:50:36 -05:00
|
|
|
})
|
|
|
|
public attachedFileTypes: string[];
|
|
|
|
|
2024-01-14 17:19:27 -06:00
|
|
|
@Index('IDX_NOTE_VISIBLE_USER_IDS', { synchronize: false })
|
2019-04-07 07:50:36 -05:00
|
|
|
@Column({
|
|
|
|
...id(),
|
2021-12-09 08:58:30 -06:00
|
|
|
array: true, default: '{}',
|
2019-04-07 07:50:36 -05:00
|
|
|
})
|
2023-08-16 03:51:28 -05:00
|
|
|
public visibleUserIds: MiUser['id'][];
|
2019-04-07 07:50:36 -05:00
|
|
|
|
2024-01-14 17:19:27 -06:00
|
|
|
@Index('IDX_NOTE_MENTIONS', { synchronize: false })
|
2019-04-07 07:50:36 -05:00
|
|
|
@Column({
|
|
|
|
...id(),
|
2021-12-09 08:58:30 -06:00
|
|
|
array: true, default: '{}',
|
2019-04-07 07:50:36 -05:00
|
|
|
})
|
2023-08-16 03:51:28 -05:00
|
|
|
public mentions: MiUser['id'][];
|
2019-04-07 07:50:36 -05:00
|
|
|
|
|
|
|
@Column('text', {
|
2021-12-09 08:58:30 -06:00
|
|
|
default: '[]',
|
2019-04-07 07:50:36 -05:00
|
|
|
})
|
|
|
|
public mentionedRemoteUsers: string;
|
|
|
|
|
2023-10-18 19:20:19 -05:00
|
|
|
@Column('varchar', {
|
|
|
|
length: 1024, array: true, default: '{}',
|
|
|
|
})
|
|
|
|
public reactionAndUserPairCache: string[];
|
|
|
|
|
2019-04-07 07:50:36 -05:00
|
|
|
@Column('varchar', {
|
2021-12-09 08:58:30 -06:00
|
|
|
length: 128, array: true, default: '{}',
|
2019-04-07 07:50:36 -05:00
|
|
|
})
|
|
|
|
public emojis: string[];
|
|
|
|
|
2024-01-14 17:19:27 -06:00
|
|
|
@Index('IDX_NOTE_TAGS', { synchronize: false })
|
2019-04-07 07:50:36 -05:00
|
|
|
@Column('varchar', {
|
2021-12-09 08:58:30 -06:00
|
|
|
length: 128, array: true, default: '{}',
|
2019-04-07 07:50:36 -05:00
|
|
|
})
|
|
|
|
public tags: string[];
|
|
|
|
|
|
|
|
@Column('boolean', {
|
2021-12-09 08:58:30 -06:00
|
|
|
default: false,
|
2019-04-07 07:50:36 -05:00
|
|
|
})
|
|
|
|
public hasPoll: boolean;
|
|
|
|
|
2020-08-18 08:44:21 -05:00
|
|
|
@Index()
|
|
|
|
@Column({
|
|
|
|
...id(),
|
2022-05-05 08:45:22 -05:00
|
|
|
nullable: true,
|
2021-12-09 08:58:30 -06:00
|
|
|
comment: 'The ID of source channel.',
|
2020-08-18 08:44:21 -05:00
|
|
|
})
|
2023-08-16 03:51:28 -05:00
|
|
|
public channelId: MiChannel['id'] | null;
|
2020-08-18 08:44:21 -05:00
|
|
|
|
2023-08-16 03:51:28 -05:00
|
|
|
@ManyToOne(type => MiChannel, {
|
2021-12-09 08:58:30 -06:00
|
|
|
onDelete: 'CASCADE',
|
2020-08-18 08:44:21 -05:00
|
|
|
})
|
|
|
|
@JoinColumn()
|
2023-08-16 03:51:28 -05:00
|
|
|
public channel: MiChannel | null;
|
2020-08-18 08:44:21 -05:00
|
|
|
|
2019-04-07 07:50:36 -05:00
|
|
|
//#region Denormalized fields
|
|
|
|
@Index()
|
|
|
|
@Column('varchar', {
|
|
|
|
length: 128, nullable: true,
|
2021-12-09 08:58:30 -06:00
|
|
|
comment: '[Denormalized]',
|
2019-04-07 07:50:36 -05:00
|
|
|
})
|
|
|
|
public userHost: string | null;
|
|
|
|
|
|
|
|
@Column({
|
|
|
|
...id(),
|
|
|
|
nullable: true,
|
2021-12-09 08:58:30 -06:00
|
|
|
comment: '[Denormalized]',
|
2019-04-07 07:50:36 -05:00
|
|
|
})
|
2023-08-16 03:51:28 -05:00
|
|
|
public replyUserId: MiUser['id'] | null;
|
2019-04-07 07:50:36 -05:00
|
|
|
|
|
|
|
@Column('varchar', {
|
|
|
|
length: 128, nullable: true,
|
2021-12-09 08:58:30 -06:00
|
|
|
comment: '[Denormalized]',
|
2019-04-07 07:50:36 -05:00
|
|
|
})
|
|
|
|
public replyUserHost: string | null;
|
|
|
|
|
|
|
|
@Column({
|
|
|
|
...id(),
|
|
|
|
nullable: true,
|
2021-12-09 08:58:30 -06:00
|
|
|
comment: '[Denormalized]',
|
2019-04-07 07:50:36 -05:00
|
|
|
})
|
2023-08-16 03:51:28 -05:00
|
|
|
public renoteUserId: MiUser['id'] | null;
|
2019-04-07 07:50:36 -05:00
|
|
|
|
|
|
|
@Column('varchar', {
|
|
|
|
length: 128, nullable: true,
|
2021-12-09 08:58:30 -06:00
|
|
|
comment: '[Denormalized]',
|
2019-04-07 07:50:36 -05:00
|
|
|
})
|
|
|
|
public renoteUserHost: string | null;
|
|
|
|
//#endregion
|
2019-04-11 11:30:10 -05:00
|
|
|
|
2023-08-16 03:51:28 -05:00
|
|
|
constructor(data: Partial<MiNote>) {
|
2019-04-11 11:30:10 -05:00
|
|
|
if (data == null) return;
|
|
|
|
|
|
|
|
for (const [k, v] of Object.entries(data)) {
|
|
|
|
(this as any)[k] = v;
|
|
|
|
}
|
|
|
|
}
|
2019-04-07 07:50:36 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
export type IMentionedRemoteUsers = {
|
|
|
|
uri: string;
|
2019-10-31 15:43:54 -05:00
|
|
|
url?: string;
|
2019-04-07 07:50:36 -05:00
|
|
|
username: string;
|
|
|
|
host: string;
|
|
|
|
}[];
|