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