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