Filter recent chats from deleted entities on welcome screen

04f844577c9dd112b96c326bef764f443e669d7b

Cohee <18619528+Cohee1207@users.noreply.github.com>

1 files changed, +10 -4Showing whitespace changes
public/scripts/welcome-screen.js+10 -4
@@ -514,10 +514,16 @@ async function getRecentChats() {
514 /** @type {RecentChat[]} */514 /** @type {RecentChat[]} */
515 const data = await response.json();515 const data = await response.json();
516516
517 data.sort((a, b) => sortMoments(timestampToMoment(a.last_mes), timestampToMoment(b.last_mes)))517 if (!Array.isArray(data) || data.length === 0) {
518 return [];
519 }
520
521 const dataWithEntities = data
522 .sort((a, b) => sortMoments(timestampToMoment(a.last_mes), timestampToMoment(b.last_mes)))
518 .map(chat => ({ chat, character: characters.find(x => x.avatar === chat.avatar), group: groups.find(x => x.id === chat.group) }))523 .map(chat => ({ chat, character: characters.find(x => x.avatar === chat.avatar), group: groups.find(x => x.id === chat.group) }))
519 .filter(t => t.character || t.group)524 .filter(t => t.character || t.group);
520 .forEach(({ chat, character, group }, index) => {525
526 dataWithEntities.forEach(({ chat, character, group }, index) => {
521 const chatTimestamp = timestampToMoment(chat.last_mes);527 const chatTimestamp = timestampToMoment(chat.last_mes);
522 chat.char_name = character?.name || group?.name || '';528 chat.char_name = character?.name || group?.name || '';
523 chat.date_short = chatTimestamp.format('l');529 chat.date_short = chatTimestamp.format('l');
@@ -530,7 +536,7 @@ async function getRecentChats() {
530 chat.group = chat.group || '';536 chat.group = chat.group || '';
531 });537 });
532538
533 return data;539 return dataWithEntities.map(t => t.chat);
534}540}
535541
536export async function openPermanentAssistantChat({ tryCreate = true, created = false } = {}) {542export async function openPermanentAssistantChat({ tryCreate = true, created = false } = {}) {