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">
|
|
|
|
<img src="https://xn--931a.moe/assets/info.jpg" 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 }">
|
|
|
|
<XList v-slot="{ item: notification }" class="elsfgstc" :items="notifications" :no-gap="true">
|
2022-01-13 17:25:51 -08:00
|
|
|
<XNote v-if="['reply', 'quote', 'mention'].includes(notification.type)" :key="notification.id" :note="notification.note"/>
|
2021-11-19 02:36:12 -08:00
|
|
|
<XNotification v-else :key="notification.id" :notification="notification" :with-time="true" :full="true" class="_panel notification"/>
|
2021-04-16 08:12:50 -07:00
|
|
|
</XList>
|
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>
|
2022-03-20 11:11:14 -07:00
|
|
|
import { defineComponent, markRaw, onUnmounted, onMounted, computed, ref } from 'vue';
|
2021-11-11 09:02:25 -08:00
|
|
|
import { notificationTypes } from 'misskey-js';
|
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';
|
|
|
|
import XList from '@/components/MkDateSeparatedList.vue';
|
|
|
|
import XNote from '@/components/MkNote.vue';
|
2021-11-11 09:02:25 -08:00
|
|
|
import * as os from '@/os';
|
2021-12-29 05:13:09 -08:00
|
|
|
import { stream } 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';
|
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
|
|
|
unreadOnly?: boolean;
|
|
|
|
}>();
|
|
|
|
|
|
|
|
const pagingComponent = ref<InstanceType<typeof MkPagination>>();
|
|
|
|
|
|
|
|
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
|
|
|
unreadOnly: props.unreadOnly,
|
|
|
|
})),
|
|
|
|
};
|
|
|
|
|
|
|
|
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') {
|
|
|
|
stream.send('readNotification', {
|
2022-06-04 20:26:36 -07:00
|
|
|
id: notification.id,
|
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) {
|
|
|
|
pagingComponent.value.prepend({
|
|
|
|
...notification,
|
2022-06-04 20:26:36 -07:00
|
|
|
isRead: document.visibilityState === 'visible',
|
2022-01-09 04:35:35 -08:00
|
|
|
});
|
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(() => {
|
2022-06-25 11:12:58 -07:00
|
|
|
connection = stream.useChannel('main');
|
2022-01-09 04:35:35 -08:00
|
|
|
connection.on('notification', onNotification);
|
2022-04-30 05:52:07 -07: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 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>
|
|
|
|
|
2022-12-27 01:29:39 -08:00
|
|
|
<style lang="scss" scoped>
|
2021-08-21 01:40:15 -07:00
|
|
|
.elsfgstc {
|
|
|
|
background: var(--panel);
|
|
|
|
}
|
2020-01-29 11:37:25 -08:00
|
|
|
</style>
|