diff options
| author | syuilo <syuilotan@yahoo.co.jp> | 2020-03-28 18:07:41 +0900 |
|---|---|---|
| committer | syuilo <syuilotan@yahoo.co.jp> | 2020-03-28 18:07:41 +0900 |
| commit | 614a1d74ddf388dcb82f69722c96696ad530602d (patch) | |
| tree | faf2d14d1d82ea321080ebb677d8c402460c9a5b /src/models | |
| parent | Add i/apps private API (diff) | |
| download | misskey-614a1d74ddf388dcb82f69722c96696ad530602d.tar.gz misskey-614a1d74ddf388dcb82f69722c96696ad530602d.tar.bz2 misskey-614a1d74ddf388dcb82f69722c96696ad530602d.zip | |
Resolve #6192
Diffstat (limited to 'src/models')
| -rw-r--r-- | src/models/entities/notification.ts | 58 | ||||
| -rw-r--r-- | src/models/repositories/notification.ts | 10 |
2 files changed, 61 insertions, 7 deletions
diff --git a/src/models/entities/notification.ts b/src/models/entities/notification.ts index cd3fe9b01e..565645a5d6 100644 --- a/src/models/entities/notification.ts +++ b/src/models/entities/notification.ts @@ -4,6 +4,7 @@ import { id } from '../id'; import { Note } from './note'; import { FollowRequest } from './follow-request'; import { UserGroupInvitation } from './user-group-invitation'; +import { AccessToken } from './access-token'; @Entity() export class Notification { @@ -35,11 +36,13 @@ export class Notification { /** * 通知の送信者(initiator) */ + @Index() @Column({ ...id(), + nullable: true, comment: 'The ID of sender user of the Notification.' }) - public notifierId: User['id']; + public notifierId: User['id'] | null; @ManyToOne(type => User, { onDelete: 'CASCADE' @@ -59,16 +62,19 @@ export class Notification { * receiveFollowRequest - フォローリクエストされた * followRequestAccepted - 自分の送ったフォローリクエストが承認された * groupInvited - グループに招待された + * app - アプリ通知 */ + @Index() @Column('enum', { - enum: ['follow', 'mention', 'reply', 'renote', 'quote', 'reaction', 'pollVote', 'receiveFollowRequest', 'followRequestAccepted', 'groupInvited'], + enum: ['follow', 'mention', 'reply', 'renote', 'quote', 'reaction', 'pollVote', 'receiveFollowRequest', 'followRequestAccepted', 'groupInvited', 'app'], comment: 'The type of the Notification.' }) - public type: 'follow' | 'mention' | 'reply' | 'renote' | 'quote' | 'reaction' | 'pollVote' | 'receiveFollowRequest' | 'followRequestAccepted' | 'groupInvited'; + public type: 'follow' | 'mention' | 'reply' | 'renote' | 'quote' | 'reaction' | 'pollVote' | 'receiveFollowRequest' | 'followRequestAccepted' | 'groupInvited' | 'app'; /** * 通知が読まれたかどうか */ + @Index() @Column('boolean', { default: false, comment: 'Whether the Notification is read.' @@ -114,10 +120,52 @@ export class Notification { @Column('varchar', { length: 128, nullable: true }) - public reaction: string; + public reaction: string | null; @Column('integer', { nullable: true }) - public choice: number; + public choice: number | null; + + /** + * アプリ通知のbody + */ + @Column('varchar', { + length: 2048, nullable: true + }) + public customBody: string | null; + + /** + * アプリ通知のheader + * (省略時はアプリ名で表示されることを期待) + */ + @Column('varchar', { + length: 256, nullable: true + }) + public customHeader: string | null; + + /** + * アプリ通知のicon(URL) + * (省略時はアプリアイコンで表示されることを期待) + */ + @Column('varchar', { + length: 1024, nullable: true + }) + public customIcon: string | null; + + /** + * アプリ通知のアプリ(のトークン) + */ + @Index() + @Column({ + ...id(), + nullable: true + }) + public appAccessTokenId: AccessToken['id'] | null; + + @ManyToOne(type => AccessToken, { + onDelete: 'CASCADE' + }) + @JoinColumn() + public appAccessToken: AccessToken | null; } diff --git a/src/models/repositories/notification.ts b/src/models/repositories/notification.ts index f020714f80..a8978cc01b 100644 --- a/src/models/repositories/notification.ts +++ b/src/models/repositories/notification.ts @@ -1,5 +1,5 @@ import { EntityRepository, Repository } from 'typeorm'; -import { Users, Notes, UserGroupInvitations } from '..'; +import { Users, Notes, UserGroupInvitations, AccessTokens } from '..'; import { Notification } from '../entities/notification'; import { ensure } from '../../prelude/ensure'; import { awaitAll } from '../../prelude/await-all'; @@ -13,13 +13,14 @@ export class NotificationRepository extends Repository<Notification> { src: Notification['id'] | Notification, ): Promise<PackedNotification> { const notification = typeof src === 'object' ? src : await this.findOne(src).then(ensure); + const token = notification.appAccessTokenId ? await AccessTokens.findOne(notification.appAccessTokenId).then(ensure) : null; return await awaitAll({ id: notification.id, createdAt: notification.createdAt.toISOString(), type: notification.type, userId: notification.notifierId, - user: Users.pack(notification.notifier || notification.notifierId), + user: notification.notifierId ? Users.pack(notification.notifier || notification.notifierId) : null, ...(notification.type === 'mention' ? { note: Notes.pack(notification.note || notification.noteId!, notification.notifieeId), } : {}), @@ -43,6 +44,11 @@ export class NotificationRepository extends Repository<Notification> { ...(notification.type === 'groupInvited' ? { invitation: UserGroupInvitations.pack(notification.userGroupInvitationId!), } : {}), + ...(notification.type === 'app' ? { + body: notification.customBody, + header: notification.customHeader || token!.name, + icon: notification.customIcon || token!.iconUrl, + } : {}), }); } |