2023-07-27 14:31:52 +09:00
|
|
|
/*
|
2024-02-14 00:59:27 +09:00
|
|
|
* SPDX-FileCopyrightText: syuilo and misskey-project
|
2023-07-27 14:31:52 +09:00
|
|
|
* SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
*/
|
|
|
|
|
2019-04-07 21:50:36 +09:00
|
|
|
import { PrimaryColumn, Entity, Index, JoinColumn, Column, OneToOne } from 'typeorm';
|
2023-09-20 11:40:17 +09:00
|
|
|
import { noteVisibilities } from '@/types.js';
|
2023-09-20 11:33:36 +09:00
|
|
|
import { id } from './util/id.js';
|
2023-08-16 17:51:28 +09:00
|
|
|
import { MiNote } from './Note.js';
|
|
|
|
import type { MiUser } from './User.js';
|
2024-05-20 18:08:20 +09:00
|
|
|
import type { MiChannel } from "@/models/Channel.js";
|
2019-04-07 21:50:36 +09:00
|
|
|
|
2023-08-16 17:51:28 +09:00
|
|
|
@Entity('poll')
|
|
|
|
export class MiPoll {
|
2019-04-07 21:50:36 +09:00
|
|
|
@PrimaryColumn(id())
|
2023-08-16 17:51:28 +09:00
|
|
|
public noteId: MiNote['id'];
|
2019-04-07 21:50:36 +09:00
|
|
|
|
2023-08-16 17:51:28 +09:00
|
|
|
@OneToOne(type => MiNote, {
|
2021-12-09 23:58:30 +09:00
|
|
|
onDelete: 'CASCADE',
|
2019-04-07 21:50:36 +09:00
|
|
|
})
|
|
|
|
@JoinColumn()
|
2023-08-16 17:51:28 +09:00
|
|
|
public note: MiNote | null;
|
2019-04-07 21:50:36 +09:00
|
|
|
|
|
|
|
@Column('timestamp with time zone', {
|
2021-12-09 23:58:30 +09:00
|
|
|
nullable: true,
|
2019-04-07 21:50:36 +09:00
|
|
|
})
|
|
|
|
public expiresAt: Date | null;
|
|
|
|
|
|
|
|
@Column('boolean')
|
|
|
|
public multiple: boolean;
|
|
|
|
|
|
|
|
@Column('varchar', {
|
2023-01-10 16:41:38 +09:00
|
|
|
length: 256, array: true, default: '{}',
|
2019-04-07 21:50:36 +09:00
|
|
|
})
|
|
|
|
public choices: string[];
|
|
|
|
|
|
|
|
@Column('integer', {
|
|
|
|
array: true,
|
|
|
|
})
|
|
|
|
public votes: number[];
|
|
|
|
|
|
|
|
//#region Denormalized fields
|
|
|
|
@Column('enum', {
|
2020-05-26 14:33:55 +09:00
|
|
|
enum: noteVisibilities,
|
2021-12-09 23:58:30 +09:00
|
|
|
comment: '[Denormalized]',
|
2019-04-07 21:50:36 +09:00
|
|
|
})
|
2020-05-26 14:33:55 +09:00
|
|
|
public noteVisibility: typeof noteVisibilities[number];
|
2019-04-07 21:50:36 +09:00
|
|
|
|
|
|
|
@Index()
|
|
|
|
@Column({
|
|
|
|
...id(),
|
2021-12-09 23:58:30 +09:00
|
|
|
comment: '[Denormalized]',
|
2019-04-07 21:50:36 +09:00
|
|
|
})
|
2023-08-16 17:51:28 +09:00
|
|
|
public userId: MiUser['id'];
|
2019-04-07 21:50:36 +09:00
|
|
|
|
|
|
|
@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;
|
2024-05-20 18:08:20 +09:00
|
|
|
|
|
|
|
@Index()
|
|
|
|
@Column({
|
|
|
|
...id(),
|
|
|
|
nullable: true,
|
|
|
|
comment: '[Denormalized]',
|
|
|
|
})
|
|
|
|
public channelId: MiChannel['id'] | null;
|
2019-04-07 21:50:36 +09:00
|
|
|
//#endregion
|
2019-04-12 01:30:10 +09:00
|
|
|
|
2023-08-16 17:51:28 +09:00
|
|
|
constructor(data: Partial<MiPoll>) {
|
2019-04-12 01:30:10 +09:00
|
|
|
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 IPoll = {
|
|
|
|
choices: string[];
|
|
|
|
votes?: number[];
|
|
|
|
multiple: boolean;
|
2019-04-13 01:43:22 +09:00
|
|
|
expiresAt: Date | null;
|
2019-04-07 21:50:36 +09:00
|
|
|
};
|