From 0fb9c372ddec7d5284d6402625cbaffc9ac7eb0b Mon Sep 17 00:00:00 2001
From: syuilo <Syuilotan@yahoo.co.jp>
Date: Wed, 22 Feb 2023 15:28:17 +0900
Subject: lint

---
 packages/frontend/src/components/MkNotificationSettingWindow.vue | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

(limited to 'packages/frontend/src/components/MkNotificationSettingWindow.vue')

diff --git a/packages/frontend/src/components/MkNotificationSettingWindow.vue b/packages/frontend/src/components/MkNotificationSettingWindow.vue
index e303403872..2d8d30e337 100644
--- a/packages/frontend/src/components/MkNotificationSettingWindow.vue
+++ b/packages/frontend/src/components/MkNotificationSettingWindow.vue
@@ -54,7 +54,7 @@ const props = withDefaults(defineProps<{
 	showGlobalToggle: true,
 });
 
-let includingTypes = $computed(() => props.includingTypes || []);
+let includingTypes = $computed(() => props.includingTypes ?? []);
 
 const dialog = $shallowRef<InstanceType<typeof MkModalWindow>>();
 
-- 
cgit v1.2.3-freya


From becc4d2e540a07943d55a476c2e25cc22911162a Mon Sep 17 00:00:00 2001
From: tamaina <tamaina@hotmail.co.jp>
Date: Thu, 23 Feb 2023 20:46:14 +0900
Subject: fix:
 i/notificationsで古い通知タイプを許容するなど、古い通知タイプの清算 (#10042)
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

* wip

* fix

* create migration

* oops

* fix front const

* changelog

* fix type

* fix

* wip

* Revert "wip"

This reverts commit 6cdb3600e280be3550b8b6353b2c7930f7b31438.

* enumのこす

* fix

---------

Co-authored-by: syuilo <Syuilotan@yahoo.co.jp>
---
 CHANGELOG.md                                       |  2 ++
 locales/ja-JP.yml                                  |  1 +
 .../src/core/entities/NotificationEntityService.ts |  7 -----
 .../backend/src/models/entities/Notification.ts    |  8 +++---
 .../backend/src/models/entities/UserProfile.ts     |  4 +--
 .../src/server/api/endpoints/i/notifications.ts    | 19 +++++++++-----
 packages/backend/src/types.ts                      |  3 ++-
 .../src/components/MkNotificationSettingWindow.vue | 30 ++++++++++------------
 .../frontend/src/components/MkNotifications.vue    |  2 +-
 packages/frontend/src/const.ts                     |  3 +++
 packages/frontend/src/pages/notifications.vue      |  2 +-
 .../frontend/src/pages/settings/notifications.vue  |  2 +-
 12 files changed, 44 insertions(+), 39 deletions(-)

(limited to 'packages/frontend/src/components/MkNotificationSettingWindow.vue')

diff --git a/CHANGELOG.md b/CHANGELOG.md
index 91f4e0aae9..775ad9393e 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -17,6 +17,8 @@ You should also include the user name that made the change.
 
 ### Bugfixes
 - Client: 「キャッシュを削除」した後、ローカルのカスタム絵文字が表示されなくなるされなくなる問題を修正
+- Client: 通知設定画面で以前からグループの招待を有効化していた場合、通知の表示に失敗する問題の修正
+- Client: 通知設定画面に古いトグルが残っていた問題を修正
 
 ## 13.7.2 (2023/02/23)
 
diff --git a/locales/ja-JP.yml b/locales/ja-JP.yml
index 3faab45007..5ba5f64769 100644
--- a/locales/ja-JP.yml
+++ b/locales/ja-JP.yml
@@ -1846,6 +1846,7 @@ _notification:
     pollEnded: "アンケートが終了"
     receiveFollowRequest: "フォロー申請を受け取った"
     followRequestAccepted: "フォローが受理された"
+    achievementEarned: "実績の獲得"
     app: "連携アプリからの通知"
 
   _actions:
diff --git a/packages/backend/src/core/entities/NotificationEntityService.ts b/packages/backend/src/core/entities/NotificationEntityService.ts
index 34ff52ede8..33c76c6937 100644
--- a/packages/backend/src/core/entities/NotificationEntityService.ts
+++ b/packages/backend/src/core/entities/NotificationEntityService.ts
@@ -94,13 +94,6 @@ export class NotificationEntityService implements OnModuleInit {
 				}),
 				reaction: notification.reaction,
 			} : {}),
