From bfcf29451787d10c747ad79cb3fd177ac86e9cf1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?louiz=E2=80=99?= Date: Sat, 9 Sep 2017 17:09:17 +0200 Subject: Add the persistent_by_default configuration option fix #3293 --- src/bridge/bridge.cpp | 2 +- src/config/config.cpp | 8 ++++++++ src/config/config.hpp | 1 + src/database/database.cpp | 5 +++++ src/database/database.hpp | 5 ++++- src/xmpp/biboumi_adhoc_commands.cpp | 4 ++-- 6 files changed, 21 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/bridge/bridge.cpp b/src/bridge/bridge.cpp index 02ba565..8587264 100644 --- a/src/bridge/bridge.cpp +++ b/src/bridge/bridge.cpp @@ -435,7 +435,7 @@ void Bridge::leave_irc_channel(Iid&& iid, const std::string& status_message, con bool persistent = false; #ifdef USE_DATABASE const auto goptions = Database::get_global_options(this->user_jid); - if (goptions.col()) + if (goptions.col()) persistent = true; else { diff --git a/src/config/config.cpp b/src/config/config.cpp index 0f3d639..412b170 100644 --- a/src/config/config.cpp +++ b/src/config/config.cpp @@ -23,6 +23,14 @@ std::string Config::get(const std::string& option, const std::string& def) return it->second; } +bool Config::get_bool(const std::string& option, const bool def) +{ + auto res = Config::get(option, ""); + if (res.empty()) + return def; + return res == "true"; +} + int Config::get_int(const std::string& option, const int& def) { std::string res = Config::get(option, ""); diff --git a/src/config/config.hpp b/src/config/config.hpp index 2ba38cc..c5ef15d 100644 --- a/src/config/config.hpp +++ b/src/config/config.hpp @@ -44,6 +44,7 @@ public: * the second argument as the default. */ static int get_int(const std::string&, const int&); + static bool get_bool(const std::string&, const bool); /** * Set a value for the given option. And write all the config * in the file from which it was read if save is true. diff --git a/src/database/database.cpp b/src/database/database.cpp index f706528..a2b88e2 100644 --- a/src/database/database.cpp +++ b/src/database/database.cpp @@ -6,6 +6,8 @@ #include #include +#include + #include #include @@ -18,6 +20,9 @@ Database::IrcChannelOptionsTable Database::irc_channel_options("IrcChannelOption Database::RosterTable Database::roster("roster"); std::map Database::encoding_in_cache{}; +Database::GlobalPersistent::GlobalPersistent(): + Column{Config::get_bool("persistent_by_default", false)} +{} void Database::open(const std::string& filename) { diff --git a/src/database/database.hpp b/src/database/database.hpp index f4b2ecd..f9695d3 100644 --- a/src/database/database.hpp +++ b/src/database/database.hpp @@ -73,6 +73,9 @@ class Database struct Persistent: Column { static constexpr auto name = "persistent_"; Persistent(): Column(false) {} }; + struct GlobalPersistent: Column { static constexpr auto name = "persistent_"; + GlobalPersistent(); }; + struct LocalJid: Column { static constexpr auto name = "local"; }; struct RemoteJid: Column { static constexpr auto name = "remote"; }; @@ -81,7 +84,7 @@ class Database using MucLogLineTable = Table; using MucLogLine = MucLogLineTable::RowType; - using GlobalOptionsTable = Table; + using GlobalOptionsTable = Table; using GlobalOptions = GlobalOptionsTable::RowType; using IrcServerOptionsTable = Table; diff --git a/src/xmpp/biboumi_adhoc_commands.cpp b/src/xmpp/biboumi_adhoc_commands.cpp index d78dc98..bcdac39 100644 --- a/src/xmpp/biboumi_adhoc_commands.cpp +++ b/src/xmpp/biboumi_adhoc_commands.cpp @@ -159,7 +159,7 @@ void ConfigureGlobalStep1(XmppComponent&, AdhocSession& session, XmlNode& comman { XmlSubNode value(persistent, "value"); value.set_name("value"); - if (options.col()) + if (options.col()) value.set_inner("true"); else value.set_inner("false"); @@ -193,7 +193,7 @@ void ConfigureGlobalStep2(XmppComponent& xmpp_component, AdhocSession& session, } else if (field->get_tag("var") == "persistent" && value) - options.col() = to_bool(value->get_inner()); + options.col() = to_bool(value->get_inner()); } options.save(Database::db); -- cgit v1.2.3