mirror of
				https://github.com/pierre42100/ComunicWeb
				synced 2025-11-04 04:04:20 +00:00 
			
		
		
		
	Avoid call service when no conversation is opened
This commit is contained in:
		@@ -17,6 +17,11 @@ ComunicWeb.components.conversations.service = {
 | 
				
			|||||||
	 * @var {Object} __serviceCache The service cache
 | 
						 * @var {Object} __serviceCache The service cache
 | 
				
			||||||
	 */
 | 
						 */
 | 
				
			||||||
	__serviceCache: false,
 | 
						__serviceCache: false,
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/**
 | 
				
			||||||
 | 
						 * @var {Boolean} __serviceLock Specify wether the service is already in use or not
 | 
				
			||||||
 | 
						 */
 | 
				
			||||||
 | 
						__serviceLock: false,
 | 
				
			||||||
	
 | 
						
 | 
				
			||||||
	/**
 | 
						/**
 | 
				
			||||||
	 * Initializate conversation service
 | 
						 * Initializate conversation service
 | 
				
			||||||
@@ -31,7 +36,10 @@ ComunicWeb.components.conversations.service = {
 | 
				
			|||||||
		//Check if an interval already exists or not
 | 
							//Check if an interval already exists or not
 | 
				
			||||||
		if(this.__intervalID)
 | 
							if(this.__intervalID)
 | 
				
			||||||
			clearInterval(this.__intervalID); //Remove old interval
 | 
								clearInterval(this.__intervalID); //Remove old interval
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							//Force the service to unlock
 | 
				
			||||||
 | 
							this.__serviceLock = false;
 | 
				
			||||||
 | 
							
 | 
				
			||||||
		//Initializate interval
 | 
							//Initializate interval
 | 
				
			||||||
		this.__intervalID = setInterval(function(){
 | 
							this.__intervalID = setInterval(function(){
 | 
				
			||||||
			ComunicWeb.components.conversations.service.call();
 | 
								ComunicWeb.components.conversations.service.call();
 | 
				
			||||||
@@ -51,11 +59,30 @@ ComunicWeb.components.conversations.service = {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
		//Check if the conversation element still exists or not
 | 
							//Check if the conversation element still exists or not
 | 
				
			||||||
		if(!byId("conversationsElem")){
 | 
							if(!byId("conversationsElem")){
 | 
				
			||||||
			ComunicWeb.debug.logMessage("Conversation Service : Couldn't locate conversation element, unregistering service !");
 | 
								ComunicWeb.debug.logMessage("Conversation Service : Couldn't locate conversations element, unregistering service !");
 | 
				
			||||||
			clearInterval(this.__intervalID);
 | 
								clearInterval(this.__intervalID);
 | 
				
			||||||
			return false;
 | 
								return false;
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							//Check at least one conversation is opened
 | 
				
			||||||
 | 
							if(!this.__serviceCache){
 | 
				
			||||||
 | 
								ComunicWeb.debug.logMessage("Conversation Service : task skipped : the service cache is empty (equals to false).");
 | 
				
			||||||
 | 
								return false;
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							if(JSON.stringify(this.__serviceCache) == "{}"){
 | 
				
			||||||
 | 
								ComunicWeb.debug.logMessage("Conversation Service : task skipped : the service cache is empty. (equals to {})");
 | 
				
			||||||
 | 
								return false;
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							//Check if the service is locked or not
 | 
				
			||||||
 | 
							if(this.__serviceLock){
 | 
				
			||||||
 | 
								ComunicWeb.debug.logMessage("Conversation Service : task skipped : the service is locked.");
 | 
				
			||||||
 | 
								return false;
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							//Lock service
 | 
				
			||||||
 | 
							this.__serviceLock = true;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		//Perform service task
 | 
							//Perform service task
 | 
				
			||||||
		this.performTask();
 | 
							this.performTask();
 | 
				
			||||||
	},
 | 
						},
 | 
				
			||||||
@@ -66,6 +93,7 @@ ComunicWeb.components.conversations.service = {
 | 
				
			|||||||
	 * @return {Boolean} True for a success
 | 
						 * @return {Boolean} True for a success
 | 
				
			||||||
	 */
 | 
						 */
 | 
				
			||||||
	performTask: function(){
 | 
						performTask: function(){
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		console.log(this.__serviceCache);
 | 
							console.log(this.__serviceCache);
 | 
				
			||||||
		//Prepare API request
 | 
							//Prepare API request
 | 
				
			||||||
		var newConversations = [];
 | 
							var newConversations = [];
 | 
				
			||||||
@@ -96,6 +124,21 @@ ComunicWeb.components.conversations.service = {
 | 
				
			|||||||
		return true;
 | 
							return true;
 | 
				
			||||||
	},
 | 
						},
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/**
 | 
				
			||||||
 | 
						 * Service callback function
 | 
				
			||||||
 | 
						 * 
 | 
				
			||||||
 | 
						 * @param {Object}
 | 
				
			||||||
 | 
						 * @return {Boolean} True for a success
 | 
				
			||||||
 | 
						 */
 | 
				
			||||||
 | 
						callback: function(){
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							//Unlock service
 | 
				
			||||||
 | 
							this.__serviceLock = false;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							//Success
 | 
				
			||||||
 | 
							return true;
 | 
				
			||||||
 | 
						},
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/**
 | 
						/**
 | 
				
			||||||
	 * Register a new conversation
 | 
						 * Register a new conversation
 | 
				
			||||||
	 * 
 | 
						 * 
 | 
				
			||||||
@@ -149,6 +192,9 @@ ComunicWeb.components.conversations.service = {
 | 
				
			|||||||
			clearObject(this.__serviceCache);
 | 
								clearObject(this.__serviceCache);
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							//Unlock service
 | 
				
			||||||
 | 
							this.__serviceLock = false;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		//Success
 | 
							//Success
 | 
				
			||||||
		return true;
 | 
							return true;
 | 
				
			||||||
	},
 | 
						},
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user