feat: use single inbox id

This commit is contained in:
Shivam Mishra
2026-05-14 20:30:02 +05:30
parent 83e96956fc
commit 295bc94fa3
3 changed files with 35 additions and 9 deletions
@@ -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 });
@@ -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);
});
+19
View File
@@ -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) => {