mirror of
				https://github.com/pierre42100/ComunicWeb
				synced 2025-10-30 01:34:53 +00:00 
			
		
		
		
	Can get and cache conversations list
This commit is contained in:
		| @@ -5,6 +5,62 @@ | ||||
|  */ | ||||
|  | ||||
| ComunicWeb.components.conversations.interface = { | ||||
|  | ||||
| 	/** | ||||
| 	 * @var {Object} __conversationsList Cached list of conversations | ||||
| 	 */ | ||||
| 	__conversationsList: false, | ||||
|  | ||||
| 	/** | ||||
| 	 * Get and return the list of available conversations | ||||
| 	 *  | ||||
| 	 * @param {Function} onceGotList What to do next | ||||
| 	 * @param {Boolean} force Force the list to be loaded even if present in the cache | ||||
| 	 * @return {Boolean} True for a success | ||||
| 	 */ | ||||
| 	getList: function(onceGotList, force){ | ||||
|  | ||||
| 		//First, check if the list is already present in the cache or not | ||||
| 		if(this.__conversationsList && !force){ | ||||
| 			//Perform next action now | ||||
| 			onceGotList(this.__conversationsList); | ||||
| 		} | ||||
|  | ||||
| 		//Else, prepare an API request | ||||
| 		var apiURI = "conversations/getList"; | ||||
| 		var params = {}; //No params required now | ||||
|  | ||||
| 		//Perform the API request | ||||
| 		ComunicWeb.common.api.makeAPIrequest(apiURI, params, true, function(results){ | ||||
|  | ||||
| 			//Check for error | ||||
| 			if(results.error){ | ||||
| 				//Log error | ||||
| 				ComunicWeb.debug.logMessage("ERROR : couldn't get conversations list !"); | ||||
|  | ||||
| 				//Perform next action | ||||
| 				onceGotList(results); | ||||
| 			} | ||||
| 			else { | ||||
| 				//Process the list | ||||
| 				var conversationsList = {}; | ||||
| 				for(i in results){ | ||||
| 					conversationsList["conversation-"+results[i].ID] = results[i]; | ||||
| 				} | ||||
|  | ||||
| 				//Save the list in the cache | ||||
| 				ComunicWeb.components.conversations.interface.__conversationsList = conversationsList; | ||||
|  | ||||
| 				//Perform next action | ||||
| 				onceGotList(conversationsList); | ||||
| 			} | ||||
|  | ||||
| 		}); | ||||
|  | ||||
| 		//Success | ||||
| 		return true; | ||||
| 	}, | ||||
|  | ||||
| 	/** | ||||
| 	 * Create a conversation | ||||
| 	 *  | ||||
| @@ -41,5 +97,5 @@ ComunicWeb.components.conversations.interface = { | ||||
|  | ||||
| 		//Success | ||||
| 		return true; | ||||
| 	} | ||||
| 	}, | ||||
| } | ||||
| @@ -31,6 +31,7 @@ ComunicWeb.components.conversations.list = { | ||||
| 		createButton.className = "btn btn-box-tool"; | ||||
| 		createButton.onclick = function(){ | ||||
| 			ComunicWeb.components.conversations.list.displayCreateForm(listBox); | ||||
| 			this.remove(); | ||||
| 		} | ||||
|  | ||||
| 			//Button icon | ||||
| @@ -38,7 +39,7 @@ ComunicWeb.components.conversations.list = { | ||||
| 			createButtonIcon.className = "fa fa-pencil"; | ||||
|  | ||||
| 		//Get and display conversations list | ||||
| 		//TODO : implement | ||||
| 		this.showConversationsList(); | ||||
|  | ||||
| 		//Success | ||||
| 		return true; | ||||
| @@ -180,5 +181,23 @@ ComunicWeb.components.conversations.list = { | ||||
| 			//Open the conversation (under construction) | ||||
| 			console.log("Open conversation ID: " + response.conversationID); | ||||
| 		}) | ||||
| 	} | ||||
| 	}, | ||||
|  | ||||
| 	/** | ||||
| 	 * Show the conversations list | ||||
| 	 *  | ||||
| 	 * @return {Boolean} True for a success | ||||
| 	 */ | ||||
| 	showConversationsList: function(){ | ||||
|  | ||||
| 		//Get and show the conversation list | ||||
| 		ComunicWeb.components.conversations.interface.getList(function(){ | ||||
|  | ||||
| 			console.log("OK --------------------"); | ||||
|  | ||||
| 		}, true); | ||||
|  | ||||
| 		//Success | ||||
| 		return true; | ||||
| 	}, | ||||
| } | ||||
		Reference in New Issue
	
	Block a user
	 Pierre
					Pierre