Feat: 未読通知数を表示できるように (#11982)
* 未読通知数を表示できるように * Update Changelog * オプトインにする * Fix lint * (add) テスト通知のプッシュ通知を追加 * add test * フロントエンドの表示上限を99に変更 * Make it default on * 共通スタイルをくくりだす * Update Changelog * tweak * Update UserEntityService.ts * rename * Update navbar-for-mobile.vue --------- Co-authored-by: syuilo <Syuilotan@yahoo.co.jp>
This commit is contained in:
		| @@ -226,11 +226,18 @@ export async function mainBoot() { | ||||
| 		}); | ||||
|  | ||||
| 		main.on('readAllNotifications', () => { | ||||
| 			updateAccount({ hasUnreadNotification: false }); | ||||
| 			updateAccount({ | ||||
| 				hasUnreadNotification: false, | ||||
| 				unreadNotificationsCount: 0, | ||||
| 			}); | ||||
| 		}); | ||||
|  | ||||
| 		main.on('unreadNotification', () => { | ||||
| 			updateAccount({ hasUnreadNotification: true }); | ||||
| 			const unreadNotificationsCount = ($i?.unreadNotificationsCount ?? 0) + 1; | ||||
| 			updateAccount({ | ||||
| 				hasUnreadNotification: true, | ||||
| 				unreadNotificationsCount, | ||||
| 			}); | ||||
| 		}); | ||||
|  | ||||
| 		main.on('unreadMention', () => { | ||||
|   | ||||
| @@ -7,16 +7,18 @@ SPDX-License-Identifier: AGPL-3.0-only | ||||
| <MkModal ref="modal" v-slot="{ type, maxHeight }" :preferType="preferedModalType" :anchor="anchor" :transparentBg="true" :src="src" @click="modal.close()" @closed="emit('closed')"> | ||||
| 	<div class="szkkfdyq _popup _shadow" :class="{ asDrawer: type === 'drawer' }" :style="{ maxHeight: maxHeight ? maxHeight + 'px' : '' }"> | ||||
| 		<div class="main"> | ||||
| 			<template v-for="item in items"> | ||||
| 			<template v-for="item in items" :key="item.text"> | ||||
| 				<button v-if="item.action" v-click-anime class="_button item" @click="$event => { item.action($event); close(); }"> | ||||
| 					<i class="icon" :class="item.icon"></i> | ||||
| 					<div class="text">{{ item.text }}</div> | ||||
| 					<span v-if="item.indicate" class="indicator"><i class="_indicatorCircle"></i></span> | ||||
| 					<span v-if="item.indicate && item.indicateValue" class="_indicateCounter indicatorWithValue">{{ item.indicateValue }}</span> | ||||
| 					<span v-else-if="item.indicate" class="indicator"><i class="_indicatorCircle"></i></span> | ||||
| 				</button> | ||||
| 				<MkA v-else v-click-anime :to="item.to" class="item" @click.passive="close()"> | ||||
| 					<i class="icon" :class="item.icon"></i> | ||||
| 					<div class="text">{{ item.text }}</div> | ||||
| 					<span v-if="item.indicate" class="indicator"><i class="_indicatorCircle"></i></span> | ||||
| 					<span v-if="item.indicate && item.indicateValue" class="_indicateCounter indicatorWithValue">{{ item.indicateValue }}</span> | ||||
| 					<span v-else-if="item.indicate" class="indicator"><i class="_indicatorCircle"></i></span> | ||||
| 				</MkA> | ||||
| 			</template> | ||||
| 		</div> | ||||
| @@ -27,7 +29,7 @@ SPDX-License-Identifier: AGPL-3.0-only | ||||
| <script lang="ts" setup> | ||||
| import { } from 'vue'; | ||||
| import MkModal from '@/components/MkModal.vue'; | ||||
| import { navbarItemDef } from '@/navbar'; | ||||
| import { navbarItemDef } from '@/navbar.js'; | ||||
| import { defaultStore } from '@/store.js'; | ||||
| import { deviceKind } from '@/scripts/device-kind.js'; | ||||
|  | ||||
| @@ -57,6 +59,7 @@ const items = Object.keys(navbarItemDef).filter(k => !menu.includes(k)).map(k => | ||||
| 	to: def.to, | ||||
| 	action: def.action, | ||||
| 	indicate: def.indicated, | ||||
| 	indicateValue: def.indicateValue, | ||||
| })); | ||||
|  | ||||
| function close() { | ||||
| @@ -116,6 +119,17 @@ function close() { | ||||
| 				line-height: 1.5em; | ||||
| 			} | ||||
|  | ||||
| 			> .indicatorWithValue { | ||||
| 				position: absolute; | ||||
| 				top: 32px; | ||||
| 				left: 16px; | ||||
|  | ||||
| 				@media (max-width: 500px) { | ||||
| 					top: 16px; | ||||
| 					left: 8px; | ||||
| 				} | ||||
| 			} | ||||
|  | ||||
| 			> .indicator { | ||||
| 				position: absolute; | ||||
| 				top: 32px; | ||||
|   | ||||
| @@ -22,7 +22,7 @@ SPDX-License-Identifier: AGPL-3.0-only | ||||
| </template> | ||||
|  | ||||
| <script lang="ts" setup> | ||||
| import { onUnmounted, onMounted, computed, shallowRef } from 'vue'; | ||||
| import { onUnmounted, onDeactivated, onMounted, computed, shallowRef } from 'vue'; | ||||
| import MkPagination, { Paging } from '@/components/MkPagination.vue'; | ||||
| import XNotification from '@/components/MkNotification.vue'; | ||||
| import MkDateSeparatedList from '@/components/MkDateSeparatedList.vue'; | ||||
| @@ -68,6 +68,10 @@ onMounted(() => { | ||||
| onUnmounted(() => { | ||||
| 	if (connection) connection.dispose(); | ||||
| }); | ||||
|  | ||||
| onDeactivated(() => { | ||||
| 	if (connection) connection.dispose(); | ||||
| }); | ||||
| </script> | ||||
|  | ||||
| <style lang="scss" module> | ||||
|   | ||||
| @@ -19,6 +19,15 @@ export const navbarItemDef = reactive({ | ||||
| 		icon: 'ti ti-bell', | ||||
| 		show: computed(() => $i != null), | ||||
| 		indicated: computed(() => $i != null && $i.hasUnreadNotification), | ||||
| 		indicateValue: computed(() => { | ||||
| 			if (!$i || $i.unreadNotificationsCount === 0) return ''; | ||||
|  | ||||
| 			if ($i.unreadNotificationsCount > 99) { | ||||
| 				return '99+'; | ||||
| 			} else { | ||||
| 				return $i.unreadNotificationsCount.toString(); | ||||
| 			} | ||||
| 		}), | ||||
| 		to: '/my/notifications', | ||||
| 	}, | ||||
| 	drive: { | ||||
|   | ||||
| @@ -74,11 +74,11 @@ let sendReadMessage = $computed(() => pushRegistrationInServer?.sendReadMessage | ||||
| const userLists = await os.api('users/lists/list'); | ||||
|  | ||||
| async function readAllUnreadNotes() { | ||||
| 	await os.api('i/read-all-unread-notes'); | ||||
| 	await os.apiWithDialog('i/read-all-unread-notes'); | ||||
| } | ||||
|  | ||||
| async function readAllNotifications() { | ||||
| 	await os.api('notifications/mark-all-as-read'); | ||||
| 	await os.apiWithDialog('notifications/mark-all-as-read'); | ||||
| } | ||||
|  | ||||
| async function updateReceiveConfig(type, value) { | ||||
|   | ||||
| @@ -155,6 +155,19 @@ hr { | ||||
| 	background: currentColor; | ||||
| } | ||||
|  | ||||
| ._indicateCounter { | ||||
| 	display: inline-flex; | ||||
| 	color: var(--fgOnAccent); | ||||
| 	font-weight: 700; | ||||
| 	background: var(--indicator); | ||||
| 	height: 1.5em; | ||||
| 	min-width: 1.5em; | ||||
| 	align-items: center; | ||||
| 	justify-content: center; | ||||
| 	border-radius: 99rem; | ||||
| 	padding: 0.3em 0.5em; | ||||
| } | ||||
|  | ||||
| ._noSelect { | ||||
| 	user-select: none; | ||||
| 	-webkit-user-select: none; | ||||
|   | ||||
| @@ -67,7 +67,8 @@ let notifications = $ref<Misskey.entities.Notification[]>([]); | ||||
|  | ||||
| function onNotification(notification: Misskey.entities.Notification, isClient = false) { | ||||
| 	if (document.visibilityState === 'visible') { | ||||
| 		if (!isClient) { | ||||
| 		if (!isClient && notification.type !== 'test') { | ||||
| 			// サーバーサイドのテスト通知の際は自動で既読をつけない(テストできないので) | ||||
| 			useStream().send('readNotification'); | ||||
| 		} | ||||
|  | ||||
|   | ||||
| @@ -19,7 +19,10 @@ SPDX-License-Identifier: AGPL-3.0-only | ||||
| 			<div v-if="item === '-'" :class="$style.divider"></div> | ||||
| 			<component :is="navbarItemDef[item].to ? 'MkA' : 'button'" v-else-if="navbarItemDef[item] && (navbarItemDef[item].show !== false)" class="_button" :class="[$style.item, { [$style.active]: navbarItemDef[item].active }]" :activeClass="$style.active" :to="navbarItemDef[item].to" v-on="navbarItemDef[item].action ? { click: navbarItemDef[item].action } : {}"> | ||||
| 				<i class="ti-fw" :class="[$style.itemIcon, navbarItemDef[item].icon]"></i><span :class="$style.itemText">{{ navbarItemDef[item].title }}</span> | ||||
| 				<span v-if="navbarItemDef[item].indicated" :class="$style.itemIndicator"><i class="_indicatorCircle"></i></span> | ||||
| 				<span v-if="navbarItemDef[item].indicated" :class="$style.itemIndicator"> | ||||
| 					<span v-if="navbarItemDef[item].indicateValue" class="_indicateCounter" :class="$style.itemIndicateValueIcon">{{ navbarItemDef[item].indicateValue }}</span> | ||||
| 					<i v-else class="_indicatorCircle"></i> | ||||
| 				</span> | ||||
| 			</component> | ||||
| 		</template> | ||||
| 		<div :class="$style.divider"></div> | ||||
| @@ -252,6 +255,12 @@ function more() { | ||||
| 	color: var(--navIndicator); | ||||
| 	font-size: 8px; | ||||
| 	animation: blink 1s infinite; | ||||
|  | ||||
| 	&:has(.itemIndicateValueIcon) { | ||||
| 		animation: none; | ||||
| 		left: auto; | ||||
| 		right: 20px; | ||||
| 	} | ||||
| } | ||||
|  | ||||
| .itemText { | ||||
|   | ||||
| @@ -29,7 +29,10 @@ SPDX-License-Identifier: AGPL-3.0-only | ||||
| 					v-on="navbarItemDef[item].action ? { click: navbarItemDef[item].action } : {}" | ||||
| 				> | ||||
| 					<i class="ti-fw" :class="[$style.itemIcon, navbarItemDef[item].icon]"></i><span :class="$style.itemText">{{ navbarItemDef[item].title }}</span> | ||||
| 					<span v-if="navbarItemDef[item].indicated" :class="$style.itemIndicator"><i class="_indicatorCircle"></i></span> | ||||
| 					<span v-if="navbarItemDef[item].indicated" :class="$style.itemIndicator"> | ||||
| 						<span v-if="navbarItemDef[item].indicateValue" class="_indicateCounter" :class="$style.itemIndicateValueIcon">{{ navbarItemDef[item].indicateValue }}</span> | ||||
| 						<i v-else class="_indicatorCircle"></i> | ||||
| 					</span> | ||||
| 				</component> | ||||
| 			</template> | ||||
| 			<div :class="$style.divider"></div> | ||||
| @@ -106,7 +109,7 @@ function more(ev: MouseEvent) { | ||||
| <style lang="scss" module> | ||||
| .root { | ||||
| 	--nav-width: 250px; | ||||
| 	--nav-icon-only-width: 72px; | ||||
| 	--nav-icon-only-width: 80px; | ||||
|  | ||||
| 	flex: 0 0 var(--nav-width); | ||||
| 	width: var(--nav-width); | ||||
| @@ -312,6 +315,13 @@ function more(ev: MouseEvent) { | ||||
| 		color: var(--navIndicator); | ||||
| 		font-size: 8px; | ||||
| 		animation: blink 1s infinite; | ||||
|  | ||||
| 		&:has(.itemIndicateValueIcon) { | ||||
| 			animation: none; | ||||
| 			left: auto; | ||||
| 			right: 40px; | ||||
| 			font-size: 10px; | ||||
| 		} | ||||
| 	} | ||||
|  | ||||
| 	.itemText { | ||||
| @@ -475,6 +485,14 @@ function more(ev: MouseEvent) { | ||||
| 		color: var(--navIndicator); | ||||
| 		font-size: 8px; | ||||
| 		animation: blink 1s infinite; | ||||
|  | ||||
| 		&:has(.itemIndicateValueIcon) { | ||||
| 			animation: none; | ||||
| 			top: 4px; | ||||
| 			left: auto; | ||||
| 			right: 4px; | ||||
| 			font-size: 10px; | ||||
| 		} | ||||
| 	} | ||||
| } | ||||
| </style> | ||||
|   | ||||
| @@ -21,7 +21,10 @@ SPDX-License-Identifier: AGPL-3.0-only | ||||
| 		<div v-if="item === '-'" class="divider"></div> | ||||
| 		<component :is="navbarItemDef[item].to ? 'MkA' : 'button'" v-else-if="navbarItemDef[item] && (navbarItemDef[item].show !== false)" v-click-anime class="item _button" :class="item" activeClass="active" :to="navbarItemDef[item].to" v-on="navbarItemDef[item].action ? { click: navbarItemDef[item].action } : {}"> | ||||
| 			<i class="ti-fw" :class="navbarItemDef[item].icon"></i><span class="text">{{ navbarItemDef[item].title }}</span> | ||||
| 			<span v-if="navbarItemDef[item].indicated" class="indicator"><i class="_indicatorCircle"></i></span> | ||||
| 			<span v-if="navbarItemDef[item].indicated" class="indicator"> | ||||
| 				<span v-if="navbarItemDef[item].indicateValue" class="_indicateCounter itemIndicateValueIcon">{{ navbarItemDef[item].indicateValue }}</span> | ||||
| 				<i v-else class="_indicatorCircle"></i> | ||||
| 			</span> | ||||
| 		</component> | ||||
| 	</template> | ||||
| 	<div class="divider"></div> | ||||
| @@ -218,6 +221,12 @@ watch(defaultStore.reactiveState.menuDisplay, () => { | ||||
| 			color: var(--navIndicator); | ||||
| 			font-size: 8px; | ||||
| 			animation: blink 1s infinite; | ||||
|  | ||||
| 			&:has(.itemIndicateValueIcon) { | ||||
| 				animation: none; | ||||
| 				left: auto; | ||||
| 				right: 20px; | ||||
| 			} | ||||
| 		} | ||||
|  | ||||
| 		&:hover { | ||||
|   | ||||
| @@ -52,7 +52,12 @@ SPDX-License-Identifier: AGPL-3.0-only | ||||
| 	<div v-if="isMobile" :class="$style.nav"> | ||||
| 		<button :class="$style.navButton" class="_button" @click="drawerMenuShowing = true"><i :class="$style.navButtonIcon" class="ti ti-menu-2"></i><span v-if="menuIndicated" :class="$style.navButtonIndicator"><i class="_indicatorCircle"></i></span></button> | ||||
| 		<button :class="$style.navButton" class="_button" @click="mainRouter.push('/')"><i :class="$style.navButtonIcon" class="ti ti-home"></i></button> | ||||
| 		<button :class="$style.navButton" class="_button" @click="mainRouter.push('/my/notifications')"><i :class="$style.navButtonIcon" class="ti ti-bell"></i><span v-if="$i?.hasUnreadNotification" :class="$style.navButtonIndicator"><i class="_indicatorCircle"></i></span></button> | ||||
| 		<button :class="$style.navButton" class="_button" @click="mainRouter.push('/my/notifications')"> | ||||
| 			<i :class="$style.navButtonIcon" class="ti ti-bell"></i> | ||||
| 			<span v-if="$i?.hasUnreadNotification" :class="$style.navButtonIndicator"> | ||||
| 				<span class="_indicateCounter" :class="$style.itemIndicateValueIcon">{{ $i.unreadNotificationsCount > 99 ? '99+' : $i.unreadNotificationsCount }}</span> | ||||
| 			</span> | ||||
| 		</button> | ||||
| 		<button :class="$style.postButton" class="_button" @click="os.post()"><i :class="$style.navButtonIcon" class="ti ti-pencil"></i></button> | ||||
| 	</div> | ||||
|  | ||||
| @@ -485,5 +490,10 @@ body { | ||||
| 	color: var(--indicator); | ||||
| 	font-size: 16px; | ||||
| 	animation: blink 1s infinite; | ||||
|  | ||||
| 	&:has(.itemIndicateValueIcon) { | ||||
| 		animation: none; | ||||
| 		font-size: 12px; | ||||
| 	} | ||||
| } | ||||
| </style> | ||||
|   | ||||
| @@ -27,7 +27,12 @@ SPDX-License-Identifier: AGPL-3.0-only | ||||
| 	<div v-if="isMobile" ref="navFooter" :class="$style.nav"> | ||||
| 		<button :class="$style.navButton" class="_button" @click="drawerMenuShowing = true"><i :class="$style.navButtonIcon" class="ti ti-menu-2"></i><span v-if="menuIndicated" :class="$style.navButtonIndicator"><i class="_indicatorCircle"></i></span></button> | ||||
| 		<button :class="$style.navButton" class="_button" @click="mainRouter.currentRoute.value.name === 'index' ? top() : mainRouter.push('/')"><i :class="$style.navButtonIcon" class="ti ti-home"></i></button> | ||||
| 		<button :class="$style.navButton" class="_button" @click="mainRouter.push('/my/notifications')"><i :class="$style.navButtonIcon" class="ti ti-bell"></i><span v-if="$i?.hasUnreadNotification" :class="$style.navButtonIndicator"><i class="_indicatorCircle"></i></span></button> | ||||
| 		<button :class="$style.navButton" class="_button" @click="mainRouter.push('/my/notifications')"> | ||||
| 			<i :class="$style.navButtonIcon" class="ti ti-bell"></i> | ||||
| 			<span v-if="$i?.hasUnreadNotification" :class="$style.navButtonIndicator"> | ||||
| 				<span class="_indicateCounter" :class="$style.itemIndicateValueIcon">{{ $i.unreadNotificationsCount > 99 ? '99+' : $i.unreadNotificationsCount }}</span> | ||||
| 			</span> | ||||
| 		</button> | ||||
| 		<button :class="$style.navButton" class="_button" @click="widgetsShowing = true"><i :class="$style.navButtonIcon" class="ti ti-apps"></i></button> | ||||
| 		<button :class="$style.postButton" class="_button" @click="os.post()"><i :class="$style.navButtonIcon" class="ti ti-pencil"></i></button> | ||||
| 	</div> | ||||
| @@ -444,6 +449,11 @@ $widgets-hide-threshold: 1090px; | ||||
| 	color: var(--indicator); | ||||
| 	font-size: 16px; | ||||
| 	animation: blink 1s infinite; | ||||
|  | ||||
| 	&:has(.itemIndicateValueIcon) { | ||||
| 		animation: none; | ||||
| 		font-size: 12px; | ||||
| 	} | ||||
| } | ||||
|  | ||||
| .menuDrawerBg { | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 かっこかり
					かっこかり