Fix update of unread notification counter
This commit is contained in:
parent
fe3a9ff0c2
commit
5cb3863883
4 changed files with 26 additions and 15 deletions
|
@ -11,6 +11,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
|
||||||
- Detect preferred color scheme.
|
- Detect preferred color scheme.
|
||||||
- Show loading indicator while attachment is being uploaded.
|
- Show loading indicator while attachment is being uploaded.
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
|
||||||
|
- Fix update of unread notification counter.
|
||||||
|
|
||||||
## [1.21.0] - 2023-04-12
|
## [1.21.0] - 2023-04-12
|
||||||
|
|
||||||
### Changed
|
### Changed
|
||||||
|
|
|
@ -62,7 +62,6 @@ const { loadTheme } = useTheme()
|
||||||
onMounted(async () => {
|
onMounted(async () => {
|
||||||
if (isUserAuthenticated()) {
|
if (isUserAuthenticated()) {
|
||||||
loadTheme()
|
loadTheme()
|
||||||
// TODO: reload notifications periodically
|
|
||||||
await loadNotifications(ensureAuthToken())
|
await loadNotifications(ensureAuthToken())
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
import { ref } from "vue"
|
import { ref } from "vue"
|
||||||
|
|
||||||
import { getNotificationMarker } from "@/api/markers"
|
import { getNotificationMarker, updateNotificationMarker } from "@/api/markers"
|
||||||
import { Notification, getNotifications } from "@/api/notifications"
|
import { Notification, getNotifications } from "@/api/notifications"
|
||||||
|
|
||||||
const notifications = ref<Notification[]>([])
|
const notifications = ref<Notification[]>([])
|
||||||
|
@ -33,9 +33,24 @@ export function useNotifications() {
|
||||||
return unreadCount
|
return unreadCount
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function updateUnreadNotificationCount(authToken: string) {
|
||||||
|
const firstNotification = notifications.value[0]
|
||||||
|
if (
|
||||||
|
firstNotification &&
|
||||||
|
firstNotification.id !== lastReadId.value
|
||||||
|
) {
|
||||||
|
await updateNotificationMarker(
|
||||||
|
authToken,
|
||||||
|
firstNotification.id,
|
||||||
|
)
|
||||||
|
lastReadId.value = firstNotification.id
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
notifications,
|
notifications,
|
||||||
loadNotifications,
|
loadNotifications,
|
||||||
getUnreadNotificationCount,
|
getUnreadNotificationCount,
|
||||||
|
updateUnreadNotificationCount,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -67,11 +67,10 @@
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { onMounted } from "vue"
|
import { watch } from "vue"
|
||||||
import { $ } from "vue/macros"
|
import { $, $$ } from "vue/macros"
|
||||||
|
|
||||||
import { PAGE_SIZE } from "@/api/common"
|
import { PAGE_SIZE } from "@/api/common"
|
||||||
import { updateNotificationMarker } from "@/api/markers"
|
|
||||||
import { getNotifications, Notification } from "@/api/notifications"
|
import { getNotifications, Notification } from "@/api/notifications"
|
||||||
import { ProfileWrapper } from "@/api/users"
|
import { ProfileWrapper } from "@/api/users"
|
||||||
import Avatar from "@/components/Avatar.vue"
|
import Avatar from "@/components/Avatar.vue"
|
||||||
|
@ -85,18 +84,12 @@ import { humanizeDate } from "@/utils/dates"
|
||||||
|
|
||||||
const { ensureAuthToken } = useCurrentUser()
|
const { ensureAuthToken } = useCurrentUser()
|
||||||
const { getActorAddress } = useInstanceInfo()
|
const { getActorAddress } = useInstanceInfo()
|
||||||
let { notifications } = $(useNotifications())
|
let { notifications, updateUnreadNotificationCount } = $(useNotifications())
|
||||||
|
|
||||||
onMounted(async () => {
|
watch($$(notifications), async () => {
|
||||||
// Update notification timeline marker
|
// Update notification timeline marker
|
||||||
const firstNotification = notifications[0]
|
await updateUnreadNotificationCount(ensureAuthToken())
|
||||||
if (firstNotification) {
|
}, { immediate: true })
|
||||||
await updateNotificationMarker(
|
|
||||||
ensureAuthToken(),
|
|
||||||
firstNotification.id,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
function getSender(notification: Notification): ProfileWrapper {
|
function getSender(notification: Notification): ProfileWrapper {
|
||||||
return new ProfileWrapper(notification.account)
|
return new ProfileWrapper(notification.account)
|
||||||
|
|
Loading…
Reference in a new issue