Can create & open private conversation quickly

This commit is contained in:
Pierre 2017-06-19 14:55:29 +02:00
parent ec27f58676
commit f593983c83
2 changed files with 68 additions and 1 deletions

View File

@ -203,6 +203,39 @@ ComunicWeb.components.conversations.interface = {
return true;
},
/**
* Search for private conversation
*
* @param {Integer} otherUser The ID of the other user
* @param {Boolean} allowCreation Allow the server to create the conversation if not found
* @param {function} callback What to do once the request is completed
* @return {Boolean} True for a success
*/
searchPrivate: function(otherUser, allowCreation, callback){
//Perform an API request
var apiURI = "conversations/getPrivate";
var params = {
otherUser: otherUser,
allowCreate: allowCreation
}
//Perform API request
ComunicWeb.common.api.makeAPIrequest(apiURI, params, true, function(result){
//Check for errors
if(result.error)
ComunicWeb.debug.logMessage("An error occured while trying to get a private conversation ID !");
//Perfrorm next action
callback(result);
});
//Success
return true;
},
/**
* Empty conversations cache
*
@ -218,7 +251,7 @@ ComunicWeb.components.conversations.interface = {
//Success
return true;
}
},
}
//Register conversations cache cleaning function

View File

@ -129,4 +129,38 @@ ComunicWeb.components.conversations.manager = {
//Success
return true;
},
/**
* Open a private conversation with only one user
*
* @param {Integer} otherID The ID of the user with who the conversation will be started
* @return {Boolean} True for a success
*/
openPrivate: function(otherID){
//Search for such conversation in the database, create it in case of failure
//Prepare what to do next
var callback = function(result){
//In case of error
if(result.error){
//Notify user
ComunicWeb.common.notificationSystem.showNotification("Couldn't create a conversation with this user ! Please try again...", "danger", 2);
return false;
}
//Open the first conversation
ComunicWeb.components.conversations.manager.addConversation({
conversationID: result.conversationsID[0],
});
};
//Peform request
ComunicWeb.components.conversations.interface.searchPrivate(otherID, true, callback);
//Success
return true;
},
}