2020-01-29 21:37:25 +02:00
|
|
|
<template>
|
2022-01-09 14:35:35 +02:00
|
|
|
<MkPagination ref="pagingComponent" :pagination="pagination">
|
|
|
|
<template #empty>
|
|
|
|
<div class="_fullinfo">
|
|
|
|
<img src="https://xn--931a.moe/assets/info.jpg" class="_ghost"/>
|
2022-07-20 16:24:26 +03:00
|
|
|
<div>{{ i18n.ts.noNotifications }}</div>
|
2022-01-09 14:35:35 +02:00
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<template #default="{ items: notifications }">
|
2023-01-14 10:23:49 +02:00
|
|
|
<MkDateSeparatedList v-slot="{ item: notification }" :class="$style.list" :items="notifications" :no-gap="true">
|
2023-03-31 08:14:30 +03:00
|
|
|
<MkNote v-if="['reply', 'quote', 'mention'].includes(notification.type)" :key="notification.id" :note="notification.note"/>
|
2023-01-27 04:35:04 +02:00
|
|
|
<XNotification v-else :key="notification.id" :notification="notification" :with-time="true" :full="true" class="_panel notification"/>
|
2023-01-09 22:31:02 +02:00
|
|
|
</MkDateSeparatedList>
|
2022-01-09 14:35:35 +02:00
|
|
|
</template>
|
|
|
|
</MkPagination>
|
2020-01-29 21:37:25 +02:00
|
|
|
</template>
|
|
|
|
|
2022-01-09 14:35:35 +02:00
|
|
|
<script lang="ts" setup>
|
2023-02-16 16:09:41 +02:00
|
|
|
import { onUnmounted, onMounted, computed, shallowRef } from 'vue';
|
2022-09-06 12:21:49 +03:00
|
|
|
import MkPagination, { Paging } 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-05-15 13:08:46 +03:00
|
|
|
import { useStream } from '@/stream';
|
2022-01-09 14:35:35 +02:00
|
|
|
import { $i } from '@/account';
|
2022-07-20 16:24:26 +03:00
|
|
|
import { i18n } from '@/i18n';
|
2023-02-23 13:46:14 +02:00
|
|
|
import { notificationTypes } from '@/const';
|
2022-01-09 14:35:35 +02:00
|
|
|
|
|
|
|
const props = defineProps<{
|
2022-03-20 20:11:14 +02:00
|
|
|
includeTypes?: 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
|
|
|
|
|
|
|
const pagination: Paging = {
|
|
|
|
endpoint: 'i/notifications' as const,
|
|
|
|
limit: 10,
|
|
|
|
params: computed(() => ({
|
2022-03-06 09:06:27 +02:00
|
|
|
includeTypes: props.includeTypes ?? undefined,
|
|
|
|
excludeTypes: props.includeTypes ? undefined : $i.mutingNotificationTypes,
|
2022-01-09 14:35:35 +02:00
|
|
|
})),
|
|
|
|
};
|
|
|
|
|
|
|
|
const onNotification = (notification) => {
|
2022-03-06 09:06:27 +02:00
|
|
|
const isMuted = props.includeTypes ? !props.includeTypes.includes(notification.type) : $i.mutingNotificationTypes.includes(notification.type);
|
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) {
|
2023-04-04 08:06:57 +03:00
|
|
|
pagingComponent.value.prepend(notification);
|
2020-01-29 21:37:25 +02:00
|
|
|
}
|
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
|
|
|
|
2022-06-25 21:12:58 +03:00
|
|
|
onUnmounted(() => {
|
|
|
|
if (connection) connection.dispose();
|
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>
|