Skip to content

GOWA - WhatsApp REST API with support for UI, Multi Account, Webhooks, and MCP, and Chatwoot. Built with Golang for efficient memory use.

feat: enhance chat modal navigation and global component exposure

Aldino Kemalfa5b288185f9
diff --git a/.gitignore b/.gitignore
index b7377173..688eac45 100644
Binary files a/.gitignore and b/.gitignore differ
diff --git a/src/views/components/ChatList.js b/src/views/components/ChatList.js
index 0fef6df1..b9c4629e 100644
--- a/src/views/components/ChatList.js
+++ b/src/views/components/ChatList.js
@@ -29,6 +29,9 @@ export default {
$('#modalChatList').modal('show');
this.loadChats();
},
+ closeModal() {
+ $('#modalChatList').modal('hide');
+ },
async loadChats() {
this.loading = true;
try {
@@ -74,16 +77,17 @@ export default {
this.selectedChatJid = jid;
// Store the JID for the chat messages component
localStorage.setItem('selectedChatJid', jid);
-
- // Close the current modal and trigger ChatMessages openModal method
- $('#modalChatList').modal({
- onHidden: function() {
- setTimeout(() => {
- // Trigger a custom event to open ChatMessages modal properly
- window.dispatchEvent(new CustomEvent('openChatMessages'));
- }, 100);
+
+ // Close the current modal
+ $('#modalChatList').modal('hide');
+
+ // Directly open ChatMessages modal after ChatList modal closes
+ setTimeout(() => {
+ // Find the ChatMessages component and call its openModal method
+ if (window.ChatMessagesComponent && window.ChatMessagesComponent.openModal) {
+ window.ChatMessagesComponent.openModal();
}
- }).modal('hide');
+ }, 200);
},
formatTimestamp(timestamp) {
if (!timestamp) return 'N/A';
@@ -96,6 +100,16 @@ export default {
return 'Other';
}
},
+ mounted() {
+ // Expose the component globally for other components to access
+ window.ChatListComponent = this;
+ },
+ beforeUnmount() {
+ // Clean up global reference
+ if (window.ChatListComponent === this) {
+ delete window.ChatListComponent;
+ }
+ },
template: `
<div class="purple card" @click="openModal()" style="cursor: pointer">
<div class="content">
@@ -106,7 +120,7 @@ export default {
</div>
</div>
</div>
-
+
<!-- Modal ChatList -->
<div class="ui large modal" id="modalChatList">
<i class="close icon"></i>
diff --git a/src/views/components/ChatMessages.js b/src/views/components/ChatMessages.js
index d4b6b2c3..7f797c11 100644
--- a/src/views/components/ChatMessages.js
+++ b/src/views/components/ChatMessages.js
@@ -379,7 +379,7 @@ export default {
}
},
async downloadAllMediaInMessages() {
- const mediaMessages = this.messages.filter(message =>
+ const mediaMessages = this.messages.filter(message =>
message.media_type && message.url && message.id &&
!this.isMediaDownloaded(message.id) && !this.isMediaDownloading(message.id)
);
@@ -390,7 +390,7 @@ export default {
// Download in batches to respect concurrency limit
const downloadQueue = [...mediaMessages];
-
+
const processQueue = async () => {
while (downloadQueue.length > 0 && this.currentDownloads < this.maxConcurrentDownloads) {
const message = downloadQueue.shift();
@@ -400,7 +400,7 @@ export default {
await new Promise(resolve => setTimeout(resolve, 100));
}
}
-
+
// If there are still items in queue and we can download more, continue
if (downloadQueue.length > 0 && this.currentDownloads < this.maxConcurrentDownloads) {
setTimeout(processQueue, 500); // Wait a bit before checking again
@@ -410,30 +410,47 @@ export default {
// Start processing
processQueue();
},
+ backToChatList() {
+ // Close current modal
+ $('#modalChatMessages').modal('hide');
+
+ // Open Chat List modal after a short delay
+ setTimeout(() => {
+ if (window.ChatListComponent && window.ChatListComponent.openModal) {
+ window.ChatListComponent.openModal();
+ } else {
+ // Fallback: try to find and click the Chat List card
+ const chatListCards = document.querySelectorAll('.card .header');
+ for (let card of chatListCards) {
+ if (card.textContent.includes('Chat List')) {
+ card.click();
+ break;
+ }
+ }
+ }
+ }, 200);
+ },
},
mounted() {
- // Store the event handler so we can remove it later
- this.handleOpenChatMessages = () => {
- this.openModal();
- };
-
+ // Expose the openModal method globally for ChatList component to call
+ window.ChatMessagesComponent = this;
+
// Handle retry media download events
this.handleRetryMediaDownload = (event) => {
const messageId = event.detail;
this.retryMediaDownload(messageId);
};
-
- // Listen for custom event from ChatList to open modal properly
- window.addEventListener('openChatMessages', this.handleOpenChatMessages);
-
+
// Listen for retry media download events
document.addEventListener('retryMediaDownload', this.handleRetryMediaDownload);
},
beforeUnmount() {
- // Clean up event listeners
- if (this.handleOpenChatMessages) {
- window.removeEventListener('openChatMessages', this.handleOpenChatMessages);
+ // Clean up global reference
+ if (window.ChatMessagesComponent === this) {
+ delete window.ChatMessagesComponent;
}
+
+ // Clean up event listeners
if (this.handleRetryMediaDownload) {
document.removeEventListener('retryMediaDownload', this.handleRetryMediaDownload);
}
@@ -589,6 +606,10 @@ export default {
</div>
</div>
<div class="actions">
+ <button class="ui button" @click="backToChatList">
+ <i class="arrow left icon"></i>
+ Back to Chat List
+ </button>
<div class="ui approve button">Close</div>
</div>
</div>