Remove usage of userInfo in app.js; make storage aware of connection status to avoid connecting to the server in offline mode; fix updateChaInList querying for non-existent elements and using them blindly; make websocket also check connection status on reload.
This commit is contained in:
parent
3a1ed0903c
commit
a021ca821f
4 changed files with 66 additions and 39 deletions
19
js/ui.js
19
js/ui.js
|
|
@ -110,7 +110,7 @@ export const ui = {
|
|||
<span class="chat-item-time">${timeStr}</span>
|
||||
</div>
|
||||
<div class="chat-item-preview">
|
||||
<span class="chat-item-msg">${chat.lastMessage || 'No messages yet'}</span>
|
||||
<span class="chat-item-msg" data-chatid="${chat.id}">${chat.lastMessage || 'No messages yet'}</span>
|
||||
${hasUnread ? `<span class="unread-badge">${chat.unreadCount}</span>` : ''}
|
||||
</div>
|
||||
</div>
|
||||
|
|
@ -122,8 +122,10 @@ export const ui = {
|
|||
},
|
||||
|
||||
async updateChatInChatList(msg) {
|
||||
const li = document.getElementById(msg.from);
|
||||
li.querySelector(".chat-item-msg").innerText = msg.body;
|
||||
const span = document.querySelector(`.chat-item-msg[data-chatid="${msg.from}"]`);
|
||||
if (span) {
|
||||
span.innerText = msg.body;
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
|
|
@ -170,7 +172,6 @@ export const ui = {
|
|||
},
|
||||
|
||||
generateMessage(msg, activeChatName, userID, chatId, isLocal = false) {
|
||||
console.log(msg);
|
||||
const isOutgoing = msg.fromMe || msg.sender === 'me';
|
||||
|
||||
function getPrevMessageElem() {
|
||||
|
|
@ -239,6 +240,11 @@ export const ui = {
|
|||
a.removeEventListener('click', clickListener);
|
||||
a.innerText = `[Downloading]`;
|
||||
const mediaMsg = msg.media ? msg : await getMessage(chatId, msg.id, true);
|
||||
if (!mediaMsg.media.url) {
|
||||
a.addEventListener('click', clickListener);
|
||||
a.innerText = `[Error, click to try again]`
|
||||
return;
|
||||
}
|
||||
const url = new URL(mediaMsg.media.url);
|
||||
const reqID = url.pathname.split('/').filter(Boolean).pop();
|
||||
|
||||
|
|
@ -319,5 +325,10 @@ export const ui = {
|
|||
|
||||
toggleChatBottomBar() {
|
||||
elements.chatBottomBar.classList.toggle("collapsed");
|
||||
},
|
||||
|
||||
removeChatMessage(msgId) {
|
||||
const message = document.getElementById(msgId);
|
||||
if (message) message.remove();
|
||||
}
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue