mirror of
				https://github.com/lingble/chatwoot.git
				synced 2025-11-03 20:48:07 +00:00 
			
		
		
		
	* fixes: Triggering disabled ongoing campaigns. * Fix the specs Co-authored-by: Muhsin Keloth <muhsinkeramam@gmail.com>
		
			
				
	
	
		
			25 lines
		
	
	
		
			644 B
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
			
		
		
	
	
			25 lines
		
	
	
		
			644 B
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
import store from '../store';
 | 
						|
class CampaignTimer {
 | 
						|
  constructor() {
 | 
						|
    this.campaignTimers = [];
 | 
						|
  }
 | 
						|
 | 
						|
  initTimers = ({ campaigns }, websiteToken) => {
 | 
						|
    this.clearTimers();
 | 
						|
    campaigns.forEach(campaign => {
 | 
						|
      const { timeOnPage, id: campaignId } = campaign;
 | 
						|
      this.campaignTimers[campaignId] = setTimeout(() => {
 | 
						|
        store.dispatch('campaign/startCampaign', { campaignId, websiteToken });
 | 
						|
      }, timeOnPage * 1000);
 | 
						|
    });
 | 
						|
  };
 | 
						|
 | 
						|
  clearTimers = () => {
 | 
						|
    this.campaignTimers.forEach(timerId => {
 | 
						|
      clearTimeout(timerId);
 | 
						|
      this.campaignTimers[timerId] = null;
 | 
						|
    });
 | 
						|
  };
 | 
						|
}
 | 
						|
export default new CampaignTimer();
 |