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