enhance(timeline): タブがバックグラウンドから戻ってきた時、ノートの取得をまとめて行うように (MisskeyIO#960)
This commit is contained in:
parent
eb5e94dbf8
commit
d36be50b1c
1 changed files with 33 additions and 22 deletions
|
@ -71,12 +71,7 @@ const tlComponent = shallowRef<InstanceType<typeof MkNotes>>();
|
||||||
let tlNotesCount = 0;
|
let tlNotesCount = 0;
|
||||||
const notVisibleNoteData = new Array<object>();
|
const notVisibleNoteData = new Array<object>();
|
||||||
|
|
||||||
async function prepend(data) {
|
async function fulfillNoteData(data) {
|
||||||
if (tlComponent.value == null) return;
|
|
||||||
|
|
||||||
let note = data;
|
|
||||||
|
|
||||||
if (!document.hidden) {
|
|
||||||
// チェックするプロパティはなんでも良い
|
// チェックするプロパティはなんでも良い
|
||||||
// minimizeが有効でid以外が存在しない場合は取得する
|
// minimizeが有効でid以外が存在しない場合は取得する
|
||||||
if (!data.visibility) {
|
if (!data.visibility) {
|
||||||
|
@ -88,10 +83,22 @@ async function prepend(data) {
|
||||||
'X-Client-Transaction-Id': generateClientTransactionId('misskey'),
|
'X-Client-Transaction-Id': generateClientTransactionId('misskey'),
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
if (!res.ok) return;
|
if (!res.ok) return null;
|
||||||
note = deepMerge(data, await res.json());
|
return deepMerge(data, await res.json());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
|
||||||
|
async function prepend(data) {
|
||||||
|
if (tlComponent.value == null) return;
|
||||||
|
|
||||||
|
let note = data;
|
||||||
|
|
||||||
|
if (!document.hidden) {
|
||||||
|
note = await fulfillNoteData(data);
|
||||||
|
if (note == null) return;
|
||||||
|
|
||||||
tlNotesCount++;
|
tlNotesCount++;
|
||||||
|
|
||||||
if (instance.notesPerOneAd > 0 && tlNotesCount % instance.notesPerOneAd === 0) {
|
if (instance.notesPerOneAd > 0 && tlNotesCount % instance.notesPerOneAd === 0) {
|
||||||
|
@ -119,16 +126,20 @@ async function loadUnloadedNotes() {
|
||||||
if (tlComponent.value == null) return;
|
if (tlComponent.value == null) return;
|
||||||
if (notVisibleNoteData.length === 0) return;
|
if (notVisibleNoteData.length === 0) return;
|
||||||
|
|
||||||
if (notVisibleNoteData.length >= 10) {
|
|
||||||
tlComponent.value.pagingComponent?.deleteItem();
|
|
||||||
tlComponent.value.pagingComponent?.stopFetch();
|
tlComponent.value.pagingComponent?.stopFetch();
|
||||||
}
|
try {
|
||||||
|
const items = [...notVisibleNoteData];
|
||||||
|
notVisibleNoteData.length = 0;
|
||||||
|
|
||||||
while (notVisibleNoteData.length > 0) {
|
const notes = await Promise.allSettled(items.map(fulfillNoteData));
|
||||||
await prepend(notVisibleNoteData.shift());
|
if (items.length >= 10) tlComponent.value.pagingComponent?.deleteItem();
|
||||||
}
|
|
||||||
|
|
||||||
|
for (const note of notes.filter(i => i.status === 'fulfilled' && i.value != null)) {
|
||||||
|
await prepend((note as PromiseFulfilledResult<object>).value);
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
tlComponent.value.pagingComponent?.startFetch();
|
tlComponent.value.pagingComponent?.startFetch();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let connection: Misskey.ChannelConnection | null = null;
|
let connection: Misskey.ChannelConnection | null = null;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue