Fix bug in updateChatInChatList that would make outgoing messages show up in the user self chat; fix app awaiting for getAppUser on wrong scope.

This commit is contained in:
天クマ 2026-07-16 20:03:32 -03:00
commit b3b74b04fc
2 changed files with 9 additions and 9 deletions

View file

@ -13,7 +13,7 @@ document.addEventListener('DOMContentLoaded', async () => {
await updateOnlineStatus(); await updateOnlineStatus();
setupEventListeners(); setupEventListeners();
try { try {
elements.loggedUserName.textContent = await getAppUser().pushName; elements.loggedUserName.textContent = (await getAppUser()).pushName;
loadChats(); loadChats();
checkWahaStatus(); checkWahaStatus();
initWebSocket(); initWebSocket();
@ -122,7 +122,7 @@ function normalizeChatId(raw) {
return raw; return raw;
} }
function handleIncomingMessage(msg) { async function handleIncomingMessage(msg) {
if (!msg) return; if (!msg) return;
// console.log('[WS] handleIncomingMessage payload:', msg); // console.log('[WS] handleIncomingMessage payload:', msg);
@ -145,7 +145,7 @@ function handleIncomingMessage(msg) {
const msgId = normalizeChatId(msg.id) || msg.id; const msgId = normalizeChatId(msg.id) || msg.id;
const exists = document.getElementById(msgId); const exists = document.getElementById(msgId);
if (!exists) { if (!exists) {
ui.appendSingleMessage({ ...msg, chatId: msgChatId }, activeChatState.name, getAppUser().id); ui.appendSingleMessage({ ...msg, chatId: msgChatId }, activeChatState.name, (await getAppUser()).id);
ui.scrollToBottom(); ui.scrollToBottom();
} }
} }
@ -193,7 +193,7 @@ async function selectChat(chat) {
try { try {
const rawMessages = await getChatMessages(chat.id); const rawMessages = await getChatMessages(chat.id);
const processedMessages = compensateMessageOrdering(rawMessages); const processedMessages = compensateMessageOrdering(rawMessages);
ui.renderMessages(processedMessages, chat.name, getAppUser().id, chat.id); ui.renderMessages(processedMessages, chat.name, (await getAppUser()).id, chat.id);
} catch (error) { } catch (error) {
console.error('Failed to load messages:', error); console.error('Failed to load messages:', error);
elements.messagesContainer.innerHTML = '<div class="loading-chats">Error loading messages</div>'; elements.messagesContainer.innerHTML = '<div class="loading-chats">Error loading messages</div>';
@ -215,7 +215,7 @@ async function sendMessage() {
status: 'sending' status: 'sending'
}; };
ui.appendSingleMessage(tempMsg, activeChatState.name, getAppUser().id); ui.appendSingleMessage(tempMsg, activeChatState.name, (await getAppUser()).id);
ui.scrollToBottom(); ui.scrollToBottom();
try { try {
@ -284,12 +284,12 @@ async function sendFileMessage(file) {
} }
}; };
ui.appendSingleMessage(tempMsg, activeChatState.name, getAppUser().id, activeChatState.id, true); ui.appendSingleMessage(tempMsg, activeChatState.name, (await getAppUser()).id, activeChatState.id, true);
ui.scrollToBottom(); ui.scrollToBottom();
const result = await waha.sendFileMessage(activeChatState.id, file); const result = await waha.sendFileMessage(activeChatState.id, file);
ui.removeChatMessage(tempId); ui.removeChatMessage(tempId);
ui.appendSingleMessage(result.id, activeChatState.name, getAppUser().id, activeChatState.id); ui.appendSingleMessage(result.id, activeChatState.name, (await getAppUser()).id, activeChatState.id);
} catch (error) { } catch (error) {
console.error(error.message); console.error(error.message);
} }

View file

@ -122,7 +122,7 @@ export const ui = {
}, },
async updateChatInChatList(msg) { async updateChatInChatList(msg) {
const span = document.querySelector(`.chat-item-msg[data-chatid="${msg.from}"]`); const span = document.querySelector(`.chat-item-msg[data-chatid="${msg.fromMe ? msg.to : msg.from}"]`);
if (span) { if (span) {
span.innerText = msg.body; span.innerText = msg.body;
} }
@ -240,7 +240,7 @@ export const ui = {
a.removeEventListener('click', clickListener); a.removeEventListener('click', clickListener);
a.innerText = `[Downloading]`; a.innerText = `[Downloading]`;
const mediaMsg = msg.media ? msg : await getMessage(chatId, msg.id, true); const mediaMsg = msg.media ? msg : await getMessage(chatId, msg.id, true);
if (!mediaMsg.media.url) { if (!mediaMsg || !mediaMsg?.media.url) {
a.addEventListener('click', clickListener); a.addEventListener('click', clickListener);
a.innerText = `[Error, click to try again]` a.innerText = `[Error, click to try again]`
return; return;