406b4bdbe7
* refactor(frontend): 非推奨となったReactivity Transformを使わないように * refactor: 不要な括弧を除去 * fix: 不要なアノテーションを除去 * fix: Refの配列をrefしている部分の対応 * refactor: 不要な括弧を除去 * fix: lint * refactor: Ref、ShallowRef、ComputedRefの変数の宣言をletからconstに置換 * fix: type error * chore: drop reactivity transform from eslint configuration * refactor: remove unnecessary import * fix: 対応漏れ
109 lines
3 KiB
Vue
109 lines
3 KiB
Vue
<!--
|
|
SPDX-FileCopyrightText: syuilo and other misskey contributors
|
|
SPDX-License-Identifier: AGPL-3.0-only
|
|
-->
|
|
|
|
<template>
|
|
<MkPullToRefresh :refresher="() => reload()">
|
|
<MkPagination ref="pagingComponent" :pagination="pagination">
|
|
<template #empty>
|
|
<div class="_fullinfo">
|
|
<img :src="infoImageUrl" class="_ghost"/>
|
|
<div>{{ i18n.ts.noNotifications }}</div>
|
|
</div>
|
|
</template>
|
|
|
|
<template #default="{ items: notifications }">
|
|
<MkDateSeparatedList v-slot="{ item: notification }" :class="$style.list" :items="notifications" :noGap="true">
|
|
<MkNote v-if="['reply', 'quote', 'mention'].includes(notification.type)" :key="notification.id" :note="notification.note" :withHardMute="true"/>
|
|
<XNotification v-else :key="notification.id" :notification="notification" :withTime="true" :full="true" class="_panel"/>
|
|
</MkDateSeparatedList>
|
|
</template>
|
|
</MkPagination>
|
|
</MkPullToRefresh>
|
|
</template>
|
|
|
|
<script lang="ts" setup>
|
|
import { onUnmounted, onDeactivated, onMounted, computed, shallowRef, onActivated, watch } from 'vue';
|
|
import MkPagination, { Paging } from '@/components/MkPagination.vue';
|
|
import XNotification from '@/components/MkNotification.vue';
|
|
import MkDateSeparatedList from '@/components/MkDateSeparatedList.vue';
|
|
import MkNote from '@/components/MkNote.vue';
|
|
import { useStream } from '@/stream.js';
|
|
import { $i } from '@/account.js';
|
|
import { i18n } from '@/i18n.js';
|
|
import { notificationTypes } from '@/const.js';
|
|
import { infoImageUrl } from '@/instance.js';
|
|
import { defaultStore } from '@/store.js';
|
|
import MkPullToRefresh from '@/components/MkPullToRefresh.vue';
|
|
|
|
const props = defineProps<{
|
|
excludeTypes?: typeof notificationTypes[number][];
|
|
}>();
|
|
|
|
const pagingComponent = shallowRef<InstanceType<typeof MkPagination>>();
|
|
|
|
const pagination = computed(() => defaultStore.reactiveState.useGroupedNotifications.value ? {
|
|
endpoint: 'i/notifications-grouped' as const,
|
|
limit: 20,
|
|
params: computed(() => ({
|
|
excludeTypes: props.excludeTypes ?? undefined,
|
|
})),
|
|
} : {
|
|
endpoint: 'i/notifications' as const,
|
|
limit: 20,
|
|
params: computed(() => ({
|
|
excludeTypes: props.excludeTypes ?? undefined,
|
|
})),
|
|
});
|
|
|
|
function onNotification(notification) {
|
|
const isMuted = props.excludeTypes ? props.excludeTypes.includes(notification.type) : false;
|
|
if (isMuted || document.visibilityState === 'visible') {
|
|
useStream().send('readNotification');
|
|
}
|
|
|
|
if (!isMuted) {
|
|
pagingComponent.value.prepend(notification);
|
|
}
|
|
}
|
|
|
|
function reload() {
|
|
return new Promise<void>((res) => {
|
|
pagingComponent.value?.reload().then(() => {
|
|
res();
|
|
});
|
|
});
|
|
}
|
|
|
|
let connection;
|
|
|
|
onMounted(() => {
|
|
connection = useStream().useChannel('main');
|
|
connection.on('notification', onNotification);
|
|
});
|
|
|
|
onActivated(() => {
|
|
pagingComponent.value?.reload();
|
|
connection = useStream().useChannel('main');
|
|
connection.on('notification', onNotification);
|
|
});
|
|
|
|
onUnmounted(() => {
|
|
if (connection) connection.dispose();
|
|
});
|
|
|
|
onDeactivated(() => {
|
|
if (connection) connection.dispose();
|
|
});
|
|
|
|
defineExpose({
|
|
reload,
|
|
});
|
|
</script>
|
|
|
|
<style lang="scss" module>
|
|
.list {
|
|
background: var(--panel);
|
|
}
|
|
</style>
|