From 3311bd866b23e03354b3e92fc55d634399be8d02 Mon Sep 17 00:00:00 2001 From: Johann150 Date: Fri, 20 May 2022 09:28:57 +0200 Subject: [PATCH] add move notification type --- locales/en-US.yml | 2 + .../src/models/entities/notification.ts | 40 +++++++++++++------ .../src/models/repositories/notification.ts | 3 ++ packages/foundkey-js/src/consts.ts | 2 +- packages/foundkey-js/src/entities.ts | 5 +++ 5 files changed, 38 insertions(+), 14 deletions(-) diff --git a/locales/en-US.yml b/locales/en-US.yml index 887d7d287..9b53f3fc0 100644 --- a/locales/en-US.yml +++ b/locales/en-US.yml @@ -1293,6 +1293,7 @@ _notification: yourFollowRequestAccepted: "Your follow request was accepted" youWereInvitedToGroup: "{userName} invited you to a group" pollEnded: "Poll results have become available" + moved: "{name} has moved to a different account" emptyPushNotificationMessage: "Push notifications have been updated" _types: follow: "New followers" @@ -1306,6 +1307,7 @@ _notification: receiveFollowRequest: "Received follow requests" followRequestAccepted: "Accepted follow requests" groupInvited: "Group invitations" + move: "Others moving accounts" app: "Notifications from linked apps" _actions: followBack: "followed you back" diff --git a/packages/backend/src/models/entities/notification.ts b/packages/backend/src/models/entities/notification.ts index cab6551f7..a0d6cbde4 100644 --- a/packages/backend/src/models/entities/notification.ts +++ b/packages/backend/src/models/entities/notification.ts @@ -52,19 +52,20 @@ export class Notification { public notifier: User | null; /** - * 通知の種類。 - * follow - フォローされた - * mention - 投稿で自分が言及された - * reply - (自分または自分がWatchしている)投稿が返信された - * renote - (自分または自分がWatchしている)投稿がRenoteされた - * quote - (自分または自分がWatchしている)投稿が引用Renoteされた - * reaction - (自分または自分がWatchしている)投稿にリアクションされた - * pollVote - (自分または自分がWatchしている)投稿のアンケートに投票された - * pollEnded - 自分のアンケートもしくは自分が投票したアンケートが終了した - * receiveFollowRequest - フォローリクエストされた - * followRequestAccepted - 自分の送ったフォローリクエストが承認された - * groupInvited - グループに招待された - * app - アプリ通知 + * Type of notification. + * follow - notifier followed notifiee + * mention - notifiee was mentioned + * reply - notifiee (author or watching) was replied to + * renote - notifiee (author or watching) was renoted + * quote - notifiee (author or watching) was quoted + * reaction - notifiee (author or watching) had a reaction added to the note + * pollVote - new vote in a poll notifiee authored or watched + * pollEnded - notifiee's poll ended + * receiveFollowRequest - notifiee received a new follow request + * followRequestAccepted - notifier accepted notifees follow request + * groupInvited - notifiee was invited into a group + * move - notifier moved + * app - custom application notification */ @Index() @Column('enum', { @@ -129,6 +130,19 @@ export class Notification { }) public choice: number | null; + @Column({ + ...id(), + nullable: true, + comment: 'The ID of the moved to account.', + }) + public moveTargetId: User['id'] | null; + + @ManyToOne(() => User, { + onDelete: 'CASCADE', + }) + @JoinColumn() + public moveTarget: User | null; + /** * アプリ通知のbody */ diff --git a/packages/backend/src/models/repositories/notification.ts b/packages/backend/src/models/repositories/notification.ts index c62a24959..c1e2273be 100644 --- a/packages/backend/src/models/repositories/notification.ts +++ b/packages/backend/src/models/repositories/notification.ts @@ -44,6 +44,9 @@ export const NotificationRepository = db.getRepository(Notification).extend({ ...(notification.type === 'groupInvited' ? { invitation: UserGroupInvitations.pack(notification.userGroupInvitationId!), } : {}), + ...(notification.type === 'move' ? { + moveTarget: Users.pack(notification.moveTarget ?? notification.moveTargetId), + } : {}), ...(notification.type === 'app' ? { body: notification.customBody, header: notification.customHeader || token?.name, diff --git a/packages/foundkey-js/src/consts.ts b/packages/foundkey-js/src/consts.ts index a90b8720a..a7ea18d25 100644 --- a/packages/foundkey-js/src/consts.ts +++ b/packages/foundkey-js/src/consts.ts @@ -1,4 +1,4 @@ -export const notificationTypes = ['follow', 'mention', 'reply', 'renote', 'quote', 'reaction', 'pollVote', 'pollEnded', 'receiveFollowRequest', 'followRequestAccepted', 'groupInvited', 'app'] as const; +export const notificationTypes = ['follow', 'mention', 'reply', 'renote', 'quote', 'reaction', 'pollVote', 'pollEnded', 'receiveFollowRequest', 'followRequestAccepted', 'groupInvited', 'move', 'app'] as const; export const noteNotificationTypes = ['mention', 'reply', 'renote', 'quote', 'reaction', 'pollVote', 'pollEnded'] as const; diff --git a/packages/foundkey-js/src/entities.ts b/packages/foundkey-js/src/entities.ts index 30dd90582..c8a91fba9 100644 --- a/packages/foundkey-js/src/entities.ts +++ b/packages/foundkey-js/src/entities.ts @@ -223,6 +223,11 @@ export type Notification = { invitation: UserGroup; user: User; userId: User['id']; +} | { + type: 'move', + user: User; + userId: User['id']; + moveTarget: User; } | { type: 'app'; header?: string | null;