2020-01-29 11:37:25 -08:00
|
|
|
<template>
|
2022-01-09 04:35:35 -08:00
|
|
|
<MkPagination ref="pagingComponent" :pagination="pagination">
|
|
|
|
<template #empty>
|
|
|
|
<div class="_fullinfo">
|
2023-06-08 22:00:53 -07:00
|
|
|
<img :src="infoImageUrl" class="_ghost"/>
|
2022-07-20 06:24:26 -07:00
|
|
|
<div>{{ i18n.ts.noNotifications }}</div>
|
2022-01-09 04:35:35 -08:00
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<template #default="{ items: notifications }">
|
2023-05-18 21:58:09 -07:00
|
|
|
<MkDateSeparatedList v-slot="{ item: notification }" :class="$style.list" :items="notifications" :noGap="true">
|
2023-03-30 22:14:30 -07:00
|
|
|
<MkNote v-if="['reply', 'quote', 'mention'].includes(notification.type)" :key="notification.id" :note="notification.note"/>
|
2023-05-18 21:58:09 -07:00
|
|
|
<XNotification v-else :key="notification.id" :notification="notification" :withTime="true" :full="true" class="_panel notification"/>
|
2023-01-09 12:31:02 -08:00
|
|
|
</MkDateSeparatedList>
|
2022-01-09 04:35:35 -08:00
|
|
|
</template>
|
|
|
|
</MkPagination>
|
2020-01-29 11:37:25 -08:00
|
|
|
</template>
|
|
|
|
|
2022-01-09 04:35:35 -08:00
|
|
|
<script lang="ts" setup>
|
2023-02-16 06:09:41 -08:00
|
|
|
import { onUnmounted, onMounted, computed, shallowRef } from 'vue';
|
2022-09-06 02:21:49 -07:00
|
|
|
import MkPagination, { Paging } from '@/components/MkPagination.vue';
|
2022-08-30 08:24:33 -07:00
|
|
|
import XNotification from '@/components/MkNotification.vue';
|
2023-01-09 12:31:02 -08:00
|
|
|
import MkDateSeparatedList from '@/components/MkDateSeparatedList.vue';
|
2023-03-30 22:14:30 -07:00
|
|
|
import MkNote from '@/components/MkNote.vue';
|
2023-05-15 03:08:46 -07:00
|
|
|
import { useStream } from '@/stream';
|
2022-01-09 04:35:35 -08:00
|
|
|
import { $i } from '@/account';
|
2022-07-20 06:24:26 -07:00
|
|
|
import { i18n } from '@/i18n';
|
2023-02-23 03:46:14 -08:00
|
|
|
import { notificationTypes } from '@/const';
|
2023-06-08 22:00:53 -07:00
|
|
|
import { infoImageUrl } from '@/instance';
|
2022-01-09 04:35:35 -08:00
|
|
|
|
|
|
|
const props = defineProps<{
|
2022-03-20 11:11:14 -07:00
|
|
|
includeTypes?: typeof notificationTypes[number][];
|
2022-01-09 04:35:35 -08:00
|
|
|
}>();
|
|
|
|
|
2023-01-02 20:37:32 -08:00
|
|
|
const pagingComponent = shallowRef<InstanceType<typeof MkPagination>>();
|
2022-01-09 04:35:35 -08:00
|
|
|
|
|
|
|
const pagination: Paging = {
|
|
|
|
endpoint: 'i/notifications' as const,
|
|
|
|
limit: 10,
|
|
|
|
params: computed(() => ({
|
2022-03-05 23:06:27 -08:00
|
|
|
includeTypes: props.includeTypes ?? undefined,
|
|
|
|
excludeTypes: props.includeTypes ? undefined : $i.mutingNotificationTypes,
|
2022-01-09 04:35:35 -08:00
|
|
|
})),
|
|
|
|
};
|
|
|
|
|
|
|
|
const onNotification = (notification) => {
|
2022-03-05 23:06:27 -08:00
|
|
|
const isMuted = props.includeTypes ? !props.includeTypes.includes(notification.type) : $i.mutingNotificationTypes.includes(notification.type);
|
2022-01-09 04:35:35 -08:00
|
|
|
if (isMuted || document.visibilityState === 'visible') {
|
2023-05-15 03:08:46 -07:00
|
|
|
useStream().send('readNotification');
|
2022-01-09 04:35:35 -08:00
|
|
|
}
|
2020-07-29 07:03:08 -07:00
|
|
|
|
2022-01-09 04:35:35 -08:00
|
|
|
if (!isMuted) {
|
2023-04-03 22:06:57 -07:00
|
|
|
pagingComponent.value.prepend(notification);
|
2020-01-29 11:37:25 -08:00
|
|
|
}
|
2022-01-09 04:35:35 -08:00
|
|
|
};
|
|
|
|
|
2022-06-25 11:12:58 -07:00
|
|
|
let connection;
|
|
|
|
|
2022-01-09 04:35:35 -08:00
|
|
|
onMounted(() => {
|
2023-05-15 03:08:46 -07:00
|
|
|
connection = useStream().useChannel('main');
|
2022-01-09 04:35:35 -08:00
|
|
|
connection.on('notification', onNotification);
|
2022-06-25 11:12:58 -07:00
|
|
|
});
|
2022-04-30 05:52:07 -07:00
|
|
|
|
2022-06-25 11:12:58 -07:00
|
|
|
onUnmounted(() => {
|
|
|
|
if (connection) connection.dispose();
|
2020-01-29 11:37:25 -08:00
|
|
|
});
|
|
|
|
</script>
|
|
|
|
|
2023-01-14 00:23:49 -08:00
|
|
|
<style lang="scss" module>
|
|
|
|
.list {
|
2021-08-21 01:40:15 -07:00
|
|
|
background: var(--panel);
|
|
|
|
}
|
2020-01-29 11:37:25 -08:00
|
|
|
</style>
|