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