| @@ -83,7 +83,7 @@ | ||||
| </template> | ||||
|  | ||||
| <script lang="ts" setup> | ||||
| import { ref, shallowRef, onMounted, onUnmounted, watch } from 'vue'; | ||||
| import { ref, shallowRef } from 'vue'; | ||||
| import * as misskey from 'misskey-js'; | ||||
| import MkReactionIcon from '@/components/MkReactionIcon.vue'; | ||||
| import MkFollowButton from '@/components/MkFollowButton.vue'; | ||||
| @@ -94,7 +94,6 @@ import { notePage } from '@/filters/note'; | ||||
| import { userPage } from '@/filters/user'; | ||||
| import { i18n } from '@/i18n'; | ||||
| import * as os from '@/os'; | ||||
| import { stream } from '@/stream'; | ||||
| import { useTooltip } from '@/scripts/use-tooltip'; | ||||
| import { $i } from '@/account'; | ||||
|  | ||||
| @@ -110,35 +109,6 @@ const props = withDefaults(defineProps<{ | ||||
| const elRef = shallowRef<HTMLElement>(null); | ||||
| const reactionRef = ref(null); | ||||
|  | ||||
| let readObserver: IntersectionObserver | undefined; | ||||
| let connection; | ||||
|  | ||||
| onMounted(() => { | ||||
| 	if (!props.notification.isRead) { | ||||
| 		readObserver = new IntersectionObserver((entries, observer) => { | ||||
| 			if (!entries.some(entry => entry.isIntersecting)) return; | ||||
| 			stream.send('readNotification', { | ||||
| 				id: props.notification.id, | ||||
| 			}); | ||||
| 			observer.disconnect(); | ||||
| 		}); | ||||
|  | ||||
| 		readObserver.observe(elRef.value); | ||||
|  | ||||
| 		connection = stream.useChannel('main'); | ||||
| 		connection.on('readAllNotifications', () => readObserver.disconnect()); | ||||
|  | ||||
| 		watch(props.notification.isRead, () => { | ||||
| 			readObserver.disconnect(); | ||||
| 		}); | ||||
| 	} | ||||
| }); | ||||
|  | ||||
| onUnmounted(() => { | ||||
| 	if (readObserver) readObserver.disconnect(); | ||||
| 	if (connection) connection.dispose(); | ||||
| }); | ||||
|  | ||||
| const followRequestDone = ref(false); | ||||
|  | ||||
| const acceptFollowRequest = () => { | ||||
|   | ||||
| @@ -29,7 +29,6 @@ import { notificationTypes } from '@/const'; | ||||
|  | ||||
| const props = defineProps<{ | ||||
| 	includeTypes?: typeof notificationTypes[number][]; | ||||
| 	unreadOnly?: boolean; | ||||
| }>(); | ||||
|  | ||||
| const pagingComponent = shallowRef<InstanceType<typeof MkPagination>>(); | ||||
| @@ -40,23 +39,17 @@ const pagination: Paging = { | ||||
| 	params: computed(() => ({ | ||||
| 		includeTypes: props.includeTypes ?? undefined, | ||||
| 		excludeTypes: props.includeTypes ? undefined : $i.mutingNotificationTypes, | ||||
| 		unreadOnly: props.unreadOnly, | ||||
| 	})), | ||||
| }; | ||||
|  | ||||
| const onNotification = (notification) => { | ||||
| 	const isMuted = props.includeTypes ? !props.includeTypes.includes(notification.type) : $i.mutingNotificationTypes.includes(notification.type); | ||||
| 	if (isMuted || document.visibilityState === 'visible') { | ||||
| 		stream.send('readNotification', { | ||||
| 			id: notification.id, | ||||
| 		}); | ||||
| 		stream.send('readNotification'); | ||||
| 	} | ||||
|  | ||||
| 	if (!isMuted) { | ||||
| 		pagingComponent.value.prepend({ | ||||
| 			...notification, | ||||
| 			isRead: document.visibilityState === 'visible', | ||||
| 		}); | ||||
| 		pagingComponent.value.prepend(notification); | ||||
| 	} | ||||
| }; | ||||
|  | ||||
| @@ -65,30 +58,6 @@ let connection; | ||||
| onMounted(() => { | ||||
| 	connection = stream.useChannel('main'); | ||||
| 	connection.on('notification', onNotification); | ||||
| 	connection.on('readAllNotifications', () => { | ||||
| 		if (pagingComponent.value) { | ||||
| 			for (const item of pagingComponent.value.queue) { | ||||
| 				item.isRead = true; | ||||
| 			} | ||||
| 			for (const item of pagingComponent.value.items) { | ||||
| 				item.isRead = true; | ||||
| 			} | ||||
| 		} | ||||
| 	}); | ||||
| 	connection.on('readNotifications', notificationIds => { | ||||
| 		if (pagingComponent.value) { | ||||
| 			for (let i = 0; i < pagingComponent.value.queue.length; i++) { | ||||
| 				if (notificationIds.includes(pagingComponent.value.queue[i].id)) { | ||||
| 					pagingComponent.value.queue[i].isRead = true; | ||||
| 				} | ||||
| 			} | ||||
| 			for (let i = 0; i < (pagingComponent.value.items || []).length; i++) { | ||||
| 				if (notificationIds.includes(pagingComponent.value.items[i].id)) { | ||||
| 					pagingComponent.value.items[i].isRead = true; | ||||
| 				} | ||||
| 			} | ||||
| 		} | ||||
| 	}); | ||||
| }); | ||||
|  | ||||
| onUnmounted(() => { | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 syuilo
					syuilo