fix: fix notification count
This commit is contained in:
parent
719c3171f8
commit
78bc8426dd
|
@ -1,7 +1,7 @@
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import type { Notification, LibraryFollow } from '~/types'
|
import type { Notification, LibraryFollow } from '~/types'
|
||||||
|
|
||||||
import { computed, ref, watchEffect } from 'vue'
|
import { computed, ref, watchEffect, watch } from 'vue'
|
||||||
import { useI18n } from 'vue-i18n'
|
import { useI18n } from 'vue-i18n'
|
||||||
import { useStore } from '~/store'
|
import { useStore } from '~/store'
|
||||||
|
|
||||||
|
@ -30,7 +30,7 @@ const notificationData = computed(() => {
|
||||||
|
|
||||||
if (activity.type === 'Follow') {
|
if (activity.type === 'Follow') {
|
||||||
if (activity.object && activity.object.type === 'music.Library') {
|
if (activity.object && activity.object.type === 'music.Library') {
|
||||||
const detailUrl = { name: 'content.libraries.detail', params: { id: activity.object.uuid } }
|
const detailUrl = { name: 'library.detail.edit', params: { id: activity.object.uuid } }
|
||||||
|
|
||||||
if (activity.related_object?.approved === null) {
|
if (activity.related_object?.approved === null) {
|
||||||
return {
|
return {
|
||||||
|
@ -76,7 +76,7 @@ const notificationData = computed(() => {
|
||||||
})
|
})
|
||||||
|
|
||||||
const read = ref(false)
|
const read = ref(false)
|
||||||
watchEffect(async () => {
|
watch(read, async () => {
|
||||||
await axios.patch(`federation/inbox/${item.value.id}/`, { is_read: read.value })
|
await axios.patch(`federation/inbox/${item.value.id}/`, { is_read: read.value })
|
||||||
|
|
||||||
item.value.is_read = read.value
|
item.value.is_read = read.value
|
||||||
|
@ -92,11 +92,13 @@ const handleAction = (handler?: () => void) => {
|
||||||
const approveLibraryFollow = async (follow: LibraryFollow) => {
|
const approveLibraryFollow = async (follow: LibraryFollow) => {
|
||||||
await axios.post(`federation/follows/library/${follow.uuid}/accept/`)
|
await axios.post(`federation/follows/library/${follow.uuid}/accept/`)
|
||||||
follow.approved = true
|
follow.approved = true
|
||||||
|
item.value.is_read = true
|
||||||
}
|
}
|
||||||
|
|
||||||
const rejectLibraryFollow = async (follow: LibraryFollow) => {
|
const rejectLibraryFollow = async (follow: LibraryFollow) => {
|
||||||
await axios.post(`federation/follows/library/${follow.uuid}/reject/`)
|
await axios.post(`federation/follows/library/${follow.uuid}/reject/`)
|
||||||
follow.approved = false
|
follow.approved = false
|
||||||
|
item.value.is_read = true
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|
|
@ -4,7 +4,7 @@ import type { Notification } from '~/types'
|
||||||
import moment from 'moment'
|
import moment from 'moment'
|
||||||
import axios from 'axios'
|
import axios from 'axios'
|
||||||
|
|
||||||
import { ref, reactive, computed, watch, markRaw } from 'vue'
|
import { ref, reactive, computed, watch } from 'vue'
|
||||||
import { useI18n } from 'vue-i18n'
|
import { useI18n } from 'vue-i18n'
|
||||||
import { useStore } from '~/store'
|
import { useStore } from '~/store'
|
||||||
|
|
||||||
|
@ -38,7 +38,7 @@ const fetchData = async () => {
|
||||||
try {
|
try {
|
||||||
const response = await axios.get('federation/inbox/', { params: filters })
|
const response = await axios.get('federation/inbox/', { params: filters })
|
||||||
notifications.count = response.data.count
|
notifications.count = response.data.count
|
||||||
notifications.results = response.data.results.map(markRaw)
|
notifications.results = response.data.results
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
useErrorHandler(error as Error)
|
useErrorHandler(error as Error)
|
||||||
}
|
}
|
||||||
|
@ -50,7 +50,7 @@ watch(filters, fetchData, { immediate: true })
|
||||||
|
|
||||||
useWebSocketHandler('inbox.item_added', (event) => {
|
useWebSocketHandler('inbox.item_added', (event) => {
|
||||||
notifications.count += 1
|
notifications.count += 1
|
||||||
notifications.results.unshift(markRaw((event.item)))
|
notifications.results.unshift(event.item)
|
||||||
})
|
})
|
||||||
|
|
||||||
const instanceSupportMessageDelay = ref(60)
|
const instanceSupportMessageDelay = ref(60)
|
||||||
|
|
Loading…
Reference in New Issue