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