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