feat: make notification read more smart

This commit is contained in:
Lhc_fl 2024-09-17 18:11:46 +08:00 committed by laoXong
parent 507e9e580f
commit 70045735a7
2 changed files with 20 additions and 1 deletions

2
.gitignore vendored
View File

@ -78,3 +78,5 @@ vite.config.ts.timestamp-*
# VSCode addon
.favorites.json
/dump.rdb

View File

@ -5,7 +5,7 @@ SPDX-License-Identifier: AGPL-3.0-only
<template>
<MkPullToRefresh :refresher="() => reload()">
<MkPagination ref="pagingComponent" :pagination="pagination">
<MkPagination ref="pagingComponent" :pagination="pagination" @queue="onQueue">
<template #empty>
<div class="_fullinfo">
<img :src="infoImageUrl" class="_ghost"/>
@ -65,9 +65,26 @@ function onNotification(notification) {
if (!isMuted) {
pagingComponent.value?.prepend(notification);
onQueue();
}
}
let queued = false;
function checkAllNotificationsCanRead() {
queued = false;
if (!document.hasFocus()) { onQueue(); return; }
if (!(pagingComponent.value?.queue.size) && !(props.excludeTypes?.length)) {
misskeyApi('notifications/mark-all-as-read');
}
}
function onQueue() {
if (queued) return;
queued = true;
setTimeout(() => checkAllNotificationsCanRead(), 2000);
}
function reload() {
return new Promise<void>((res) => {
pagingComponent.value?.reload().then(() => {