2019-04-07 14:50:36 +02:00
|
|
|
import { Entity, Index, JoinColumn, ManyToOne, Column, PrimaryColumn } from 'typeorm';
|
2022-02-27 03:07:39 +01:00
|
|
|
import { User } from './user.js';
|
|
|
|
import { id } from '../id.js';
|
|
|
|
import { Note } from './note.js';
|
|
|
|
import { FollowRequest } from './follow-request.js';
|
|
|
|
import { UserGroupInvitation } from './user-group-invitation.js';
|
|
|
|
import { AccessToken } from './access-token.js';
|
|
|
|
import { notificationTypes } from '@/types.js';
|
2019-04-07 14:50:36 +02:00
|
|
|
|
|
|
|
@Entity()
|
|
|
|
export class Notification {
|
|
|
|
@PrimaryColumn(id())
|
|
|
|
public id: string;
|
|
|
|
|
|
|
|
@Index()
|
|
|
|
@Column('timestamp with time zone', {
|
2021-12-09 15:58:30 +01:00
|
|
|
comment: 'The created date of the Notification.',
|
2019-04-07 14:50:36 +02:00
|
|
|
})
|
|
|
|
public createdAt: Date;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 通知の受信者
|
|
|
|
*/
|
|
|
|
@Index()
|
|
|
|
@Column({
|
|
|
|
...id(),
|
2021-12-09 15:58:30 +01:00
|
|
|
comment: 'The ID of recipient user of the Notification.',
|
2019-04-07 14:50:36 +02:00
|
|
|
})
|
|
|
|
public notifieeId: User['id'];
|
|
|
|
|
|
|
|
@ManyToOne(type => User, {
|
2021-12-09 15:58:30 +01:00
|
|
|
onDelete: 'CASCADE',
|
2019-04-07 14:50:36 +02:00
|
|
|
})
|
|
|
|
@JoinColumn()
|
|
|
|
public notifiee: User | null;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 通知の送信者(initiator)
|
|
|
|
*/
|
2020-03-28 10:07:41 +01:00
|
|
|
@Index()
|
2019-04-07 14:50:36 +02:00
|
|
|
@Column({
|
|
|
|
...id(),
|
2020-03-28 10:07:41 +01:00
|
|
|
nullable: true,
|
2021-12-09 15:58:30 +01:00
|
|
|
comment: 'The ID of sender user of the Notification.',
|
2019-04-07 14:50:36 +02:00
|
|
|
})
|
2020-03-28 10:07:41 +01:00
|
|
|
public notifierId: User['id'] | null;
|
2019-04-07 14:50:36 +02:00
|
|
|
|
|
|
|
@ManyToOne(type => User, {
|
2021-12-09 15:58:30 +01:00
|
|
|
onDelete: 'CASCADE',
|
2019-04-07 14:50:36 +02:00
|
|
|
})
|
|
|
|
@JoinColumn()
|
|
|
|
public notifier: User | null;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 通知の種類。
|
|
|
|
* follow - フォローされた
|
|
|
|
* mention - 投稿で自分が言及された
|
|
|
|
* reply - (自分または自分がWatchしている)投稿が返信された
|
|
|
|
* renote - (自分または自分がWatchしている)投稿がRenoteされた
|
|
|
|
* quote - (自分または自分がWatchしている)投稿が引用Renoteされた
|
|
|
|
* reaction - (自分または自分がWatchしている)投稿にリアクションされた
|
2022-03-06 08:06:27 +01:00
|
|
|
* pollVote - (自分または自分がWatchしている)投稿のアンケートに投票された
|
|
|
|
* pollEnded - 自分のアンケートもしくは自分が投票したアンケートが終了した
|
2020-01-29 20:37:25 +01:00
|
|
|
* receiveFollowRequest - フォローリクエストされた
|
|
|
|
* followRequestAccepted - 自分の送ったフォローリクエストが承認された
|
2020-02-12 18:17:54 +01:00
|
|
|
* groupInvited - グループに招待された
|
2020-03-28 10:07:41 +01:00
|
|
|
* app - アプリ通知
|
2019-04-07 14:50:36 +02:00
|
|
|
*/
|
2020-03-28 10:07:41 +01:00
|
|
|
@Index()
|
2020-01-29 20:37:25 +01:00
|
|
|
@Column('enum', {
|
2020-05-26 07:33:55 +02:00
|
|
|
enum: notificationTypes,
|
2021-12-09 15:58:30 +01:00
|
|
|
comment: 'The type of the Notification.',
|
2019-04-07 14:50:36 +02:00
|
|
|
})
|
2020-05-26 07:33:55 +02:00
|
|
|
public type: typeof notificationTypes[number];
|
2019-04-07 14:50:36 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 通知が読まれたかどうか
|
|
|
|
*/
|
2020-03-28 10:07:41 +01:00
|
|
|
@Index()
|
2019-04-07 14:50:36 +02:00
|
|
|
@Column('boolean', {
|
|
|
|
default: false,
|
2021-12-09 15:58:30 +01:00
|
|
|
comment: 'Whether the Notification is read.',
|
2019-04-07 14:50:36 +02:00
|
|
|
})
|
|
|
|
public isRead: boolean;
|
|
|
|
|
|
|
|
@Column({
|
|
|
|
...id(),
|
2021-12-09 15:58:30 +01:00
|
|
|
nullable: true,
|
2019-04-07 14:50:36 +02:00
|
|
|
})
|
|
|
|
public noteId: Note['id'] | null;
|
|
|
|
|
|
|
|
@ManyToOne(type => Note, {
|
2021-12-09 15:58:30 +01:00
|
|
|
onDelete: 'CASCADE',
|
2019-04-07 14:50:36 +02:00
|
|
|
})
|
|
|
|
@JoinColumn()
|
|
|
|
public note: Note | null;
|
|
|
|
|
2020-01-29 20:37:25 +01:00
|
|
|
@Column({
|
|
|
|
...id(),
|
2021-12-09 15:58:30 +01:00
|
|
|
nullable: true,
|
2020-01-29 20:37:25 +01:00
|
|
|
})
|
|
|
|
public followRequestId: FollowRequest['id'] | null;
|
|
|
|
|
|
|
|
@ManyToOne(type => FollowRequest, {
|
2021-12-09 15:58:30 +01:00
|
|
|
onDelete: 'CASCADE',
|
2020-01-29 20:37:25 +01:00
|
|
|
})
|
|
|
|
@JoinColumn()
|
|
|
|
public followRequest: FollowRequest | null;
|
|
|
|
|
2020-02-12 18:17:54 +01:00
|
|
|
@Column({
|
|
|
|
...id(),
|
2021-12-09 15:58:30 +01:00
|
|
|
nullable: true,
|
2020-02-12 18:17:54 +01:00
|
|
|
})
|
|
|
|
public userGroupInvitationId: UserGroupInvitation['id'] | null;
|
|
|
|
|
|
|
|
@ManyToOne(type => UserGroupInvitation, {
|
2021-12-09 15:58:30 +01:00
|
|
|
onDelete: 'CASCADE',
|
2020-02-12 18:17:54 +01:00
|
|
|
})
|
|
|
|
@JoinColumn()
|
|
|
|
public userGroupInvitation: UserGroupInvitation | null;
|
|
|
|
|
2019-04-07 14:50:36 +02:00
|
|
|
@Column('varchar', {
|
2021-12-09 15:58:30 +01:00
|
|
|
length: 128, nullable: true,
|
2019-04-07 14:50:36 +02:00
|
|
|
})
|
2020-03-28 10:07:41 +01:00
|
|
|
public reaction: string | null;
|
2019-04-07 14:50:36 +02:00
|
|
|
|
|
|
|
@Column('integer', {
|
2021-12-09 15:58:30 +01:00
|
|
|
nullable: true,
|
2019-04-07 14:50:36 +02:00
|
|
|
})
|
2020-03-28 10:07:41 +01:00
|
|
|
public choice: number | null;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* アプリ通知のbody
|
|
|
|
*/
|
|
|
|
@Column('varchar', {
|
2021-12-09 15:58:30 +01:00
|
|
|
length: 2048, nullable: true,
|
2020-03-28 10:07:41 +01:00
|
|
|
})
|
|
|
|
public customBody: string | null;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* アプリ通知のheader
|
|
|
|
* (省略時はアプリ名で表示されることを期待)
|
|
|
|
*/
|
|
|
|
@Column('varchar', {
|
2021-12-09 15:58:30 +01:00
|
|
|
length: 256, nullable: true,
|
2020-03-28 10:07:41 +01:00
|
|
|
})
|
|
|
|
public customHeader: string | null;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* アプリ通知のicon(URL)
|
|
|
|
* (省略時はアプリアイコンで表示されることを期待)
|
|
|
|
*/
|
|
|
|
@Column('varchar', {
|
2021-12-09 15:58:30 +01:00
|
|
|
length: 1024, nullable: true,
|
2020-03-28 10:07:41 +01:00
|
|
|
})
|
|
|
|
public customIcon: string | null;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* アプリ通知のアプリ(のトークン)
|
|
|
|
*/
|
|
|
|
@Index()
|
|
|
|
@Column({
|
|
|
|
...id(),
|
2021-12-09 15:58:30 +01:00
|
|
|
nullable: true,
|
2020-03-28 10:07:41 +01:00
|
|
|
})
|
|
|
|
public appAccessTokenId: AccessToken['id'] | null;
|
|
|
|
|
|
|
|
@ManyToOne(type => AccessToken, {
|
2021-12-09 15:58:30 +01:00
|
|
|
onDelete: 'CASCADE',
|
2020-03-28 10:07:41 +01:00
|
|
|
})
|
|
|
|
@JoinColumn()
|
|
|
|
public appAccessToken: AccessToken | null;
|
2019-04-07 14:50:36 +02:00
|
|
|
}
|