2018-04-15 13:02:32 +00:00
|
|
|
/**
|
|
|
|
* Settings interface
|
|
|
|
*
|
|
|
|
* @author Pierre HUBERT
|
|
|
|
*/
|
|
|
|
|
2020-04-03 16:43:23 +00:00
|
|
|
const SettingsInterface = {
|
2018-04-15 13:02:32 +00:00
|
|
|
|
2018-04-16 14:15:48 +00:00
|
|
|
/**
|
|
|
|
* Get general account settings
|
|
|
|
*
|
|
|
|
* @param {function} callback
|
|
|
|
*/
|
|
|
|
getGeneral: function(callback){
|
|
|
|
|
|
|
|
//Make a request over the API
|
2018-04-16 14:16:55 +00:00
|
|
|
var apiURI = "settings/get_general";
|
2018-04-16 14:15:48 +00:00
|
|
|
var params = {};
|
|
|
|
ComunicWeb.common.api.makeAPIrequest(apiURI, params, true, callback);
|
|
|
|
|
|
|
|
},
|
2018-04-15 13:02:32 +00:00
|
|
|
|
2018-04-17 17:47:18 +00:00
|
|
|
/**
|
|
|
|
* Set (update) general account settings
|
|
|
|
*
|
|
|
|
* @param {object} settings New general account settings
|
|
|
|
* @param {function} callback Callback function
|
|
|
|
*/
|
|
|
|
setGeneral: function(settings, callback){
|
|
|
|
var apiURI = "settings/set_general";
|
|
|
|
ComunicWeb.common.api.makeAPIrequest(apiURI, settings, true, callback);
|
|
|
|
},
|
2021-02-17 17:38:04 +00:00
|
|
|
|
2018-04-17 12:05:27 +00:00
|
|
|
/**
|
|
|
|
* Check the availability of the virtual directory for user
|
|
|
|
*
|
|
|
|
* @param {string} directory The directory to check
|
2018-04-19 08:20:49 +00:00
|
|
|
* @param {function} callback
|
2018-04-17 12:05:27 +00:00
|
|
|
*/
|
|
|
|
checkUserDirectoryAvailability: function(directory, callback){
|
|
|
|
var apiURI = "settings/check_user_directory_availability";
|
|
|
|
var params = {
|
|
|
|
directory: directory
|
|
|
|
};
|
|
|
|
ComunicWeb.common.api.makeAPIrequest(apiURI, params, true, callback);
|
2018-04-18 16:33:18 +00:00
|
|
|
},
|
|
|
|
|
2018-08-15 06:26:14 +00:00
|
|
|
/**
|
|
|
|
* Get language settings
|
|
|
|
*
|
|
|
|
* @param {function} callback
|
|
|
|
*/
|
|
|
|
getLanguage: function(callback){
|
|
|
|
//Make a request over the API
|
|
|
|
var apiURI = "settings/get_language";
|
|
|
|
var params = {};
|
|
|
|
ComunicWeb.common.api.makeAPIrequest(apiURI, params, true, callback);
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set (update) language settinsg
|
|
|
|
*
|
|
|
|
* @param {string} language The language to apply
|
|
|
|
* @param {function} callback
|
|
|
|
*/
|
|
|
|
setLanguage: function(language, callback){
|
|
|
|
//Make a request over the API
|
|
|
|
var apiURI = "settings/set_language";
|
|
|
|
var params = {
|
|
|
|
lang: language
|
|
|
|
};
|
|
|
|
ComunicWeb.common.api.makeAPIrequest(apiURI, params, true, callback);
|
|
|
|
},
|
|
|
|
|
2018-04-18 16:33:18 +00:00
|
|
|
/**
|
|
|
|
* Get security account settings
|
|
|
|
*
|
|
|
|
* @param {string} password The password of the user
|
|
|
|
* @param {function} callback Callback function
|
|
|
|
*/
|
|
|
|
getSecurity: function(password, callback){
|
|
|
|
var apiURI = "settings/get_security";
|
|
|
|
var params = {
|
|
|
|
password: password
|
|
|
|
};
|
|
|
|
ComunicWeb.common.api.makeAPIrequest(apiURI, params, true, callback);
|
|
|
|
},
|
2018-04-17 12:05:27 +00:00
|
|
|
|
2018-04-19 08:20:49 +00:00
|
|
|
/**
|
|
|
|
* Set (update) security account settings
|
|
|
|
*
|
|
|
|
* @param {object} settings New settings
|
|
|
|
* @param {function} callback
|
|
|
|
*/
|
|
|
|
setSecurity: function(settings, callback){
|
|
|
|
var apiURI = "settings/set_security";
|
|
|
|
ComunicWeb.common.api.makeAPIrequest(apiURI, settings, true, callback);
|
2018-04-20 06:35:43 +00:00
|
|
|
},
|
2018-04-19 08:20:49 +00:00
|
|
|
|
2018-04-20 06:35:43 +00:00
|
|
|
/**
|
|
|
|
* Update the password of the user
|
|
|
|
*
|
|
|
|
* @param {string} oldPassword The old password of the user
|
|
|
|
* @param {string} newPassword The new password
|
|
|
|
* @param {function} callback
|
|
|
|
*/
|
|
|
|
updatePassword: function(oldPassword, newPassword, callback){
|
|
|
|
var apiURI = "settings/update_password";
|
|
|
|
var params = {
|
|
|
|
oldPassword: oldPassword,
|
|
|
|
newPassword: newPassword
|
|
|
|
};
|
|
|
|
ComunicWeb.common.api.makeAPIrequest(apiURI, params, true, callback);
|
|
|
|
},
|
2018-04-29 13:13:51 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get account image settings from the API
|
|
|
|
*
|
|
|
|
* @param {function} callback
|
|
|
|
*/
|
|
|
|
getAccountImage: function(callback){
|
|
|
|
var apiURI = "settings/get_account_image";
|
|
|
|
var params = {};
|
|
|
|
ComunicWeb.common.api.makeAPIrequest(apiURI, params, true, callback);
|
2018-05-01 06:59:14 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Upload a new account image
|
|
|
|
*
|
|
|
|
* @param {FormData} data The data containing information about the new account image
|
|
|
|
* @param {function} callback
|
|
|
|
*/
|
|
|
|
uploadAccountImage: function(data, callback){
|
|
|
|
var apiURI = "settings/upload_account_image";
|
|
|
|
ComunicWeb.common.api.makeFormDatarequest(apiURI, data, true, callback);
|
2018-05-01 08:57:58 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Delete current user account image
|
|
|
|
*
|
|
|
|
* @param {function} callback
|
|
|
|
*/
|
|
|
|
deleteAccountImage: function(callback){
|
|
|
|
var apiURI = "settings/delete_account_image";
|
|
|
|
var params = {};
|
|
|
|
ComunicWeb.common.api.makeAPIrequest(apiURI, params, true, callback);
|
2018-05-01 09:42:23 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Update the visibility of the account image
|
|
|
|
*
|
|
|
|
* @param {string} visibility The new visibility level for the account image
|
|
|
|
* @param {function} callback
|
|
|
|
*/
|
|
|
|
updateAccountImageVisibility: function(visibility, callback){
|
|
|
|
var apiURI = "settings/set_account_image_visibility";
|
|
|
|
var params = {
|
|
|
|
visibility: visibility
|
|
|
|
};
|
|
|
|
ComunicWeb.common.api.makeAPIrequest(apiURI, params, true, callback);
|
2020-04-03 16:32:11 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Upload a new custom emoji on the server
|
|
|
|
*
|
|
|
|
* @param {FormData} form Associated form
|
|
|
|
*/
|
|
|
|
uploadEmoji: async function(form) {
|
|
|
|
return new Promise((res, err) => {
|
|
|
|
ComunicWeb.common.api.makeFormDatarequest("settings/upload_custom_emoji", form, true, (data) => {
|
|
|
|
if(data.error)
|
|
|
|
err(data.error);
|
|
|
|
else
|
|
|
|
res(data)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
},
|
2020-04-03 16:43:23 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Delete a custom emoji
|
|
|
|
*
|
|
|
|
* @param {Number} id The ID of the emoji to delete
|
|
|
|
*/
|
|
|
|
deleteEmoji: async function(id) {
|
|
|
|
await api("settings/delete_custom_emoji", {
|
|
|
|
emojiID: id
|
|
|
|
}, true);
|
|
|
|
},
|
2021-02-16 17:00:26 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get data conservation policy
|
|
|
|
*
|
|
|
|
* @returns {Promise<DataConservationPolicy>}
|
|
|
|
*/
|
|
|
|
getDataConservationPolicy: async function() {
|
|
|
|
return await api("settings/get_data_conservation_policy", null, true);
|
2021-02-16 17:23:59 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Update data conservation password
|
|
|
|
*
|
|
|
|
* @param {DataConservationPolicy} policy New policy
|
|
|
|
* @param {String} password User password
|
|
|
|
*/
|
|
|
|
setDataConservationPolicy: async function(policy, password) {
|
|
|
|
let data = {
|
|
|
|
password: password
|
|
|
|
}
|
|
|
|
|
|
|
|
for (let key in policy) {
|
|
|
|
if (policy.hasOwnProperty(key))
|
|
|
|
data[key] = policy[key]
|
|
|
|
}
|
|
|
|
|
|
|
|
await api("settings/set_data_conservation_policy", data, true)
|
2021-02-16 17:00:26 +00:00
|
|
|
}
|
2020-04-03 16:43:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ComunicWeb.components.settings.interface = SettingsInterface;
|