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