2020-01-29 21:37:25 +02:00
|
|
|
<template>
|
2021-04-16 18:12:50 +03:00
|
|
|
<transition name="fade" mode="out-in">
|
2021-04-16 17:19:39 +03:00
|
|
|
<MkLoading v-if="fetching"/>
|
|
|
|
|
2021-04-16 18:12:50 +03:00
|
|
|
<MkError v-else-if="error" @retry="init()"/>
|
2020-01-29 21:37:25 +02:00
|
|
|
|
2021-11-19 12:36:12 +02:00
|
|
|
<p v-else-if="empty" class="mfcuwfyp">{{ $ts.noNotifications }}</p>
|
2020-01-29 21:37:25 +02:00
|
|
|
|
2021-04-18 08:29:31 +03:00
|
|
|
<div v-else>
|
2021-11-19 12:36:12 +02:00
|
|
|
<XList v-slot="{ item: notification }" class="elsfgstc" :items="items" :no-gap="true">
|
|
|
|
<XNote v-if="['reply', 'quote', 'mention'].includes(notification.type)" :key="notification.id" :note="notification.note" @update:note="noteUpdated(notification.note, $event)"/>
|
|
|
|
<XNotification v-else :key="notification.id" :notification="notification" :with-time="true" :full="true" class="_panel notification"/>
|
2021-04-16 18:12:50 +03:00
|
|
|
</XList>
|
2020-01-29 21:37:25 +02:00
|
|
|
|
2021-11-19 12:36:12 +02:00
|
|
|
<MkButton v-show="more" v-appear="$store.state.enableInfiniteScroll ? fetchMore : null" primary style="margin: var(--margin) auto;" :disabled="moreFetching" :style="{ cursor: moreFetching ? 'wait' : 'pointer' }" @click="fetchMore">
|
2021-04-16 18:12:50 +03:00
|
|
|
<template v-if="!moreFetching">{{ $ts.loadMore }}</template>
|
|
|
|
<template v-if="moreFetching"><MkLoading inline/></template>
|
2021-05-30 10:42:22 +03:00
|
|
|
</MkButton>
|
2021-04-16 18:12:50 +03:00
|
|
|
</div>
|
|
|
|
</transition>
|
2020-01-29 21:37:25 +02:00
|
|
|
</template>
|
|
|
|
|
|
|
|
<script lang="ts">
|
2021-07-26 05:12:06 +03:00
|
|
|
import { defineComponent, PropType, markRaw } from 'vue';
|
2021-11-11 19:02:25 +02:00
|
|
|
import paging from '@/scripts/paging';
|
2020-01-29 21:37:25 +02:00
|
|
|
import XNotification from './notification.vue';
|
|
|
|
import XList from './date-separated-list.vue';
|
2020-02-18 23:26:29 +02:00
|
|
|
import XNote from './note.vue';
|
2021-11-11 19:02:25 +02:00
|
|
|
import { notificationTypes } from 'misskey-js';
|
|
|
|
import * as os from '@/os';
|
2021-12-29 15:13:09 +02:00
|
|
|
import { stream } from '@/stream';
|
2021-11-11 19:02:25 +02:00
|
|
|
import MkButton from '@/components/ui/button.vue';
|
2020-01-29 21:37:25 +02:00
|
|
|
|
2020-10-17 14:12:00 +03:00
|
|
|
export default defineComponent({
|
2020-01-29 21:37:25 +02:00
|
|
|
components: {
|
|
|
|
XNotification,
|
|
|
|
XList,
|
2020-02-18 23:26:29 +02:00
|
|
|
XNote,
|
2021-05-30 10:42:22 +03:00
|
|
|
MkButton,
|
2020-01-29 21:37:25 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
mixins: [
|
|
|
|
paging({}),
|
|
|
|
],
|
|
|
|
|
|
|
|
props: {
|
2020-08-22 04:06:17 +03:00
|
|
|
includeTypes: {
|
|
|
|
type: Array as PropType<typeof notificationTypes[number][]>,
|
|
|
|
required: false,
|
|
|
|
default: null,
|
2020-01-29 21:37:25 +02:00
|
|
|
},
|
2021-10-09 06:44:19 +03:00
|
|
|
unreadOnly: {
|
|
|
|
type: Boolean,
|
|
|
|
required: false,
|
|
|
|
default: false,
|
|
|
|
},
|
2020-01-29 21:37:25 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
connection: null,
|
|
|
|
pagination: {
|
|
|
|
endpoint: 'i/notifications',
|
|
|
|
limit: 10,
|
|
|
|
params: () => ({
|
2020-08-22 04:06:17 +03:00
|
|
|
includeTypes: this.allIncludeTypes || undefined,
|
2021-10-09 06:44:19 +03:00
|
|
|
unreadOnly: this.unreadOnly,
|
2020-01-29 21:37:25 +02:00
|
|
|
})
|
|
|
|
},
|
|
|
|
};
|
|
|
|
},
|
|
|
|
|
2020-08-22 04:06:17 +03:00
|
|
|
computed: {
|
|
|
|
allIncludeTypes() {
|
2020-12-19 03:55:52 +02:00
|
|
|
return this.includeTypes ?? notificationTypes.filter(x => !this.$i.mutingNotificationTypes.includes(x));
|
2020-08-22 04:06:17 +03:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2020-01-29 21:37:25 +02:00
|
|
|
watch: {
|
2020-10-17 14:12:00 +03:00
|
|
|
includeTypes: {
|
|
|
|
handler() {
|
2020-08-22 04:06:17 +03:00
|
|
|
this.reload();
|
2020-10-17 14:12:00 +03:00
|
|
|
},
|
|
|
|
deep: true
|
|
|
|
},
|
2021-10-09 06:44:19 +03:00
|
|
|
unreadOnly: {
|
|
|
|
handler() {
|
|
|
|
this.reload();
|
|
|
|
},
|
|
|
|
},
|
2020-12-19 03:55:52 +02:00
|
|
|
// TODO: vue/vuexのバグか仕様かは不明なものの、プロフィール更新するなどして $i が更新されると、
|
2020-10-17 14:12:00 +03:00
|
|
|
// mutingNotificationTypes に変化が無くてもこのハンドラーが呼び出され無駄なリロードが発生するのを直す
|
2020-12-19 03:55:52 +02:00
|
|
|
'$i.mutingNotificationTypes': {
|
2020-10-17 14:12:00 +03:00
|
|
|
handler() {
|
|
|
|
if (this.includeTypes === null) {
|
|
|
|
this.reload();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
deep: true
|
2020-01-29 21:37:25 +02:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
mounted() {
|
2021-12-29 15:13:09 +02:00
|
|
|
this.connection = markRaw(stream.useChannel('main'));
|
2020-01-29 21:37:25 +02:00
|
|
|
this.connection.on('notification', this.onNotification);
|
|
|
|
},
|
|
|
|
|
2020-10-17 14:12:00 +03:00
|
|
|
beforeUnmount() {
|
2020-01-29 21:37:25 +02:00
|
|
|
this.connection.dispose();
|
|
|
|
},
|
|
|
|
|
|
|
|
methods: {
|
|
|
|
onNotification(notification) {
|
2020-09-18 16:18:21 +03:00
|
|
|
const isMuted = !this.allIncludeTypes.includes(notification.type);
|
2020-08-22 04:06:17 +03:00
|
|
|
if (isMuted || document.visibilityState === 'visible') {
|
2021-12-29 15:13:09 +02:00
|
|
|
stream.send('readNotification', {
|
2020-05-24 12:41:40 +03:00
|
|
|
id: notification.id
|
|
|
|
});
|
|
|
|
}
|
2020-01-29 21:37:25 +02:00
|
|
|
|
2020-08-22 04:06:17 +03:00
|
|
|
if (!isMuted) {
|
|
|
|
this.prepend({
|
|
|
|
...notification,
|
|
|
|
isRead: document.visibilityState === 'visible'
|
|
|
|
});
|
|
|
|
}
|
2020-01-29 21:37:25 +02:00
|
|
|
},
|
2020-07-29 17:03:08 +03:00
|
|
|
|
|
|
|
noteUpdated(oldValue, newValue) {
|
|
|
|
const i = this.items.findIndex(n => n.note === oldValue);
|
2020-10-17 14:12:00 +03:00
|
|
|
this.items[i] = {
|
2020-07-29 17:03:08 +03:00
|
|
|
...this.items[i],
|
|
|
|
note: newValue
|
2020-10-17 14:12:00 +03:00
|
|
|
};
|
2020-07-29 17:03:08 +03:00
|
|
|
},
|
2020-01-29 21:37:25 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<style lang="scss" scoped>
|
2021-04-16 18:12:50 +03:00
|
|
|
.fade-enter-active,
|
|
|
|
.fade-leave-active {
|
|
|
|
transition: opacity 0.125s ease;
|
|
|
|
}
|
|
|
|
.fade-enter-from,
|
|
|
|
.fade-leave-to {
|
|
|
|
opacity: 0;
|
|
|
|
}
|
2020-01-29 21:37:25 +02:00
|
|
|
|
2021-04-16 18:12:50 +03:00
|
|
|
.mfcuwfyp {
|
|
|
|
margin: 0;
|
|
|
|
padding: 16px;
|
|
|
|
text-align: center;
|
|
|
|
color: var(--fg);
|
2020-01-29 21:37:25 +02:00
|
|
|
}
|
2021-08-21 11:40:15 +03:00
|
|
|
|
|
|
|
.elsfgstc {
|
|
|
|
background: var(--panel);
|
|
|
|
}
|
2020-01-29 21:37:25 +02:00
|
|
|
</style>
|