2023-01-13 04:40:33 +00:00
|
|
|
import {
|
|
|
|
Entity,
|
|
|
|
Index,
|
|
|
|
JoinColumn,
|
2024-03-17 11:56:54 +00:00
|
|
|
JoinTable,
|
2023-12-05 07:12:10 +00:00
|
|
|
Column,
|
2023-11-26 20:33:46 +00:00
|
|
|
PrimaryColumn,
|
2024-03-17 11:56:54 +00:00
|
|
|
ManyToMany,
|
2023-12-05 07:12:10 +00:00
|
|
|
ManyToOne,
|
2024-03-17 11:56:54 +00:00
|
|
|
OneToMany,
|
|
|
|
type Relation,
|
2023-01-13 04:40:33 +00:00
|
|
|
} from "typeorm";
|
2023-12-05 07:12:10 +00:00
|
|
|
import { User } from "./user.js";
|
2024-03-17 11:56:54 +00:00
|
|
|
import { DriveFile } from "./drive-file.js";
|
2023-11-26 20:33:46 +00:00
|
|
|
import { id } from "../id.js";
|
2023-12-05 07:12:10 +00:00
|
|
|
import { noteVisibilities } from "../../types.js";
|
2023-01-13 04:40:33 +00:00
|
|
|
import { Channel } from "./channel.js";
|
2024-03-17 11:56:54 +00:00
|
|
|
import { NoteFile } from "./note-file.js";
|
2019-04-07 12:50:36 +00:00
|
|
|
|
|
|
|
@Entity()
|
2023-05-29 16:31:02 +00:00
|
|
|
@Index("IDX_NOTE_TAGS", { synchronize: false })
|
|
|
|
@Index("IDX_NOTE_MENTIONS", { synchronize: false })
|
|
|
|
@Index("IDX_NOTE_VISIBLE_USER_IDS", { synchronize: false })
|
2019-04-07 12:50:36 +00:00
|
|
|
export class Note {
|
|
|
|
@PrimaryColumn(id())
|
|
|
|
public id: string;
|
|
|
|
|
|
|
|
@Index()
|
2024-04-06 19:50:21 +00:00
|
|
|
@Column("timestamp without time zone", {
|
2023-05-29 16:31:02 +00:00
|
|
|
comment: "The created date of the Note.",
|
2019-04-07 12:50:36 +00:00
|
|
|
})
|
|
|
|
public createdAt: Date;
|
|
|
|
|
|
|
|
@Index()
|
|
|
|
@Column({
|
|
|
|
...id(),
|
|
|
|
nullable: true,
|
2023-05-29 16:31:02 +00:00
|
|
|
comment: "The ID of reply target.",
|
2019-04-07 12:50:36 +00:00
|
|
|
})
|
2023-01-13 04:40:33 +00:00
|
|
|
public replyId: Note["id"] | null;
|
2019-04-07 12:50:36 +00:00
|
|
|
|
|
|
|
@Index()
|
|
|
|
@Column({
|
|
|
|
...id(),
|
|
|
|
nullable: true,
|
2023-05-29 16:31:02 +00:00
|
|
|
comment: "The ID of renote target.",
|
2019-04-07 12:50:36 +00:00
|
|
|
})
|
2023-01-13 04:40:33 +00:00
|
|
|
public renoteId: Note["id"] | null;
|
2019-04-07 12:50:36 +00:00
|
|
|
|
2021-10-31 06:30:22 +00:00
|
|
|
@Index()
|
2023-05-29 16:31:02 +00:00
|
|
|
@Column("varchar", {
|
|
|
|
length: 256,
|
|
|
|
nullable: true,
|
2021-10-31 06:30:22 +00:00
|
|
|
})
|
|
|
|
public threadId: string | null;
|
|
|
|
|
2024-03-01 12:39:13 +00:00
|
|
|
@Index() // USING pgroonga
|
2023-05-29 16:31:02 +00:00
|
|
|
@Column("text", {
|
2022-05-05 13:45:22 +00:00
|
|
|
nullable: true,
|
2019-04-07 12:50:36 +00:00
|
|
|
})
|
|
|
|
public text: string | null;
|
|
|
|
|
2023-09-22 01:29:33 +00:00
|
|
|
@Column("varchar", {
|
|
|
|
length: 10,
|
|
|
|
nullable: true,
|
|
|
|
})
|
|
|
|
public lang: string | null;
|
|
|
|
|
2023-05-29 16:31:02 +00:00
|
|
|
@Column("varchar", {
|
|
|
|
length: 256,
|
|
|
|
nullable: true,
|
2019-04-07 12:50:36 +00:00
|
|
|
})
|
|
|
|
public name: string | null;
|
|
|
|
|
2024-04-16 00:14:44 +00:00
|
|
|
@Index() // USING pgroonga
|
|
|
|
@Column("text", {
|
2023-05-29 16:31:02 +00:00
|
|
|
nullable: true,
|
2019-04-07 12:50:36 +00:00
|
|
|
})
|
|
|
|
public cw: string | null;
|
|
|
|
|
|
|
|
@Index()
|
|
|
|
@Column({
|
|
|
|
...id(),
|
2023-05-29 16:31:02 +00:00
|
|
|
comment: "The ID of author.",
|
2019-04-07 12:50:36 +00:00
|
|
|
})
|
2023-01-13 04:40:33 +00:00
|
|
|
public userId: User["id"];
|
2019-04-07 12:50:36 +00:00
|
|
|
|
2023-05-29 16:31:02 +00:00
|
|
|
@Column("boolean", {
|
2021-12-09 14:58:30 +00:00
|
|
|
default: false,
|
2019-04-07 12:50:36 +00:00
|
|
|
})
|
|
|
|
public localOnly: boolean;
|
|
|
|
|
2023-05-29 16:31:02 +00:00
|
|
|
@Column("smallint", {
|
2021-12-09 14:58:30 +00:00
|
|
|
default: 0,
|
2019-04-07 12:50:36 +00:00
|
|
|
})
|
|
|
|
public renoteCount: number;
|
|
|
|
|
2023-05-29 16:31:02 +00:00
|
|
|
@Column("smallint", {
|
2021-12-09 14:58:30 +00:00
|
|
|
default: 0,
|
2019-04-07 12:50:36 +00:00
|
|
|
})
|
|
|
|
public repliesCount: number;
|
|
|
|
|
2023-05-29 16:31:02 +00:00
|
|
|
@Column("jsonb", {
|
2021-12-09 14:58:30 +00:00
|
|
|
default: {},
|
2019-04-07 12:50:36 +00:00
|
|
|
})
|
|
|
|
public reactions: Record<string, number>;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* public ... 公開
|
|
|
|
* home ... ホームタイムライン(ユーザーページのタイムライン含む)のみに流す
|
2023-05-05 13:16:10 +00:00
|
|
|
* hidden ... only visible on profile (doesnt federate, like local only, but can be fetched via AP like home) <- for now only used for post imports
|
2019-04-07 12:50:36 +00:00
|
|
|
* followers ... フォロワーのみ
|
|
|
|
* specified ... visibleUserIds で指定したユーザーのみ
|
|
|
|
*/
|
2023-05-29 16:31:02 +00:00
|
|
|
@Column("enum", { enum: noteVisibilities })
|
2024-02-11 17:50:57 +00:00
|
|
|
public visibility: (typeof noteVisibilities)[number];
|
2019-04-07 12:50:36 +00:00
|
|
|
|
|
|
|
@Index({ unique: true })
|
2023-05-29 16:31:02 +00:00
|
|
|
@Column("varchar", {
|
|
|
|
length: 512,
|
|
|
|
nullable: true,
|
|
|
|
comment: "The URI of a note. it will be null when the note is local.",
|
2019-04-07 12:50:36 +00:00
|
|
|
})
|
|
|
|
public uri: string | null;
|
|
|
|
|
2023-05-29 16:31:02 +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.",
|
2020-04-02 12:59:14 +00:00
|
|
|
})
|
|
|
|
public url: string | null;
|
|
|
|
|
2023-05-29 16:31:02 +00:00
|
|
|
@Column("integer", {
|
|
|
|
default: 0,
|
|
|
|
select: false,
|
2019-04-07 12:50:36 +00:00
|
|
|
})
|
|
|
|
public score: number;
|
|
|
|
|
2024-03-17 06:26:27 +00:00
|
|
|
// FIXME: file id is not removed from this array even if the file is deleted
|
2024-03-17 11:56:54 +00:00
|
|
|
// TODO: drop this column and use note_files
|
2019-04-16 17:11:22 +00:00
|
|
|
@Index()
|
2019-04-07 12:50:36 +00:00
|
|
|
@Column({
|
|
|
|
...id(),
|
2023-05-29 16:31:02 +00:00
|
|
|
array: true,
|
|
|
|
default: "{}",
|
2019-04-07 12:50:36 +00:00
|
|
|
})
|
2023-01-13 04:40:33 +00:00
|
|
|
public fileIds: DriveFile["id"][];
|
2019-04-07 12:50:36 +00:00
|
|
|
|
2019-04-16 17:11:22 +00:00
|
|
|
@Index()
|
2023-05-29 16:31:02 +00:00
|
|
|
@Column("varchar", {
|
|
|
|
length: 256,
|
|
|
|
array: true,
|
|
|
|
default: "{}",
|
2019-04-07 12:50:36 +00:00
|
|
|
})
|
|
|
|
public attachedFileTypes: string[];
|
|
|
|
|
|
|
|
@Index()
|
|
|
|
@Column({
|
|
|
|
...id(),
|
2023-05-29 16:31:02 +00:00
|
|
|
array: true,
|
|
|
|
default: "{}",
|
2019-04-07 12:50:36 +00:00
|
|
|
})
|
2023-01-13 04:40:33 +00:00
|
|
|
public visibleUserIds: User["id"][];
|
2019-04-07 12:50:36 +00:00
|
|
|
|
|
|
|
@Index()
|
|
|
|
@Column({
|
|
|
|
...id(),
|
2023-05-29 16:31:02 +00:00
|
|
|
array: true,
|
|
|
|
default: "{}",
|
2019-04-07 12:50:36 +00:00
|
|
|
})
|
2023-01-13 04:40:33 +00:00
|
|
|
public mentions: User["id"][];
|
2019-04-07 12:50:36 +00:00
|
|
|
|
2024-03-17 18:29:19 +00:00
|
|
|
// FIXME: WHAT IS THIS
|
|
|
|
@Column("text", {
|
|
|
|
default: "[]",
|
|
|
|
})
|
|
|
|
public mentionedRemoteUsers: string;
|
|
|
|
|
2023-05-29 16:31:02 +00:00
|
|
|
@Column("varchar", {
|
|
|
|
length: 128,
|
|
|
|
array: true,
|
|
|
|
default: "{}",
|
2019-04-07 12:50:36 +00:00
|
|
|
})
|
|
|
|
public emojis: string[];
|
|
|
|
|
|
|
|
@Index()
|
2023-05-29 16:31:02 +00:00
|
|
|
@Column("varchar", {
|
|
|
|
length: 128,
|
|
|
|
array: true,
|
|
|
|
default: "{}",
|
2019-04-07 12:50:36 +00:00
|
|
|
})
|
|
|
|
public tags: string[];
|
|
|
|
|
2023-05-29 16:31:02 +00:00
|
|
|
@Column("boolean", {
|
2021-12-09 14:58:30 +00:00
|
|
|
default: false,
|
2019-04-07 12:50:36 +00:00
|
|
|
})
|
|
|
|
public hasPoll: boolean;
|
|
|
|
|
2020-08-18 13:44:21 +00:00
|
|
|
@Index()
|
|
|
|
@Column({
|
|
|
|
...id(),
|
2022-05-05 13:45:22 +00:00
|
|
|
nullable: true,
|
2023-05-29 16:31:02 +00:00
|
|
|
comment: "The ID of source channel.",
|
2020-08-18 13:44:21 +00:00
|
|
|
})
|
2023-01-13 04:40:33 +00:00
|
|
|
public channelId: Channel["id"] | null;
|
2020-08-18 13:44:21 +00:00
|
|
|
|
2024-04-11 12:56:40 +00:00
|
|
|
//#region Denormalized fields
|
|
|
|
@Index()
|
|
|
|
@Column("varchar", {
|
|
|
|
length: 512,
|
|
|
|
nullable: true,
|
|
|
|
comment: "[Denormalized]",
|
|
|
|
})
|
|
|
|
public userHost: string | null;
|
|
|
|
|
|
|
|
@Column({
|
|
|
|
...id(),
|
|
|
|
nullable: true,
|
|
|
|
comment: "[Denormalized]",
|
|
|
|
})
|
|
|
|
public replyUserId: User["id"] | null;
|
|
|
|
|
|
|
|
@Column("varchar", {
|
|
|
|
length: 512,
|
|
|
|
nullable: true,
|
|
|
|
comment: "[Denormalized]",
|
|
|
|
})
|
|
|
|
public replyUserHost: string | null;
|
|
|
|
|
|
|
|
@Column({
|
|
|
|
...id(),
|
|
|
|
nullable: true,
|
|
|
|
comment: "[Denormalized]",
|
|
|
|
})
|
|
|
|
public renoteUserId: User["id"] | null;
|
|
|
|
|
|
|
|
@Column("varchar", {
|
|
|
|
length: 512,
|
|
|
|
nullable: true,
|
|
|
|
comment: "[Denormalized]",
|
|
|
|
})
|
|
|
|
public renoteUserHost: string | null;
|
|
|
|
|
|
|
|
@Column("timestamp without time zone", {
|
|
|
|
nullable: true,
|
|
|
|
comment: "The updated date of the Note.",
|
|
|
|
})
|
|
|
|
public updatedAt: Date | null;
|
|
|
|
//#endregion
|
|
|
|
|
2024-03-17 11:56:54 +00:00
|
|
|
//#region Relations
|
|
|
|
@OneToMany(
|
|
|
|
() => NoteFile,
|
|
|
|
(noteFile: NoteFile) => noteFile.note,
|
|
|
|
)
|
|
|
|
public noteFiles: Relation<NoteFile[]>;
|
|
|
|
|
|
|
|
@ManyToMany(
|
|
|
|
() => DriveFile,
|
|
|
|
(file: DriveFile) => file.notes,
|
|
|
|
)
|
|
|
|
@JoinTable({
|
|
|
|
name: "note_file",
|
|
|
|
joinColumn: {
|
|
|
|
name: "noteId",
|
|
|
|
referencedColumnName: "id",
|
|
|
|
},
|
|
|
|
inverseJoinColumn: {
|
|
|
|
name: "fileId",
|
|
|
|
referencedColumnName: "id",
|
|
|
|
},
|
|
|
|
})
|
|
|
|
public files: Relation<DriveFile[]>;
|
|
|
|
|
|
|
|
@ManyToOne(() => Note, {
|
|
|
|
onDelete: "CASCADE",
|
2024-04-11 12:56:40 +00:00
|
|
|
nullable: true,
|
2024-03-17 11:56:54 +00:00
|
|
|
})
|
|
|
|
@JoinColumn()
|
2024-04-11 12:56:40 +00:00
|
|
|
public reply: Relation<Note | null>;
|
2024-03-17 11:56:54 +00:00
|
|
|
|
|
|
|
@ManyToOne(() => Note, {
|
|
|
|
onDelete: "CASCADE",
|
2024-04-11 12:56:40 +00:00
|
|
|
nullable: true,
|
2024-03-17 11:56:54 +00:00
|
|
|
})
|
|
|
|
@JoinColumn()
|
2024-04-11 12:56:40 +00:00
|
|
|
public renote: Relation<Note | null>;
|
2024-03-17 11:56:54 +00:00
|
|
|
|
|
|
|
@ManyToOne(() => Channel, {
|
2023-05-29 16:31:02 +00:00
|
|
|
onDelete: "CASCADE",
|
2024-04-11 12:56:40 +00:00
|
|
|
nullable: true,
|
2020-08-18 13:44:21 +00:00
|
|
|
})
|
|
|
|
@JoinColumn()
|
2024-04-11 12:56:40 +00:00
|
|
|
public channel: Relation<Channel | null>;
|
2020-08-18 13:44:21 +00:00
|
|
|
|
2024-03-17 11:56:54 +00:00
|
|
|
@ManyToOne(() => User, {
|
|
|
|
onDelete: "CASCADE",
|
2024-04-11 12:56:40 +00:00
|
|
|
nullable: true,
|
2024-03-17 11:56:54 +00:00
|
|
|
})
|
|
|
|
@JoinColumn()
|
2024-04-11 12:56:40 +00:00
|
|
|
public user: Relation<User | null>;
|
2024-03-17 11:56:54 +00:00
|
|
|
//#endregion Relations
|
|
|
|
|
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
|
|
|
}
|
2024-03-17 18:29:19 +00:00
|
|
|
|
|
|
|
export type IMentionedRemoteUsers = {
|
|
|
|
uri: string;
|
|
|
|
url?: string;
|
|
|
|
username: string;
|
|
|
|
host: string;
|
|
|
|
}[];
|