Load images in messages automatically
This commit is contained in:
parent
7269cd868b
commit
6af2d4a1ea
2 changed files with 31 additions and 12 deletions
5
app.js
5
app.js
|
|
@ -265,8 +265,7 @@ async function sendMessage() {
|
||||||
tempBubble.id = responseData.id;
|
tempBubble.id = responseData.id;
|
||||||
}
|
}
|
||||||
const meta = tempBubble.querySelector('.message-meta');
|
const meta = tempBubble.querySelector('.message-meta');
|
||||||
meta.innerHTML = `<span>${formatTime(new Date())}</span><i data-lucide="check" style="width:14px; height:14px;"></i>`;
|
meta.innerHTML = `<span>${formatTime(new Date())}</span><span style="width:14px; height:14px;" class="mif-done">`;
|
||||||
lucide.createIcons();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
activeChatState.lastMessage = text;
|
activeChatState.lastMessage = text;
|
||||||
|
|
@ -290,7 +289,7 @@ async function sendMessage() {
|
||||||
|
|
||||||
async function sendFileMessage(file) {
|
async function sendFileMessage(file) {
|
||||||
try {
|
try {
|
||||||
console.log(await waha.sendFileMessage(activeChatState.id, file));
|
const result = await waha.sendFileMessage(activeChatState.id, file);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(error.message);
|
console.error(error.message);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
38
ui.js
38
ui.js
|
|
@ -143,6 +143,11 @@ export const ui = {
|
||||||
* Append a single message (used for optimistic updates immediately upon sending)
|
* Append a single message (used for optimistic updates immediately upon sending)
|
||||||
*/
|
*/
|
||||||
appendSingleMessage(msg, activeChatName, userID, chatId) {
|
appendSingleMessage(msg, activeChatName, userID, chatId) {
|
||||||
|
elements.messagesContainer.appendChild(this.generateMessage(msg, activeChatName, userID, chatId))
|
||||||
|
},
|
||||||
|
|
||||||
|
generateMessage(msg, activeChatName, userID, chatId) {
|
||||||
|
console.log(msg)
|
||||||
const isOutgoing = msg.fromMe || msg.sender === 'me';
|
const isOutgoing = msg.fromMe || msg.sender === 'me';
|
||||||
|
|
||||||
const groupDiv = document.createElement('div');
|
const groupDiv = document.createElement('div');
|
||||||
|
|
@ -156,11 +161,13 @@ export const ui = {
|
||||||
let statusCheck = '';
|
let statusCheck = '';
|
||||||
if (isOutgoing) {
|
if (isOutgoing) {
|
||||||
if (msg.status === 'read') {
|
if (msg.status === 'read') {
|
||||||
statusCheck = '<i data-lucide="check-check" style="color: var(--online-color); width:14px; height:14px;"></i>';
|
statusCheck = '<span class="mif-done_all" style="color: var(--online-color); width:14px; height:14px;"></span>';
|
||||||
} else if (msg.status === 'delivered') {
|
} else if (msg.status === 'delivered') {
|
||||||
statusCheck = '<i data-lucide="check-check" style="width:14px; height:14px;"></i>';
|
statusCheck = '<span class="mif-done" style="width:14px; height:14px;"></span>';
|
||||||
|
} else if (msg.status === 'sending') {
|
||||||
|
statusCheck = '<span class="mif-earth" style="width:14px; height:14px;"></span>';
|
||||||
} else {
|
} else {
|
||||||
statusCheck = '<i data-lucide="check" style="width:14px; height:14px;"></i>';
|
statusCheck = '<span class="mif-done" style="width:14px; height:14px;"></span>';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -185,7 +192,9 @@ export const ui = {
|
||||||
const a = document.createElement('a');
|
const a = document.createElement('a');
|
||||||
a.innerText = `[Request media]`;
|
a.innerText = `[Request media]`;
|
||||||
|
|
||||||
a.addEventListener('click', async (e) => {
|
const clickListener = async (e) => {
|
||||||
|
a.removeEventListener('click', clickListener);
|
||||||
|
a.innerText = `[Downloading]`;
|
||||||
const mediaMsg = await waha.getSingleChatMessage(chatId, msg.id, true);
|
const mediaMsg = await waha.getSingleChatMessage(chatId, msg.id, true);
|
||||||
|
|
||||||
const url = new URL(mediaMsg.media.url);
|
const url = new URL(mediaMsg.media.url);
|
||||||
|
|
@ -205,11 +214,16 @@ export const ui = {
|
||||||
} else {
|
} else {
|
||||||
e.target.textContent = filename || `Download ${mediaMsg.media.filename}`;
|
e.target.textContent = filename || `Download ${mediaMsg.media.filename}`;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
})
|
|
||||||
|
|
||||||
contentEl.appendChild(a);
|
contentEl.appendChild(a);
|
||||||
|
a.addEventListener('click', clickListener);
|
||||||
|
|
||||||
|
if (msg._data.mimetype.startsWith('image/')) {
|
||||||
|
a.click();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
const meta = document.createElement('div');
|
const meta = document.createElement('div');
|
||||||
meta.className = 'message-meta';
|
meta.className = 'message-meta';
|
||||||
|
|
@ -242,10 +256,16 @@ export const ui = {
|
||||||
}
|
}
|
||||||
|
|
||||||
groupDiv.appendChild(bubble);
|
groupDiv.appendChild(bubble);
|
||||||
|
return groupDiv;
|
||||||
elements.messagesContainer.appendChild(groupDiv);
|
|
||||||
},
|
},
|
||||||
|
|
||||||
|
updateMessage(originalMsgId, generatedMsg) {
|
||||||
|
const originalMsg = document.querySelector(`#${originalMsgId}`);
|
||||||
|
if (originalMsg) {
|
||||||
|
originalMsg.replaceWith(generatedMsg)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
toggleChatBottomBar() {
|
toggleChatBottomBar() {
|
||||||
elements.chatBottomBar.classList.toggle("collapsed");
|
elements.chatBottomBar.classList.toggle("collapsed");
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue