This commit is contained in:
tamaina 2023-07-18 07:15:20 +00:00
parent b0c6675ef3
commit f3a0839552

View file

@ -41,7 +41,7 @@
import { computed, ComputedRef, isRef, nextTick, onActivated, onBeforeUnmount, onDeactivated, onMounted, ref, watch } from 'vue'; import { computed, ComputedRef, isRef, nextTick, onActivated, onBeforeUnmount, onDeactivated, onMounted, ref, watch } from 'vue';
import * as misskey from 'misskey-js'; import * as misskey from 'misskey-js';
import * as os from '@/os'; import * as os from '@/os';
import { isBottomVisible, isTopVisible, getScrollContainer, scrollToBottom, scrollToTop } from '@/scripts/scroll'; import { isBottomVisible, isTopVisible, getScrollContainer, scrollToBottom, scrollToTop, scrollBy } from '@/scripts/scroll';
import { useDocumentVisibility } from '@/scripts/use-document-visibility'; import { useDocumentVisibility } from '@/scripts/use-document-visibility';
import MkButton from '@/components/MkButton.vue'; import MkButton from '@/components/MkButton.vue';
import { defaultStore } from '@/store'; import { defaultStore } from '@/store';
@ -159,9 +159,11 @@ const scrollableElementOrHtml = $computed(() => scrollableElement ?? document.ge
const visibility = useDocumentVisibility(); const visibility = useDocumentVisibility();
const isPausingUpdate = ref(false); const isPausingUpdateByVisibility = ref(false);
const timerForSetPause = ref<number | null>(null); const timerForSetPause = ref<number | null>(null);
const isPausingUpdateByExecutingQueue = ref(false);
//#region scrolling //#region scrolling
const checkFn = props.pagination.reversed ? isBottomVisible : isTopVisible; const checkFn = props.pagination.reversed ? isBottomVisible : isTopVisible;
const checkTop = (tolerance?: number) => { const checkTop = (tolerance?: number) => {
@ -426,7 +428,7 @@ const appearFetchMoreAhead = async (): Promise<void> => {
function visibilityChange() { function visibilityChange() {
if (visibility.value === 'hidden') { if (visibility.value === 'hidden') {
timerForSetPause.value = window.setTimeout(() => { timerForSetPause.value = window.setTimeout(() => {
isPausingUpdate.value = true; isPausingUpdateByVisibility.value = true;
timerForSetPause.value = null; timerForSetPause.value = null;
}, },
BACKGROUND_PAUSE_WAIT_SEC * 1000); BACKGROUND_PAUSE_WAIT_SEC * 1000);
@ -435,7 +437,7 @@ function visibilityChange() {
clearTimeout(timerForSetPause.value); clearTimeout(timerForSetPause.value);
timerForSetPause.value = null; timerForSetPause.value = null;
} else { } else {
isPausingUpdate.value = false; isPausingUpdateByVisibility.value = false;
if (!backed && active.value) { if (!backed && active.value) {
executeQueue(); executeQueue();
} }
@ -469,14 +471,24 @@ const prepend = (item: MisskeyEntity): void => {
} }
if ( if (
!isPausingUpdate.value && // /調 !isPausingUpdateByExecutingQueue.value && // 調
queueSize.value === 0 && // queueSize.value === 0 && //
active.value // keepAlive active.value // keepAlive
) { ) {
if (!backed) { if (!backed) {
// //
if (items.value.has(item.id)) return; // if (items.value.has(item.id)) return; //
if (isPausingUpdateByVisibility.value) {
//
// prependQueue
prependQueue(item);
//
scrollBy(scrollableElement, { top: 24, behavior: 'instant' });
// backedtrue
backed = true;
} else {
unshiftItems([item]); unshiftItems([item]);
}
} else if (!weakBacked) { } else if (!weakBacked) {
// 調 // 調
prependQueue(item); prependQueue(item);
@ -515,21 +527,18 @@ function concatItems(oldItems: MisskeyEntity[]) {
async function executeQueue() { async function executeQueue() {
if (queue.value.size === 0) return; if (queue.value.size === 0) return;
if (isPausingUpdate.value) return; if (isPausingUpdateByExecutingQueue.value) return;
const queueArr = Array.from(queue.value.entries()); const queueArr = Array.from(queue.value.entries());
queue.value = new Map(queueArr.slice(props.pagination.limit)); queue.value = new Map(queueArr.slice(props.pagination.limit));
isPausingUpdate.value = true; isPausingUpdateByExecutingQueue.value = true;
try {
unshiftItems( unshiftItems(
queueArr.slice(0, props.pagination.limit).map(v => v[1]).reverse(), queueArr.slice(0, props.pagination.limit).map(v => v[1]).reverse(),
Infinity, Infinity,
); );
await nextTick();
items.value = new Map([...items.value].slice(0, displayLimit.value)); items.value = new Map([...items.value].slice(0, displayLimit.value));
await nextTick(); await nextTick();
} finally { isPausingUpdateByExecutingQueue.value = false;
isPausingUpdate.value = false;
}
} }
function prependQueue(newItem: MisskeyEntity) { function prependQueue(newItem: MisskeyEntity) {