From 295bc94fa3486ea579e6b61e62356422b6645bcd Mon Sep 17 00:00:00 2001 From: Shivam Mishra Date: Thu, 14 May 2026 20:29:43 +0530 Subject: [PATCH] feat: use single inbox id --- .../dashboard/store/modules/inboxes.js | 12 ++++++++++++ .../src/components/ChatwootProvider.jsx | 13 ++++--------- app/javascript/ui/MessageList.vue | 19 +++++++++++++++++++ 3 files changed, 35 insertions(+), 9 deletions(-) diff --git a/app/javascript/dashboard/store/modules/inboxes.js b/app/javascript/dashboard/store/modules/inboxes.js index 49926f378..046d01e7b 100644 --- a/app/javascript/dashboard/store/modules/inboxes.js +++ b/app/javascript/dashboard/store/modules/inboxes.js @@ -210,6 +210,18 @@ export const actions = { commit(types.default.SET_INBOXES_UI_FLAG, { isFetching: false }); } }, + getById: async ({ commit, getters: $getters }, inboxId) => { + if (!inboxId || $getters.getInbox(inboxId).id) return; + + commit(types.default.SET_INBOXES_UI_FLAG, { isFetchingItem: true }); + try { + const response = await InboxesAPI.show(inboxId); + commit(types.default.SET_INBOXES_ITEM, response.data); + commit(types.default.SET_INBOXES_UI_FLAG, { isFetchingItem: false }); + } catch (error) { + commit(types.default.SET_INBOXES_UI_FLAG, { isFetchingItem: false }); + } + }, createChannel: async ({ commit }, params) => { try { commit(types.default.SET_INBOXES_UI_FLAG, { isCreating: true }); diff --git a/app/javascript/react-components/src/components/ChatwootProvider.jsx b/app/javascript/react-components/src/components/ChatwootProvider.jsx index 1379e8c70..5a4b58f1f 100644 --- a/app/javascript/react-components/src/components/ChatwootProvider.jsx +++ b/app/javascript/react-components/src/components/ChatwootProvider.jsx @@ -15,6 +15,7 @@ export const ChatwootProvider = ({ websocketURL, pubsubToken, conversationId, + inboxId, disableUpload, disableEditor, disableSignature, @@ -40,6 +41,7 @@ export const ChatwootProvider = ({ userToken, accountId: Number(accountId), conversationId: Number(conversationId), + inboxId: inboxId ? Number(inboxId) : undefined, disableEditor: disableEditor || false, disableUpload: disableUpload || false, disableSignature: disableSignature || false, @@ -62,6 +64,7 @@ export const ChatwootProvider = ({ window.__WEBSOCKET_URL__ = config.websocketURL; window.__PUBSUB_TOKEN__ = config.pubsubToken; window.__WOOT_CONVERSATION_ID__ = config.conversationId; + window.__WOOT_INBOX_ID__ = config.inboxId; window.__EDITOR_DISABLE_UPLOAD__ = config.disableUpload; window.__DISABLE_EDITOR__ = config.disableEditor; window.__WOOT_DISABLE_SIGNATURE__ = config.disableSignature; @@ -76,15 +79,7 @@ export const ChatwootProvider = ({ window.WootConstants = constants; window.axios = createAxios(axios); - // Initialize user in store and ActionCable - store.dispatch('setUser').then(async () => { - // Fetch inboxes once per session. Guarded against the shared Vuex store - // so remounting the provider (e.g. when the consumer re-keys per - // conversation) doesn't trigger redundant /inboxes requests. - const hasInboxes = store.getters['inboxes/getInboxes'].length > 0; - if (!hasInboxes) { - await store.dispatch('inboxes/get'); - } + store.dispatch('setUser').then(() => { vueActionCable.init(store, config.pubsubToken); setInitializationComplete(true); }); diff --git a/app/javascript/ui/MessageList.vue b/app/javascript/ui/MessageList.vue index 6a0d9ce84..9ce26fdcf 100644 --- a/app/javascript/ui/MessageList.vue +++ b/app/javascript/ui/MessageList.vue @@ -23,6 +23,11 @@ const conversationId = computed(() => { return window.__WOOT_CONVERSATION_ID__; }); +const configuredInboxId = computed(() => { + // eslint-disable-next-line no-underscore-dangle + return window.__WOOT_INBOX_ID__; +}); + const { t } = useI18n(); const messageListRef = useTemplateRef('messageListRef'); @@ -73,11 +78,25 @@ const fetchMore = async () => { } }; +const fetchConversationInbox = async () => { + const currentConversation = conversation.value; + const inboxId = + configuredInboxId.value || + currentConversation?.inbox_id || + currentConversation?.inbox?.id; + + if (!inboxId) return; + + await store.dispatch('inboxes/getById', inboxId); +}; + onMounted(async () => { await Promise.all([ store.dispatch('getConversation', conversationId.value), store.dispatch('fetchAllAttachments', conversationId.value), ]); + + await fetchConversationInbox(); }); watch(conversation, async (newConversation, oldConversation) => {