enhance(timeline): タブがバックグラウンドから戻ってきた時、ノートの取得をまとめて行うように (MisskeyIO#960)

This commit is contained in:
あわわわとーにゅ 2025-04-01 02:56:21 +09:00 committed by GitHub
parent eb5e94dbf8
commit d36be50b1c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -71,26 +71,33 @@ const tlComponent = shallowRef<InstanceType<typeof MkNotes>>();
let tlNotesCount = 0; let tlNotesCount = 0;
const notVisibleNoteData = new Array<object>(); const notVisibleNoteData = new Array<object>();
async function fulfillNoteData(data) {
//
// minimizeid
if (!data.visibility) {
const res = await window.fetch(`/notes/${data.id}.json`, {
method: 'GET',
credentials: 'omit',
headers: {
'Authorization': 'anonymous',
'X-Client-Transaction-Id': generateClientTransactionId('misskey'),
},
});
if (!res.ok) return null;
return deepMerge(data, await res.json());
}
return data;
}
async function prepend(data) { async function prepend(data) {
if (tlComponent.value == null) return; if (tlComponent.value == null) return;
let note = data; let note = data;
if (!document.hidden) { if (!document.hidden) {
// note = await fulfillNoteData(data);
// minimizeid if (note == null) return;
if (!data.visibility) {
const res = await window.fetch(`/notes/${data.id}.json`, {
method: 'GET',
credentials: 'omit',
headers: {
'Authorization': 'anonymous',
'X-Client-Transaction-Id': generateClientTransactionId('misskey'),
},
});
if (!res.ok) return;
note = deepMerge(data, await res.json());
}
tlNotesCount++; tlNotesCount++;
@ -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?.stopFetch();
tlComponent.value.pagingComponent?.deleteItem(); try {
tlComponent.value.pagingComponent?.stopFetch(); 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();
}
tlComponent.value.pagingComponent?.startFetch(); 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();
}
} }
let connection: Misskey.ChannelConnection | null = null; let connection: Misskey.ChannelConnection | null = null;