fix ui dm chatid lowercase normalization

This commit is contained in:
AidarKC
2026-06-21 12:27:41 +04:00
parent c8ffb6cf29
commit 2a834f1b14
6 changed files with 56 additions and 23 deletions
+6 -4
View File
@@ -10,6 +10,7 @@ import {
markChatRead,
markOutgoingSent,
markReadReceiptSentByBaseKey,
normalizeDmChatId,
authService,
setContacts,
state,
@@ -334,11 +335,12 @@ function renderLog(list, chatId, { onOpenActions } = {}) {
}
export function render({ navigate, route }) {
const chatId = route.params.chatId || 'u1';
const contact = directMessages.find((d) => d.id === chatId) || {
const routeChatId = route.params.chatId || 'u1';
const chatId = normalizeDmChatId(routeChatId) || 'u1';
const contact = directMessages.find((d) => normalizeDmChatId(d.id) === chatId) || {
id: chatId,
name: chatId,
initials: (chatId[0] || '?').toUpperCase(),
name: String(routeChatId || chatId),
initials: (String(routeChatId || chatId)[0] || '?').toUpperCase(),
};
const screen = document.createElement('section');
+5 -3
View File
@@ -2,6 +2,7 @@ import { directMessages } from '../mock-data.js';
import {
getChatMessages,
isSessionInvalidError,
normalizeDmChatId,
setContacts,
state,
terminateCurrentSession,
@@ -126,7 +127,7 @@ export function render({ navigate }) {
</div>
`;
row.prepend(avatarWrap);
row.addEventListener('click', () => navigate(`chat-view/${encodeURIComponent(item.id)}`));
row.addEventListener('click', () => navigate(`chat-view/${encodeURIComponent(normalizeDmChatId(item.id))}`));
return row;
}
@@ -139,12 +140,13 @@ export function render({ navigate }) {
const contactRows = contacts.map((login) => {
const preview = directMessages.find((item) => item.id.toLowerCase() === login.toLowerCase());
const chat = getChatMessages(login);
const canonicalLogin = normalizeDmChatId(login);
const chat = getChatMessages(canonicalLogin);
const lastChat = chat[chat.length - 1];
const unread = chat.filter((m) => m?.from === 'in' && m?.unread).length;
const lastTimeMs = Number(lastChat?.createdAtMs || 0);
return {
id: login,
id: canonicalLogin,
name: preview?.name || login,
lastMessage: lastChat?.text || preview?.lastMessage || 'Диалог пока пуст.',
time: formatChatRowTime(lastTimeMs),