| 514 | 514 | /** @type {RecentChat[]} */ |
| 515 | 515 | const data = await response.json(); |
| 516 | 516 | |
| 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 | 523 | .map(chat => ({ chat, character: characters.find(x => x.avatar === chat.avatar), group: groups.find(x => x.id === chat.group) })) |
| 519 | 524 | .filter(t => t.character || t.group); |
| 520 | | - .forEach(({ chat, character, group }, index) => { |
| 525 | + |
| 526 | + dataWithEntities.forEach(({ chat, character, group }, index) => { |
| 521 | 527 | const chatTimestamp = timestampToMoment(chat.last_mes); |
| 522 | 528 | chat.char_name = character?.name || group?.name || ''; |
| 523 | 529 | chat.date_short = chatTimestamp.format('l'); |