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() {
514514 /** @type {RecentChat[]} */
515515 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)))
518523 .map(chat => ({ chat, character: characters.find(x => x.avatar === chat.avatar), group: groups.find(x => x.id === chat.group) }))
519524 .filter(t => t.character || t.group);
520- .forEach(({ chat, character, group }, index) => {
525+
526+ dataWithEntities.forEach(({ chat, character, group }, index) => {
521527 const chatTimestamp = timestampToMoment(chat.last_mes);
522528 chat.char_name = character?.name || group?.name || '';
523529 chat.date_short = chatTimestamp.format('l');
@@ -530,7 +536,7 @@ async function getRecentChats() {
530536 chat.group = chat.group || '';
531537 });
532538
533- return data;
539+ return dataWithEntities.map(t => t.chat);
534540}
535541
536542export async function openPermanentAssistantChat({ tryCreate = true, created = false } = {}) {