From 090b8bd77a755b52a79c0da67c1f545227f7ecb8 Mon Sep 17 00:00:00 2001 From: Pierre Date: Sun, 25 Jun 2017 16:15:23 +0200 Subject: [PATCH] Send refresh conversation request on the server --- assets/js/common/network.js | 2 +- .../js/components/conversations/interface.js | 28 +++++++++++++++++++ assets/js/components/conversations/service.js | 10 ++++++- 3 files changed, 38 insertions(+), 2 deletions(-) diff --git a/assets/js/common/network.js b/assets/js/common/network.js index df7f3184..a9d72280 100644 --- a/assets/js/common/network.js +++ b/assets/js/common/network.js @@ -105,7 +105,7 @@ ComunicWeb.common.network = { networkErrorMessage.id = "networkErrorMessage"; //Create a callout element within it - var errorName = " "+"Network error"; + var errorName = " "+" Network error"; var errorMessage = "It seems that there is a network error, and Comunic can't access to the Internet anymore... Please check your internet connexion..."; var errorCallout = ComunicWeb.common.messages.createCalloutElem(errorName, errorMessage, "danger"); networkErrorMessage.appendChild(errorCallout) diff --git a/assets/js/components/conversations/interface.js b/assets/js/components/conversations/interface.js index 54738f84..5ff9c55c 100644 --- a/assets/js/components/conversations/interface.js +++ b/assets/js/components/conversations/interface.js @@ -264,6 +264,34 @@ ComunicWeb.components.conversations.interface = { }, + /** + * Refresh a conversation + * + * @param {Array} newConversations New conversations (which requires the 10 last messages) + * @param {Object} toRefresh Conversations to refresh + * @param {Function} callback The callback function + * @return {Boolean} True for a success + */ + refreshConversations: function(newConversations, toRefresh, callback){ + + //DEBUG log informations + console.log("New conversations", newConversations); + console.log("To refresh", toRefresh); + + //Perform a request on the API + var apiURI = "conversations/refresh"; + var params = { + newConversations: newConversations, + toRefresh: JSON.stringify(toRefresh), + } + + //Perform an API request + ComunicWeb.common.api.makeAPIrequest(apiURI, params, true, callback); + + //Success + return true; + }, + /** * Empty conversations cache * diff --git a/assets/js/components/conversations/service.js b/assets/js/components/conversations/service.js index bc420275..0aa942d4 100644 --- a/assets/js/components/conversations/service.js +++ b/assets/js/components/conversations/service.js @@ -119,7 +119,15 @@ ComunicWeb.components.conversations.service = { } //Perform a request on the interface - + ComunicWeb.components.conversations.interface.refreshConversations( + newConversations, + conversationsToRefresh, + function(result){ + //Call callback function + ComunicWeb.components.conversations.service.callback(result); + } + ); + //Success return true; },