chore: code cleanup

This commit is contained in:
Sojan
2025-05-03 02:09:34 -07:00
parent 3692cde1a9
commit 4c48a565f6
16 changed files with 1143 additions and 581 deletions
@@ -11,10 +11,29 @@ const getters = {
};
const actions = {
setActiveCall({ commit }, callData) {
// This action will handle both message updates and direct call status changes
handleCallStatusChanged({ state, dispatch }, { callSid, status }) {
// If this is the active call and it has ended or was missed, close the widget
if (callSid === state.activeCall?.callSid &&
(status === 'ended' || status === 'missed' || status === 'completed')) {
dispatch('clearActiveCall');
}
},
setActiveCall({ commit, dispatch, state }, callData) {
if (!callData || !callData.callSid) {
throw new Error('Invalid call data provided');
}
// If the call has a status, check if it's a terminal status
if (callData.status && ['ended', 'missed', 'completed'].includes(callData.status)) {
// If the call is already in a terminal state, clear any active call
if (callData.callSid === state.activeCall?.callSid) {
return dispatch('clearActiveCall');
}
// Otherwise just ignore it - don't set an already ended call as active
return;
}
commit('SET_ACTIVE_CALL', callData);
@@ -25,12 +44,18 @@ const actions = {
},
clearActiveCall({ commit }) {
// Store the messageId before clearing the call
const messageId = state.activeCall?.messageId;
commit('CLEAR_ACTIVE_CALL');
// Update app state if in browser environment
if (typeof window !== 'undefined' && window.app?.$data) {
window.app.$data.showCallWidget = false;
}
// We no longer need to update call widget status as we'll use reactive Vue props
// and updates will come through Chatwoot's standard message update events
},
setIncomingCall({ commit, state }, callData) {
@@ -48,16 +73,30 @@ const actions = {
return;
}
commit('SET_INCOMING_CALL', callData);
const enrichedCallData = {
...callData,
receivedAt: Date.now(),
};
commit('SET_INCOMING_CALL', enrichedCallData);
// Update app state if in browser environment
if (typeof window !== 'undefined' && window.app && window.app.$data) {
window.app.$data.showCallWidget = true;
}
// We no longer need to update call widget status as we'll use reactive Vue props
// and updates will come through Chatwoot's standard message update events
},
clearIncomingCall({ commit }) {
// Store the messageId before clearing the call
const messageId = state.incomingCall?.messageId;
commit('CLEAR_INCOMING_CALL');
// We no longer need to update call widget status as we'll use reactive Vue props
// and updates will come through Chatwoot's standard message update events
},
acceptIncomingCall({ commit, state }) {
@@ -70,8 +109,12 @@ const actions = {
commit('SET_ACTIVE_CALL', {
...incomingCall,
isJoined: true,
startedAt: Date.now(),
});
commit('CLEAR_INCOMING_CALL');
// We no longer need to update call widget status as we'll use reactive Vue props
// and updates will come through Chatwoot's standard message update events
},
};
@@ -88,6 +131,9 @@ const mutations = {
CLEAR_INCOMING_CALL($state) {
$state.incomingCall = null;
},
// We no longer need to update call widget status as we'll use reactive Vue props
// We no longer need subscription mutations
};
export default {