mirror of
https://git.joinsharkey.org/Sharkey/Sharkey.git
synced 2024-12-25 21:53:08 +02:00
✌️
This commit is contained in:
parent
b0c6675ef3
commit
f3a0839552
1 changed files with 29 additions and 20 deletions
|
@ -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' });
|
||||||
|
// 一応backedを強制的にtrueにする
|
||||||
|
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) {
|
||||||
|
|
Loading…
Reference in a new issue