SHA256
fix ui dm chatid lowercase normalization
This commit is contained in:
+22
-13
@@ -92,6 +92,10 @@ const DEFAULT_ARWEAVE_SERVER = 'https://arweave.net';
|
||||
const DEFAULT_CALL_PREFLIGHT_TIMEOUT_MS = 6000;
|
||||
const DEFAULT_OPENAI_BASE_URL = 'https://api.openai.com/v1';
|
||||
|
||||
export function normalizeDmChatId(value) {
|
||||
return String(value || '').trim().toLowerCase();
|
||||
}
|
||||
|
||||
function normalizeToolsSettings(rawTools) {
|
||||
const source = rawTools && typeof rawTools === 'object' ? rawTools : {};
|
||||
const stt = source.speechToText && typeof source.speechToText === 'object' ? source.speechToText : {};
|
||||
@@ -376,11 +380,12 @@ function sortChatMessagesInPlace(chatId) {
|
||||
}
|
||||
|
||||
function persistMessageRecord(chatId, row) {
|
||||
if (!chatId || !row?.messageKey) return;
|
||||
const normalizedChatId = normalizeDmChatId(chatId);
|
||||
if (!normalizedChatId || !row?.messageKey) return;
|
||||
const resolvedTs = resolveChatMessageTimeMs(row);
|
||||
void putStoredMessage({
|
||||
messageKey: row.messageKey,
|
||||
chatId,
|
||||
chatId: normalizedChatId,
|
||||
from: row.from || 'in',
|
||||
text: String(row.text || ''),
|
||||
baseKey: String(row.baseKey || ''),
|
||||
@@ -408,7 +413,7 @@ export async function hydrateMessagesFromStore() {
|
||||
rows
|
||||
.sort((a, b) => Number(a?.ts || 0) - Number(b?.ts || 0))
|
||||
.forEach((row) => {
|
||||
const chatId = String(row?.chatId || '').trim();
|
||||
const chatId = normalizeDmChatId(row?.chatId);
|
||||
const messageKey = String(row?.messageKey || '').trim();
|
||||
if (!chatId || !messageKey) return;
|
||||
if (state.knownMessageKeys[messageKey]) return;
|
||||
@@ -437,10 +442,12 @@ export async function hydrateMessagesFromStore() {
|
||||
}
|
||||
|
||||
export function getChatMessages(chatId) {
|
||||
if (!state.chats[chatId]) {
|
||||
state.chats[chatId] = [];
|
||||
const normalizedChatId = normalizeDmChatId(chatId);
|
||||
if (!normalizedChatId) return [];
|
||||
if (!state.chats[normalizedChatId]) {
|
||||
state.chats[normalizedChatId] = [];
|
||||
}
|
||||
return state.chats[chatId];
|
||||
return state.chats[normalizedChatId];
|
||||
}
|
||||
|
||||
export function addChatMessage(chatId, text) {
|
||||
@@ -583,9 +590,10 @@ export function addSignedMessageToChat({
|
||||
revisionTimeMs = 0,
|
||||
deleted = false,
|
||||
} = {}) {
|
||||
const normalizedChatId = normalizeDmChatId(chatId);
|
||||
const id = String(messageKey || '').trim();
|
||||
if (!chatId || !id) return false;
|
||||
const list = getChatMessages(chatId);
|
||||
if (!normalizedChatId || !id) return false;
|
||||
const list = getChatMessages(normalizedChatId);
|
||||
const existingIndex = list.findIndex((row) => String(row?.messageKey || '').trim() === id);
|
||||
const existing = existingIndex >= 0 ? list[existingIndex] : null;
|
||||
const nextRevision = Number(revisionTimeMs || 0);
|
||||
@@ -599,7 +607,7 @@ export function addSignedMessageToChat({
|
||||
if (existingIndex >= 0) {
|
||||
list.splice(existingIndex, 1);
|
||||
removeStoredMessageRecord(id);
|
||||
sortChatMessagesInPlace(chatId);
|
||||
sortChatMessagesInPlace(normalizedChatId);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
@@ -623,17 +631,18 @@ export function addSignedMessageToChat({
|
||||
if (existingIndex < 0) {
|
||||
list.push(row);
|
||||
}
|
||||
sortChatMessagesInPlace(chatId);
|
||||
persistMessageRecord(chatId, row);
|
||||
sortChatMessagesInPlace(normalizedChatId);
|
||||
persistMessageRecord(normalizedChatId, row);
|
||||
return true;
|
||||
}
|
||||
|
||||
export function markChatRead(chatId) {
|
||||
const list = getChatMessages(chatId);
|
||||
const normalizedChatId = normalizeDmChatId(chatId);
|
||||
const list = getChatMessages(normalizedChatId);
|
||||
list.forEach((row) => {
|
||||
if (row?.from === 'in') {
|
||||
row.unread = false;
|
||||
persistMessageRecord(chatId, row);
|
||||
persistMessageRecord(normalizedChatId, row);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user