2020-01-29 20:37:25 +01:00
|
|
|
<template>
|
2022-01-09 13:35:35 +01: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 15:24:26 +02:00
|
|
|
<div>{{ i18n.ts.noNotifications }}</div>
|
2022-01-09 13:35:35 +01:00
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<template #default="{ items: notifications }">
|
2023-01-14 09:23:49 +01:00
|
|
|
<MkDateSeparatedList v-slot="{ item: notification }" :class="$style.list" :items="notifications" :no-gap="true">
|
2022-01-14 02:25:51 +01:00
|
|
|
<XNote v-if="['reply', 'quote', 'mention'].includes(notification.type)" :key="notification.id" :note="notification.note"/>
|
2023-01-27 03:35:04 +01:00
|
|
|
<XNotification v-else :key="notification.id" :notification="notification" :with-time="true" :full="true" class="_panel notification"/>
|
2023-01-09 21:31:02 +01:00
|
|
|
</MkDateSeparatedList>
|
2022-01-09 13:35:35 +01:00
|
|
|
</template>
|
|
|
|
</MkPagination>
|
2020-01-29 20:37:25 +01:00
|
|
|
</template>
|
|
|
|
|
2022-01-09 13:35:35 +01:00
|
|
|
<script lang="ts" setup>
|
2023-02-16 15:09:41 +01:00
|
|
|
import { onUnmounted, onMounted, computed, shallowRef } from 'vue';
|
2022-09-06 11:21:49 +02:00
|
|
|
import MkPagination, { Paging } 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';
|
2022-08-30 17:24:33 +02:00
|
|
|
import XNote from '@/components/MkNote.vue';
|
2021-12-29 14:13:09 +01:00
|
|
|
import { stream } from '@/stream';
|
2022-01-09 13:35:35 +01:00
|
|
|
import { $i } from '@/account';
|
2022-07-20 15:24:26 +02:00
|
|
|
import { i18n } from '@/i18n';
|
2023-02-23 12:46:14 +01:00
|
|
|
import { notificationTypes } from '@/const';
|
2022-01-09 13:35:35 +01:00
|
|
|
|
|
|
|
const props = defineProps<{
|
2022-03-20 19:11:14 +01:00
|
|
|
includeTypes?: typeof notificationTypes[number][];
|
2022-01-09 13:35:35 +01:00
|
|
|
unreadOnly?: boolean;
|
|
|
|
}>();
|
|
|
|
|
2023-01-03 05:37:32 +01:00
|
|
|
const pagingComponent = shallowRef<InstanceType<typeof MkPagination>>();
|
2022-01-09 13:35:35 +01:00
|
|
|
|
|
|
|
const pagination: Paging = {
|
|
|
|
endpoint: 'i/notifications' as const,
|
|
|
|
limit: 10,
|
|
|
|
params: computed(() => ({
|
2022-03-06 08:06:27 +01:00
|
|
|
includeTypes: props.includeTypes ?? undefined,
|
|
|
|
excludeTypes: props.includeTypes ? undefined : $i.mutingNotificationTypes,
|
2022-01-09 13:35:35 +01:00
|
|
|
unreadOnly: props.unreadOnly,
|
|
|
|
})),
|
|
|
|
};
|
|
|
|
|
|
|
|
const onNotification = (notification) => {
|
2022-03-06 08:06:27 +01:00
|
|
|
const isMuted = props.includeTypes ? !props.includeTypes.includes(notification.type) : $i.mutingNotificationTypes.includes(notification.type);
|
2022-01-09 13:35:35 +01:00
|
|
|
if (isMuted || document.visibilityState === 'visible') {
|
|
|
|
stream.send('readNotification', {
|
2022-06-05 05:26:36 +02:00
|
|
|
id: notification.id,
|
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) {
|
|
|
|
pagingComponent.value.prepend({
|
|
|
|
...notification,
|
2022-06-05 05:26:36 +02:00
|
|
|
isRead: document.visibilityState === 'visible',
|
2022-01-09 13:35:35 +01:00
|
|
|
});
|
2020-01-29 20:37:25 +01:00
|
|
|
}
|
2022-01-09 13:35:35 +01:00
|
|
|
};
|
|
|
|
|
2022-06-25 20:12:58 +02:00
|
|
|
let connection;
|
|
|
|
|
2022-01-09 13:35:35 +01:00
|
|
|
onMounted(() => {
|
2022-06-25 20:12:58 +02:00
|
|
|
connection = stream.useChannel('main');
|
2022-01-09 13:35:35 +01:00
|
|
|
connection.on('notification', onNotification);
|
2022-04-30 14:52:07 +02:00
|
|
|
connection.on('readAllNotifications', () => {
|
|
|
|
if (pagingComponent.value) {
|
|
|
|
for (const item of pagingComponent.value.queue) {
|
|
|
|
item.isRead = true;
|
|
|
|
}
|
|
|
|
for (const item of pagingComponent.value.items) {
|
|
|
|
item.isRead = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
connection.on('readNotifications', notificationIds => {
|
|
|
|
if (pagingComponent.value) {
|
|
|
|
for (let i = 0; i < pagingComponent.value.queue.length; i++) {
|
|
|
|
if (notificationIds.includes(pagingComponent.value.queue[i].id)) {
|
|
|
|
pagingComponent.value.queue[i].isRead = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for (let i = 0; i < (pagingComponent.value.items || []).length; i++) {
|
|
|
|
if (notificationIds.includes(pagingComponent.value.items[i].id)) {
|
|
|
|
pagingComponent.value.items[i].isRead = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
2022-06-25 20:12:58 +02:00
|
|
|
});
|
2022-04-30 14:52:07 +02:00
|
|
|
|
2022-06-25 20:12:58 +02:00
|
|
|
onUnmounted(() => {
|
|
|
|
if (connection) connection.dispose();
|
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>
|