mirror of
				https://github.com/lingble/chatwoot.git
				synced 2025-10-31 11:08:04 +00:00 
			
		
		
		
	 b474929f5e
			
		
	
	b474929f5e
	
	
	
		
			
			# Replace the deprecated `eventBus` with mitt.js ## Description Since eventBus and it's respective methods are deprecated and removed from all future releases of vue, this was blocking us from migrating. This PR replaces eventBus with [mitt](https://github.com/developit/mitt). I have created a wrapper mitt.js to simulate the same old event names so it's backwards compatible, without making a lot of changes. Fixes # (issue) ## Type of change Please delete options that are not relevant. - [x] Bug fix (non-breaking change which fixes an issue) - [ ] New feature (non-breaking change which adds functionality) - [ ] Breaking change (fix or feature that would cause existing functionality not to work as expected) - [ ] This change requires a documentation update ## How Has This Been Tested? 1. Made sure all the places we're listening to bus events are working as expected. 2. Respective specsf or the events from mitt. ## Checklist: - [x] My code follows the style guidelines of this project - [x] I have performed a self-review of my code - [x] I have commented on my code, particularly in hard-to-understand areas - [x] I have made corresponding changes to the documentation - [x] My changes generate no new warnings - [x] I have added tests that prove my fix is effective or that my feature works - [x] New and existing unit tests pass locally with my changes - [x] Any dependent changes have been merged and published in downstream modules
		
			
				
	
	
		
			61 lines
		
	
	
		
			1.9 KiB
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
			
		
		
	
	
			61 lines
		
	
	
		
			1.9 KiB
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
| import AnalyticsHelper from './AnalyticsHelper';
 | |
| import DashboardAudioNotificationHelper from './AudioAlerts/DashboardAudioNotificationHelper';
 | |
| import { emitter } from 'shared/helpers/mitt';
 | |
| 
 | |
| export const CHATWOOT_SET_USER = 'CHATWOOT_SET_USER';
 | |
| export const CHATWOOT_RESET = 'CHATWOOT_RESET';
 | |
| 
 | |
| export const ANALYTICS_IDENTITY = 'ANALYTICS_IDENTITY';
 | |
| export const ANALYTICS_RESET = 'ANALYTICS_RESET';
 | |
| 
 | |
| export const initializeAnalyticsEvents = () => {
 | |
|   emitter.on(ANALYTICS_IDENTITY, ({ user }) => {
 | |
|     AnalyticsHelper.identify(user);
 | |
|   });
 | |
| };
 | |
| 
 | |
| const initializeAudioAlerts = user => {
 | |
|   const { ui_settings: uiSettings } = user || {};
 | |
|   const {
 | |
|     always_play_audio_alert: alwaysPlayAudioAlert,
 | |
|     enable_audio_alerts: audioAlertType,
 | |
|     alert_if_unread_assigned_conversation_exist: alertIfUnreadConversationExist,
 | |
|     notification_tone: audioAlertTone,
 | |
|     // UI Settings can be undefined initally as we don't send the
 | |
|     // entire payload for the user during the signup process.
 | |
|   } = uiSettings || {};
 | |
| 
 | |
|   DashboardAudioNotificationHelper.setInstanceValues({
 | |
|     currentUserId: user.id,
 | |
|     audioAlertType: audioAlertType || 'none',
 | |
|     audioAlertTone: audioAlertTone || 'ding',
 | |
|     alwaysPlayAudioAlert: alwaysPlayAudioAlert || false,
 | |
|     alertIfUnreadConversationExist: alertIfUnreadConversationExist || false,
 | |
|   });
 | |
| };
 | |
| 
 | |
| export const initializeChatwootEvents = () => {
 | |
|   emitter.on(CHATWOOT_RESET, () => {
 | |
|     if (window.$chatwoot) {
 | |
|       window.$chatwoot.reset();
 | |
|     }
 | |
|   });
 | |
|   emitter.on(CHATWOOT_SET_USER, ({ user }) => {
 | |
|     if (window.$chatwoot) {
 | |
|       window.$chatwoot.setUser(user.email, {
 | |
|         avatar_url: user.avatar_url,
 | |
|         email: user.email,
 | |
|         identifier_hash: user.hmac_identifier,
 | |
|         name: user.name,
 | |
|       });
 | |
|       window.$chatwoot.setCustomAttributes({
 | |
|         signedUpAt: user.created_at,
 | |
|         cloudCustomer: 'true',
 | |
|         account_id: user.account_id,
 | |
|       });
 | |
|     }
 | |
| 
 | |
|     initializeAudioAlerts(user);
 | |
|   });
 | |
| };
 |