mirror of
https://github.com/pierre42100/ComunicWeb
synced 2024-11-26 05:49:22 +00:00
Can create & open private conversation quickly
This commit is contained in:
parent
ec27f58676
commit
f593983c83
@ -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
|
||||
|
@ -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;
|
||||
|
||||
},
|
||||
}
|
Loading…
Reference in New Issue
Block a user