-			...(notification.type === 'pollVote' ? { // TODO: そのうち消す
-				note: this.noteEntityService.pack(notification.note ?? notification.noteId!, { id: notification.notifieeId }, {
-					detail: true,
-					_hint_: options._hintForEachNotes_,
-				}),
-				choice: notification.choice,
-			} : {}),
 			...(notification.type === 'pollEnded' ? {
 				note: this.noteEntityService.pack(notification.note ?? notification.noteId!, { id: notification.notifieeId }, {
 					detail: true,
diff --git a/packages/backend/src/models/entities/Notification.ts b/packages/backend/src/models/entities/Notification.ts
index 105f0d0407..51117efba5 100644
--- a/packages/backend/src/models/entities/Notification.ts
+++ b/packages/backend/src/models/entities/Notification.ts
@@ -1,5 +1,5 @@
 import { Entity, Index, JoinColumn, ManyToOne, Column, PrimaryColumn } from 'typeorm';
-import { notificationTypes } from '@/types.js';
+import { notificationTypes, obsoleteNotificationTypes } from '@/types.js';
 import { id } from '../id.js';
 import { User } from './User.js';
 import { Note } from './Note.js';
@@ -58,7 +58,6 @@ export class Notification {
 	 * renote - 投稿がRenoteされた
 	 * quote - 投稿が引用Renoteされた
 	 * reaction - 投稿にリアクションされた
-	 * pollVote - 投稿のアンケートに投票された (廃止)
 	 * pollEnded - 自分のアンケートもしくは自分が投票したアンケートが終了した
 	 * receiveFollowRequest - フォローリクエストされた
 	 * followRequestAccepted - 自分の送ったフォローリクエストが承認された
@@ -67,7 +66,10 @@ export class Notification {
 	 */
 	@Index()
 	@Column('enum', {
-		enum: notificationTypes,
+		enum: [
+			...notificationTypes,
+			...obsoleteNotificationTypes,
+		],
 		comment: 'The type of the Notification.',
 	})
 	public type: typeof notificationTypes[number];
diff --git a/packages/backend/src/models/entities/UserProfile.ts b/packages/backend/src/models/entities/UserProfile.ts
index 3d35b4cb5a..60c1c55de5 100644
--- a/packages/backend/src/models/entities/UserProfile.ts
+++ b/packages/backend/src/models/entities/UserProfile.ts
@@ -1,5 +1,5 @@
 import { Entity, Column, Index, OneToOne, JoinColumn, PrimaryColumn } from 'typeorm';
-import { ffVisibility, notificationTypes } from '@/types.js';
+import { obsoleteNotificationTypes, ffVisibility, notificationTypes } from '@/types.js';
 import { id } from '../id.js';
 import { User } from './User.js';
 import { Page } from './Page.js';
@@ -205,7 +205,7 @@ export class UserProfile {
 		enum: [ 
 			...notificationTypes,
 			// マイグレーションで削除が困難なので古いenumは残しておく
-			'groupInvited',
+			...obsoleteNotificationTypes,
 		],
 		array: true,
 		default: [],
diff --git a/packages/backend/src/server/api/endpoints/i/notifications.ts b/packages/backend/src/server/api/endpoints/i/notifications.ts
index 706e0d2089..e3897d38bd 100644
--- a/packages/backend/src/server/api/endpoints/i/notifications.ts
+++ b/packages/backend/src/server/api/endpoints/i/notifications.ts
@@ -1,7 +1,7 @@
 import { Brackets } from 'typeorm';
 import { Inject, Injectable } from '@nestjs/common';
 import type { UsersRepository, FollowingsRepository, MutingsRepository, UserProfilesRepository, NotificationsRepository } from '@/models/index.js';
-import { notificationTypes } from '@/types.js';
+import { obsoleteNotificationTypes, notificationTypes } from '@/types.js';
 import { Endpoint } from '@/server/api/endpoint-base.js';
 import { QueryService } from '@/core/QueryService.js';
 import { NoteReadService } from '@/core/NoteReadService.js';
@@ -41,11 +41,12 @@ export const paramDef = {
 		following: { type: 'boolean', default: false },
 		unreadOnly: { type: 'boolean', default: false },
 		markAsRead: { type: 'boolean', default: true },
+		// 後方互換のため、廃止された通知タイプも受け付ける
 		includeTypes: { type: 'array', items: {
-			type: 'string', enum: notificationTypes,
+			type: 'string', enum: [...notificationTypes, ...obsoleteNotificationTypes],
 		} },
 		excludeTypes: { type: 'array', items: {
-			type: 'string', enum: notificationTypes,
+			type: 'string', enum: [...notificationTypes, ...obsoleteNotificationTypes],
 		} },
 	},
 	required: [],
@@ -84,6 +85,10 @@ export default class extends Endpoint<typeof meta, typeof paramDef> {
 			if (notificationTypes.every(type => ps.excludeTypes?.includes(type))) {
 				return [];
 			}
+
+			const includeTypes = ps.includeTypes && ps.includeTypes.filter(type => !(obsoleteNotificationTypes).includes(type as any)) as typeof notificationTypes[number][];
+			const excludeTypes = ps.excludeTypes && ps.excludeTypes.filter(type => !(obsoleteNotificationTypes).includes(type as any)) as typeof notificationTypes[number][];
+
 			const followingQuery = this.followingsRepository.createQueryBuilder('following')
 				.select('following.followeeId')
 				.where('following.followerId = :followerId', { followerId: me.id });
@@ -143,10 +148,10 @@ export default class extends Endpoint<typeof meta, typeof paramDef> {
 				query.setParameters(followingQuery.getParameters());
 			}
 
-			if (ps.includeTypes && ps.includeTypes.length > 0) {
-				query.andWhere('notification.type IN (:...includeTypes)', { includeTypes: ps.includeTypes });
-			} else if (ps.excludeTypes && ps.excludeTypes.length > 0) {
-				query.andWhere('notification.type NOT IN (:...excludeTypes)', { excludeTypes: ps.excludeTypes });
+			if (includeTypes && includeTypes.length > 0) {
+				query.andWhere('notification.type IN (:...includeTypes)', { includeTypes });
+			} else if (excludeTypes && excludeTypes.length > 0) {
+				query.andWhere('notification.type NOT IN (:...excludeTypes)', { excludeTypes });
 			}
 
 			if (ps.unreadOnly) {
diff --git a/packages/backend/src/types.ts b/packages/backend/src/types.ts
index 8ac65a021c..7c6a1e5199 100644
--- a/packages/backend/src/types.ts
+++ b/packages/backend/src/types.ts
@@ -1,4 +1,5 @@
-export const notificationTypes = ['follow', 'mention', 'reply', 'renote', 'quote', 'reaction', 'pollVote', 'pollEnded', 'receiveFollowRequest', 'followRequestAccepted', 'achievementEarned', 'app'] as const;
+export const notificationTypes = ['follow', 'mention', 'reply', 'renote', 'quote', 'reaction', 'pollEnded', 'receiveFollowRequest', 'followRequestAccepted', 'achievementEarned', 'app'] as const;
+export const obsoleteNotificationTypes = ['pollVote', 'groupInvited'] as const;
 
 export const noteVisibilities = ['public', 'home', 'followers', 'specified'] as const;
 
diff --git a/packages/frontend/src/components/MkNotificationSettingWindow.vue b/packages/frontend/src/components/MkNotificationSettingWindow.vue
index 2d8d30e337..f6d0e5681d 100644
--- a/packages/frontend/src/components/MkNotificationSettingWindow.vue
+++ b/packages/frontend/src/components/MkNotificationSettingWindow.vue
@@ -6,7 +6,7 @@
 	:with-ok-button="true"
 	:ok-button-disabled="false"
 	@ok="ok()"
-	@close="dialog.close()"
+	@close="dialog?.close()"
 	@closed="emit('closed')"
 >
 	<template #header>{{ i18n.ts.notificationSetting }}</template>
@@ -25,7 +25,7 @@
 					<MkButton inline @click="disableAll">{{ i18n.ts.disableAll }}</MkButton>
 					<MkButton inline @click="enableAll">{{ i18n.ts.enableAll }}</MkButton>
 				</div>
-				<MkSwitch v-for="ntype in notificationTypes" :key="ntype" v-model="typesMap[ntype]">{{ i18n.t(`_notification._types.${ntype}`) }}</MkSwitch>
+				<MkSwitch v-for="ntype in notificationTypes" :key="ntype" v-model="typesMap[ntype].value">{{ i18n.t(`_notification._types.${ntype}`) }}</MkSwitch>
 			</template>
 		</div>
 	</MkSpacer>
@@ -33,14 +33,16 @@
 </template>
 
 <script lang="ts" setup>
-import { } from 'vue';
-import { notificationTypes } from 'misskey-js';
+import { ref, Ref } from 'vue';
 import MkSwitch from './MkSwitch.vue';
 import MkInfo from './MkInfo.vue';
 import MkButton from './MkButton.vue';
 import MkModalWindow from '@/components/MkModalWindow.vue';
+import { notificationTypes } from '@/const';
 import { i18n } from '@/i18n';
 
+type TypesMap = Record<typeof notificationTypes[number], Ref<boolean>>
+
 const emit = defineEmits<{
 	(ev: 'done', v: { includingTypes: string[] | null }): void,
 	(ev: 'closed'): void,
@@ -54,39 +56,35 @@ const props = withDefaults(defineProps<{
 	showGlobalToggle: true,
 });
 
-let includingTypes = $computed(() => props.includingTypes ?? []);
+let includingTypes = $computed(() => props.includingTypes?.filter(x => notificationTypes.includes(x)) ?? []);
 
 const dialog = $shallowRef<InstanceType<typeof MkModalWindow>>();
 
-let typesMap = $ref<Record<typeof notificationTypes[number], boolean>>({});
+const typesMap: TypesMap = notificationTypes.reduce((p, t) => ({ ...p, [t]: ref<boolean>(includingTypes.includes(t)) }), {} as any);
 let useGlobalSetting = $ref((includingTypes === null || includingTypes.length === 0) && props.showGlobalToggle);
 
-for (const ntype of notificationTypes) {
-	typesMap[ntype] = includingTypes.includes(ntype);
-}
-
 function ok() {
 	if (useGlobalSetting) {
 		emit('done', { includingTypes: null });
 	} else {
 		emit('done', {
 			includingTypes: (Object.keys(typesMap) as typeof notificationTypes[number][])
-				.filter(type => typesMap[type]),
+				.filter(type => typesMap[type].value),
 		});
 	}
 
-	dialog.close();
+	if (dialog) dialog.close();
 }
 
 function disableAll() {
-	for (const type in typesMap) {
-		typesMap[type as typeof notificationTypes[number]] = false;
+	for (const type of notificationTypes) {
+		typesMap[type].value = false;
 	}
 }
 
 function enableAll() {
-	for (const type in typesMap) {
-		typesMap[type as typeof notificationTypes[number]] = true;
+	for (const type of notificationTypes) {
+		typesMap[type].value = true;
 	}
 }
 </script>
diff --git a/packages/frontend/src/components/MkNotifications.vue b/packages/frontend/src/components/MkNotifications.vue
index 37ce7635a3..93b1c37055 100644
--- a/packages/frontend/src/components/MkNotifications.vue
+++ b/packages/frontend/src/components/MkNotifications.vue
@@ -18,7 +18,6 @@
 
 <script lang="ts" setup>
 import { onUnmounted, onMounted, computed, shallowRef } from 'vue';
-import { notificationTypes } from 'misskey-js';
 import MkPagination, { Paging } from '@/components/MkPagination.vue';
 import XNotification from '@/components/MkNotification.vue';
 import MkDateSeparatedList from '@/components/MkDateSeparatedList.vue';
@@ -26,6 +25,7 @@ import XNote from '@/components/MkNote.vue';
 import { stream } from '@/stream';
 import { $i } from '@/account';
 import { i18n } from '@/i18n';
+import { notificationTypes } from '@/const';
 
 const props = defineProps<{
 	includeTypes?: typeof notificationTypes[number][];
diff --git a/packages/frontend/src/const.ts b/packages/frontend/src/const.ts
index 77366cf07b..1d44786a63 100644
--- a/packages/frontend/src/const.ts
+++ b/packages/frontend/src/const.ts
@@ -43,3 +43,6 @@ https://github.com/sindresorhus/file-type/blob/main/supported.js
 https://github.com/sindresorhus/file-type/blob/main/core.js
 https://developer.mozilla.org/en-US/docs/Web/Media/Formats/Containers
 */
+
+export const notificationTypes = ['follow', 'mention', 'reply', 'renote', 'quote', 'reaction', 'pollEnded', 'receiveFollowRequest', 'followRequestAccepted', 'achievementEarned', 'app'] as const;
+export const obsoleteNotificationTypes = ['pollVote', 'groupInvited'] as const;
diff --git a/packages/frontend/src/pages/notifications.vue b/packages/frontend/src/pages/notifications.vue
index 0fcf0f65c4..da64a4c1e0 100644
--- a/packages/frontend/src/pages/notifications.vue
+++ b/packages/frontend/src/pages/notifications.vue
@@ -17,12 +17,12 @@
 
 <script lang="ts" setup>
 import { computed } from 'vue';
-import { notificationTypes } from 'misskey-js';
 import XNotifications from '@/components/MkNotifications.vue';
 import MkNotes from '@/components/MkNotes.vue';
 import * as os from '@/os';
 import { i18n } from '@/i18n';
 import { definePageMetadata } from '@/scripts/page-metadata';
+import { notificationTypes } from '@/const';
 
 let tab = $ref('all');
 let includeTypes = $ref<string[] | null>(null);
diff --git a/packages/frontend/src/pages/settings/notifications.vue b/packages/frontend/src/pages/settings/notifications.vue
index f64202fff2..2cf2f6d7f6 100644
--- a/packages/frontend/src/pages/settings/notifications.vue
+++ b/packages/frontend/src/pages/settings/notifications.vue
@@ -27,7 +27,6 @@
 
 <script lang="ts" setup>
 import { defineAsyncComponent } from 'vue';
-import { notificationTypes } from 'misskey-js';
 import FormLink from '@/components/form/link.vue';
 import FormSection from '@/components/form/section.vue';
 import MkSwitch from '@/components/MkSwitch.vue';
@@ -36,6 +35,7 @@ import { $i } from '@/account';
 import { i18n } from '@/i18n';
 import { definePageMetadata } from '@/scripts/page-metadata';
 import MkPushNotificationAllowButton from '@/components/MkPushNotificationAllowButton.vue';
+import { notificationTypes } from '@/const';
 
 let allowButton = $shallowRef<InstanceType<typeof MkPushNotificationAllowButton>>();
 let pushRegistrationInServer = $computed(() => allowButton?.pushRegistrationInServer);
-- 
cgit v1.2.3-freya

