@@ -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<Database::Persistent>())
|
||||
if (goptions.col<Database::GlobalPersistent>())
|
||||
persistent = true;
|
||||
else
|
||||
{
|
||||
|
||||
@@ -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, "");
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -6,6 +6,8 @@
|
||||
#include <utils/get_first_non_empty.hpp>
|
||||
#include <utils/time.hpp>
|
||||
|
||||
#include <config/config.hpp>
|
||||
|
||||
#include <database/index.hpp>
|
||||
|
||||
#include <sqlite3.h>
|
||||
@@ -18,6 +20,9 @@ Database::IrcChannelOptionsTable Database::irc_channel_options("IrcChannelOption
|
||||
Database::RosterTable Database::roster("roster");
|
||||
std::map<Database::CacheKey, Database::EncodingIn::real_type> Database::encoding_in_cache{};
|
||||
|
||||
Database::GlobalPersistent::GlobalPersistent():
|
||||
Column<bool>{Config::get_bool("persistent_by_default", false)}
|
||||
{}
|
||||
|
||||
void Database::open(const std::string& filename)
|
||||
{
|
||||
|
||||
@@ -73,6 +73,9 @@ class Database
|
||||
struct Persistent: Column<bool> { static constexpr auto name = "persistent_";
|
||||
Persistent(): Column<bool>(false) {} };
|
||||
|
||||
struct GlobalPersistent: Column<bool> { static constexpr auto name = "persistent_";
|
||||
GlobalPersistent(); };
|
||||
|
||||
struct LocalJid: Column<std::string> { static constexpr auto name = "local"; };
|
||||
|
||||
struct RemoteJid: Column<std::string> { static constexpr auto name = "remote"; };
|
||||
@@ -81,7 +84,7 @@ class Database
|
||||
using MucLogLineTable = Table<Id, Uuid, Owner, IrcChanName, IrcServerName, Date, Body, Nick>;
|
||||
using MucLogLine = MucLogLineTable::RowType;
|
||||
|
||||
using GlobalOptionsTable = Table<Id, Owner, MaxHistoryLength, RecordHistory, Persistent>;
|
||||
using GlobalOptionsTable = Table<Id, Owner, MaxHistoryLength, RecordHistory, GlobalPersistent>;
|
||||
using GlobalOptions = GlobalOptionsTable::RowType;
|
||||
|
||||
using IrcServerOptionsTable = Table<Id, Owner, Server, Pass, AfterConnectionCommand, TlsPorts, Ports, Username, Realname, VerifyCert, TrustedFingerprint, EncodingOut, EncodingIn, MaxHistoryLength>;
|
||||
|
||||
@@ -159,7 +159,7 @@ void ConfigureGlobalStep1(XmppComponent&, AdhocSession& session, XmlNode& comman
|
||||
{
|
||||
XmlSubNode value(persistent, "value");
|
||||
value.set_name("value");
|
||||
if (options.col<Database::Persistent>())
|
||||
if (options.col<Database::GlobalPersistent>())
|
||||
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<Database::Persistent>() = to_bool(value->get_inner());
|
||||
options.col<Database::GlobalPersistent>() = to_bool(value->get_inner());
|
||||
}
|
||||
|
||||
options.save(Database::db);
|
||||
|
||||
Reference in New Issue
Block a user