33 const std::string& accountId)
35 if (accountId.empty())
36 return rootPath /
"data" /
"preferences.json";
38 return rootPath /
"data" /
"accountpreferences.json";
44 if (accountId.empty() || accountId ==
"default")
45 return rootPath /
"preferences.msgpack";
48 dhtnet::fileutils::check_dir(
dir);
49 return dir /
"preferences.msgpack";
81std::map<std::string, std::string>
87 for (
const auto&
member : members) {
89 if (
value.isString()) {
91 }
else if (
value.isArray()) {
98std::vector<std::map<std::string, std::string>>
105 Json::CharReaderBuilder rbuilder;
106 rbuilder[
"collectComments"] =
false;
108 std::set<std::string>
keys;
109 std::vector<std::map<std::string, std::string>> preferences;
117 if (
ok &&
root.isArray()) {
119 for (
unsigned i = 0;
i <
root.size();
i++) {
125 if (type !=
"None" && key !=
"None") {
142 "{{" +
locale.first +
"}}",
153 JAMI_ERR() <<
"PluginPreferencesParser:: Failed to parse preferences.json for plugin: "
161std::map<std::string, std::string>
163 const std::string& accountId)
168 std::map<std::string, std::string>
rmap;
174 file.seekg(0, std::ios::end);
179 str.reserve(
static_cast<size_t>(
file.tellg()));
180 file.seekg(0, std::ios::beg);
181 str.assign((std::istreambuf_iterator<char>(
file)), std::istreambuf_iterator<char>());
185 msgpack::object_handle
oh = msgpack::unpack(
str.data(),
str.size());
189 }
catch (
const std::exception&
e) {
197std::map<std::string, std::string>
199 const std::string& accountId)
201 std::map<std::string, std::string>
rmap;
207 preferences.push_back(
item);
218 if (!accountId.empty()) {
230 const std::string& accountId)
243 }
catch (
const std::exception&
e) {
255 std::lock_guard
guard(dhtnet::fileutils::getFileLock(
filePath));
262 }
catch (
const std::exception&
e) {
271 std::lock_guard
guard(dhtnet::fileutils::getFileLock(
filePath));
278 file.seekg(0, std::ios::end);
283 str.reserve(
static_cast<size_t>(
file.tellg()));
284 file.seekg(0, std::ios::beg);
285 str.assign((std::istreambuf_iterator<char>(
file)), std::istreambuf_iterator<char>());
289 msgpack::object_handle
oh = msgpack::unpack(
str.data(),
str.size());
293 }
catch (
const std::exception&
e) {
308 std::lock_guard
guard(dhtnet::fileutils::getFileLock(
filePath));
310 Json::CharReaderBuilder rbuilder;
312 rbuilder[
"collectComments"] =
false;
316 if (
ok &&
root.isArray()) {
328 std::lock_guard
guard(dhtnet::fileutils::getFileLock(
filePath));
330 Json::CharReaderBuilder rbuilder;
332 rbuilder[
"collectComments"] =
false;
336 if (
ok &&
root.isArray()) {
352 std::lock_guard
guard(dhtnet::fileutils::getFileLock(
filePath));
364 const std::string& accountId)
369 preferences.push_back(
item);
static std::map< std::string, std::string > getPreferencesValuesMap(const std::filesystem::path &rootPath, const std::string &accountId="")
Reads preferences values.
static void getAllowDenyListPreferences(ChatHandlerList &list)
Reads ChantHandlers status from allowdeny.msgpack file.
static std::map< std::string, std::string > parsePreferenceConfig(const Json::Value &jsonPreference)
Parses a single preference from json::Value to a Map<string, string>.
static std::filesystem::path getPreferencesConfigFilePath(const std::filesystem::path &rootPath, const std::string &accountId="")
Given a plugin installation path, returns the path to the preference.json of this plugin.
static std::vector< std::map< std::string, std::string > > getPreferences(const std::filesystem::path &rootPath, const std::string &accountId="")
Reads a preference.json file from the plugin installed in rootPath.
static bool getAlwaysPreference(const std::string &rootPath, const std::string &handlerName, const std::string &accountId)
Read plugin's preferences and returns wheter a specific handler "always" preference is True or False.
static std::filesystem::path getAllowDenyListsPath()
Returns the path to allowdeny.msgpack file.
static std::filesystem::path valuesFilePath(const std::filesystem::path &rootPath, const std::string &accountId="")
Given a plugin installation path, returns the path to the preference.msgpack file.
static void setAllowDenyListPreferences(const ChatHandlerList &list)
Saves ChantHandlers status provided by list.
static bool resetPreferencesValuesMap(const std::string &rootPath, const std::string &accountId)
Resets all preferences values to their defaultValues by erasing all data saved in preferences....
static std::map< std::string, std::string > getUserPreferencesValuesMap(const std::filesystem::path &rootPath, const std::string &accountId="")
Reads preferences values which were modified from defaultValue.
static void addAlwaysHandlerPreference(const std::string &handlerName, const std::string &rootPath)
Creates a "always" preference for a handler if this preference doesn't exist yet.
static std::string convertArrayToString(const Json::Value &jsonArray)
Returns a colon separated string with values from a json::Value containing an array.
std::string getLanguage()
Returns the language of the current locale.
std::map< std::string, std::string > getLocales(const std::string &rootPath, const std::string &lang)
Returns the available keys and translations for a given plugin.
const std::filesystem::path & get_data_dir()
void emitSignal(Args... args)
std::string_view string_remove_suffix(std::string_view str, char separator)
std::map< std::pair< std::string, std::string >, std::map< std::string, bool > > ChatHandlerList
void string_replace(std::string &str, const std::string &from, const std::string &to)