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