2019-04-07 12:50:36 +00:00
|
|
|
import { Entity, Index, JoinColumn, Column, PrimaryColumn, ManyToOne } from 'typeorm';
|
|
|
|
import { User } from './user';
|
|
|
|
import { DriveFile } from './drive-file';
|
|
|
|
import { id } from '../id';
|
2020-05-26 05:33:55 +00:00
|
|
|
import { noteVisibilities } from '../../types';
|
|
|
|
|
2019-04-07 12:50:36 +00:00
|
|
|
|
|
|
|
@Entity()
|
2020-02-01 07:57:12 +00:00
|
|
|
@Index('IDX_NOTE_TAGS', { synchronize: false })
|
2019-04-07 12:50:36 +00:00
|
|
|
export class Note {
|
|
|
|
@PrimaryColumn(id())
|
|
|
|
public id: string;
|
|
|
|
|
|
|
|
@Index()
|
|
|
|
@Column('timestamp with time zone', {
|
|
|
|
comment: 'The created date of the Note.'
|
|
|
|
})
|
|
|
|
public createdAt: Date;
|
|
|
|
|
|
|
|
@Index()
|
|
|
|
@Column({
|
|
|
|
...id(),
|
|
|
|
nullable: true,
|
|
|
|
comment: 'The ID of reply target.'
|
|
|
|
})
|
|
|
|
public replyId: Note['id'] | null;
|
|
|
|
|
|
|
|
@ManyToOne(type => Note, {
|
|
|
|
onDelete: 'CASCADE'
|
|
|
|
})
|
|
|
|
@JoinColumn()
|
|
|
|
public reply: Note | null;
|
|
|
|
|
|
|
|
@Index()
|
|
|
|
@Column({
|
|
|
|
...id(),
|
|
|
|
nullable: true,
|
|
|
|
comment: 'The ID of renote target.'
|
|
|
|
})
|
|
|
|
public renoteId: Note['id'] | null;
|
|
|
|
|
|
|
|
@ManyToOne(type => Note, {
|
|
|
|
onDelete: 'CASCADE'
|
|
|
|
})
|
|
|
|
@JoinColumn()
|
|
|
|
public renote: Note | null;
|
|
|
|
|
2019-05-14 03:04:40 +00:00
|
|
|
@Column('varchar', {
|
|
|
|
length: 8192, nullable: true
|
2019-04-07 12:50:36 +00:00
|
|
|
})
|
|
|
|
public text: string | null;
|
|
|
|
|
|
|
|
@Column('varchar', {
|
|
|
|
length: 256, nullable: true
|
|
|
|
})
|
|
|
|
public name: string | null;
|
|
|
|
|
|
|
|
@Column('varchar', {
|
|
|
|
length: 512, nullable: true
|
|
|
|
})
|
|
|
|
public cw: string | null;
|
|
|
|
|
|
|
|
@Index()
|
|
|
|
@Column({
|
|
|
|
...id(),
|
|
|
|
comment: 'The ID of author.'
|
|
|
|
})
|
|
|
|
public userId: User['id'];
|
|
|
|
|
|
|
|
@ManyToOne(type => User, {
|
|
|
|
onDelete: 'CASCADE'
|
|
|
|
})
|
|
|
|
@JoinColumn()
|
|
|
|
public user: User | null;
|
|
|
|
|
|
|
|
@Column('boolean', {
|
|
|
|
default: false
|
|
|
|
})
|
|
|
|
public viaMobile: boolean;
|
|
|
|
|
|
|
|
@Column('boolean', {
|
|
|
|
default: false
|
|
|
|
})
|
|
|
|
public localOnly: boolean;
|
|
|
|
|
2019-04-16 17:12:15 +00:00
|
|
|
@Column('smallint', {
|
2019-04-07 12:50:36 +00:00
|
|
|
default: 0
|
|
|
|
})
|
|
|
|
public renoteCount: number;
|
|
|
|
|
2019-04-16 17:12:15 +00:00
|
|
|
@Column('smallint', {
|
2019-04-07 12:50:36 +00:00
|
|
|
default: 0
|
|
|
|
})
|
|
|
|
public repliesCount: number;
|
|
|
|
|
|
|
|
@Column('jsonb', {
|
|
|
|
default: {}
|
|
|
|
})
|
|
|
|
public reactions: Record<string, number>;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* public ... 公開
|
|
|
|
* home ... ホームタイムライン(ユーザーページのタイムライン含む)のみに流す
|
|
|
|
* followers ... フォロワーのみ
|
|
|
|
* specified ... visibleUserIds で指定したユーザーのみ
|
|
|
|
*/
|
2020-05-26 05:33:55 +00:00
|
|
|
@Column('enum', { enum: noteVisibilities })
|
|
|
|
public visibility: typeof noteVisibilities[number];
|
2019-04-07 12:50:36 +00:00
|
|
|
|
|
|
|
@Index({ unique: true })
|
|
|
|
@Column('varchar', {
|
2019-04-11 10:03:49 +00:00
|
|
|
length: 512, nullable: true,
|
2019-04-07 12:50:36 +00:00
|
|
|
comment: 'The URI of a note. it will be null when the note is local.'
|
|
|
|
})
|
|
|
|
public uri: string | null;
|
|
|
|
|
2020-04-02 12:59:14 +00:00
|
|
|
@Column('varchar', {
|
|
|
|
length: 512, nullable: true,
|
|
|
|
comment: 'The human readable url of a note. it will be null when the note is local.'
|
|
|
|
})
|
|
|
|
public url: string | null;
|
|
|
|
|
2019-04-07 12:50:36 +00:00
|
|
|
@Column('integer', {
|
2019-04-14 11:26:47 +00:00
|
|
|
default: 0, select: false
|
2019-04-07 12:50:36 +00:00
|
|
|
})
|
|
|
|
public score: number;
|
|
|
|
|
2019-04-16 17:11:22 +00:00
|
|
|
@Index()
|
2019-04-07 12:50:36 +00:00
|
|
|
@Column({
|
|
|
|
...id(),
|
|
|
|
array: true, default: '{}'
|
|
|
|
})
|
|
|
|
public fileIds: DriveFile['id'][];
|
|
|
|
|
2019-04-16 17:11:22 +00:00
|
|
|
@Index()
|
2019-04-07 12:50:36 +00:00
|
|
|
@Column('varchar', {
|
|
|
|
length: 256, array: true, default: '{}'
|
|
|
|
})
|
|
|
|
public attachedFileTypes: string[];
|
|
|
|
|
|
|
|
@Index()
|
|
|
|
@Column({
|
|
|
|
...id(),
|
|
|
|
array: true, default: '{}'
|
|
|
|
})
|
|
|
|
public visibleUserIds: User['id'][];
|
|
|
|
|
|
|
|
@Index()
|
|
|
|
@Column({
|
|
|
|
...id(),
|
|
|
|
array: true, default: '{}'
|
|
|
|
})
|
|
|
|
public mentions: User['id'][];
|
|
|
|
|
|
|
|
@Column('text', {
|
|
|
|
default: '[]'
|
|
|
|
})
|
|
|
|
public mentionedRemoteUsers: string;
|
|
|
|
|
|
|
|
@Column('varchar', {
|
|
|
|
length: 128, array: true, default: '{}'
|
|
|
|
})
|
|
|
|
public emojis: string[];
|
|
|
|
|
|
|
|
@Index()
|
|
|
|
@Column('varchar', {
|
|
|
|
length: 128, array: true, default: '{}'
|
|
|
|
})
|
|
|
|
public tags: string[];
|
|
|
|
|
|
|
|
@Column('boolean', {
|
|
|
|
default: false
|
|
|
|
})
|
|
|
|
public hasPoll: boolean;
|
|
|
|
|
|
|
|
//#region Denormalized fields
|
|
|
|
@Index()
|
|
|
|
@Column('varchar', {
|
|
|
|
length: 128, nullable: true,
|
|
|
|
comment: '[Denormalized]'
|
|
|
|
})
|
|
|
|
public userHost: string | null;
|
|
|
|
|
|
|
|
@Column({
|
|
|
|
...id(),
|
|
|
|
nullable: true,
|
|
|
|
comment: '[Denormalized]'
|
|
|
|
})
|
|
|
|
public replyUserId: User['id'] | null;
|
|
|
|
|
|
|
|
@Column('varchar', {
|
|
|
|
length: 128, nullable: true,
|
|
|
|
comment: '[Denormalized]'
|
|
|
|
})
|
|
|
|
public replyUserHost: string | null;
|
|
|
|
|
|
|
|
@Column({
|
|
|
|
...id(),
|
|
|
|
nullable: true,
|
|
|
|
comment: '[Denormalized]'
|
|
|
|
})
|
|
|
|
public renoteUserId: User['id'] | null;
|
|
|
|
|
|
|
|
@Column('varchar', {
|
|
|
|
length: 128, nullable: true,
|
|
|
|
comment: '[Denormalized]'
|
|
|
|
})
|
|
|
|
public renoteUserHost: string | null;
|
|
|
|
//#endregion
|
2019-04-11 16:30:10 +00: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 12:50:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export type IMentionedRemoteUsers = {
|
|
|
|
uri: string;
|
2019-10-31 20:43:54 +00:00
|
|
|
url?: string;
|
2019-04-07 12:50:36 +00:00
|
|
|
username: string;
|
|
|
|
host: string;
|
|
|
|
}[];
|