2023-07-27 08:31:52 +03:00
|
|
|
<!--
|
2024-02-13 17:59:27 +02:00
|
|
|
SPDX-FileCopyrightText: syuilo and misskey-project
|
2023-07-27 08:31:52 +03:00
|
|
|
SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
-->
|
|
|
|
|
2020-01-29 21:37:25 +02:00
|
|
|
<template>
|
2023-11-02 11:07:42 +02:00
|
|
|
<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>
|
2022-01-09 14:35:35 +02:00
|
|
|
|
2023-11-02 11:07:42 +02:00
|
|
|
<template #default="{ items: notifications }">
|
|
|
|
<MkDateSeparatedList v-slot="{ item: notification }" :class="$style.list" :items="notifications" :noGap="true">
|
2024-01-30 12:53:53 +02:00
|
|
|
<MkNote v-if="['reply', 'quote', 'mention'].includes(notification.type)" :key="notification.id + ':note'" :note="notification.note" :withHardMute="true"/>
|
2023-11-02 11:07:42 +02:00
|
|
|
<XNotification v-else :key="notification.id" :notification="notification" :withTime="true" :full="true" class="_panel"/>
|
|
|
|
</MkDateSeparatedList>
|
|
|
|
</template>
|
|
|
|
</MkPagination>
|
|
|
|
</MkPullToRefresh>
|
2020-01-29 21:37:25 +02:00
|
|
|
</template>
|
|
|
|
|
2022-01-09 14:35:35 +02:00
|
|
|
<script lang="ts" setup>
|
2023-12-21 04:36:45 +02:00
|
|
|
import { onUnmounted, onDeactivated, onMounted, computed, shallowRef, onActivated } from 'vue';
|
|
|
|
import MkPagination from '@/components/MkPagination.vue';
|
2022-08-30 18:24:33 +03:00
|
|
|
import XNotification from '@/components/MkNotification.vue';
|
2023-01-09 22:31:02 +02:00
|
|
|
import MkDateSeparatedList from '@/components/MkDateSeparatedList.vue';
|
2023-03-31 08:14:30 +03:00
|
|
|
import MkNote from '@/components/MkNote.vue';
|
2023-09-19 10:37:43 +03:00
|
|
|
import { useStream } from '@/stream.js';
|
|
|
|
import { i18n } from '@/i18n.js';
|
2023-09-29 05:29:54 +03:00
|
|
|
import { notificationTypes } from '@/const.js';
|
2023-09-19 10:37:43 +03:00
|
|
|
import { infoImageUrl } from '@/instance.js';
|
2023-11-02 08:57:55 +02:00
|
|
|
import { defaultStore } from '@/store.js';
|
2023-11-02 11:07:42 +02:00
|
|
|
import MkPullToRefresh from '@/components/MkPullToRefresh.vue';
|
2022-01-09 14:35:35 +02:00
|
|
|
|
|
|
|
const props = defineProps<{
|
2023-09-29 05:29:54 +03:00
|
|
|
excludeTypes?: typeof notificationTypes[number][];
|
2022-01-09 14:35:35 +02:00
|
|
|
}>();
|
|
|
|
|
2023-01-03 06:37:32 +02:00
|
|
|
const pagingComponent = shallowRef<InstanceType<typeof MkPagination>>();
|
2022-01-09 14:35:35 +02:00
|
|
|
|
2023-12-07 07:42:09 +02:00
|
|
|
const pagination = computed(() => defaultStore.reactiveState.useGroupedNotifications.value ? {
|
2023-11-02 08:57:55 +02:00
|
|
|
endpoint: 'i/notifications-grouped' as const,
|
|
|
|
limit: 20,
|
|
|
|
params: computed(() => ({
|
|
|
|
excludeTypes: props.excludeTypes ?? undefined,
|
|
|
|
})),
|
|
|
|
} : {
|
2022-01-09 14:35:35 +02:00
|
|
|
endpoint: 'i/notifications' as const,
|
2023-10-20 05:33:33 +03:00
|
|
|
limit: 20,
|
2022-01-09 14:35:35 +02:00
|
|
|
params: computed(() => ({
|
2023-09-29 05:29:54 +03:00
|
|
|
excludeTypes: props.excludeTypes ?? undefined,
|
2022-01-09 14:35:35 +02:00
|
|
|
})),
|
2023-11-28 13:43:25 +02:00
|
|
|
});
|
2022-01-09 14:35:35 +02:00
|
|
|
|
2023-11-02 11:07:42 +02:00
|
|
|
function onNotification(notification) {
|
2023-09-29 05:29:54 +03:00
|
|
|
const isMuted = props.excludeTypes ? props.excludeTypes.includes(notification.type) : false;
|
2022-01-09 14:35:35 +02:00
|
|
|
if (isMuted || document.visibilityState === 'visible') {
|
2023-05-15 13:08:46 +03:00
|
|
|
useStream().send('readNotification');
|
2022-01-09 14:35:35 +02:00
|
|
|
}
|
2020-07-29 17:03:08 +03:00
|
|
|
|
2022-01-09 14:35:35 +02:00
|
|
|
if (!isMuted) {
|
2024-01-30 12:53:53 +02:00
|
|
|
pagingComponent.value?.prepend(notification);
|
2020-01-29 21:37:25 +02:00
|
|
|
}
|
2023-11-02 11:07:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function reload() {
|
|
|
|
return new Promise<void>((res) => {
|
|
|
|
pagingComponent.value?.reload().then(() => {
|
|
|
|
res();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
2022-01-09 14:35:35 +02:00
|
|
|
|
2022-06-25 21:12:58 +03:00
|
|
|
let connection;
|
|
|
|
|
2022-01-09 14:35:35 +02:00
|
|
|
onMounted(() => {
|
2023-05-15 13:08:46 +03:00
|
|
|
connection = useStream().useChannel('main');
|
2022-01-09 14:35:35 +02:00
|
|
|
connection.on('notification', onNotification);
|
2022-06-25 21:12:58 +03:00
|
|
|
});
|
2022-04-30 15:52:07 +03:00
|
|
|
|
2023-11-02 11:07:42 +02:00
|
|
|
onActivated(() => {
|
|
|
|
pagingComponent.value?.reload();
|
|
|
|
connection = useStream().useChannel('main');
|
|
|
|
connection.on('notification', onNotification);
|
|
|
|
});
|
|
|
|
|
2022-06-25 21:12:58 +03:00
|
|
|
onUnmounted(() => {
|
|
|
|
if (connection) connection.dispose();
|
2020-01-29 21:37:25 +02:00
|
|
|
});
|
2023-11-01 06:34:05 +02:00
|
|
|
|
|
|
|
onDeactivated(() => {
|
|
|
|
if (connection) connection.dispose();
|
|
|
|
});
|
2023-11-10 10:49:09 +02:00
|
|
|
|
|
|
|
defineExpose({
|
|
|
|
reload,
|
|
|
|
});
|
2020-01-29 21:37:25 +02:00
|
|
|
</script>
|
|
|
|
|
2023-01-14 10:23:49 +02:00
|
|
|
<style lang="scss" module>
|
|
|
|
.list {
|
2021-08-21 11:40:15 +03:00
|
|
|
background: var(--panel);
|
|
|
|
}
|
2020-01-29 21:37:25 +02:00
|
|
|
</style>
|