Add a global configure ad-hoc command, with max history length

This commit is contained in:
louiz’
2016-08-22 00:38:44 +02:00
parent 992fa93895
commit 6776b827d2
6 changed files with 126 additions and 12 deletions
+36
View File
@@ -31,6 +31,19 @@ void Database::set_verbose(const bool val)
Database::db->verbose = val;
}
db::GlobalOptions Database::get_global_options(const std::string& owner)
{
try {
auto options = litesql::select<db::GlobalOptions>(*Database::db,
db::GlobalOptions::Owner == owner).one();
return options;
} catch (const litesql::NotFound& e) {
db::GlobalOptions options(*Database::db);
options.owner = owner;
return options;
}
}
db::IrcServerOptions Database::get_irc_server_options(const std::string& owner,
const std::string& server)
{
@@ -79,6 +92,29 @@ db::IrcChannelOptions Database::get_irc_channel_options_with_server_default(cons
coptions.encodingOut = get_first_non_empty(coptions.encodingOut.value(),
soptions.encodingOut.value());
coptions.maxHistoryLength = get_first_non_empty(coptions.maxHistoryLength.value(),
soptions.maxHistoryLength.value());
return coptions;
}
db::IrcChannelOptions Database::get_irc_channel_options_with_server_and_global_default(const std::string& owner,
const std::string& server,
const std::string& channel)
{
auto coptions = Database::get_irc_channel_options(owner, server, channel);
auto soptions = Database::get_irc_server_options(owner, server);
auto goptions = Database::get_global_options(owner);
coptions.encodingIn = get_first_non_empty(coptions.encodingIn.value(),
soptions.encodingIn.value());
coptions.encodingOut = get_first_non_empty(coptions.encodingOut.value(),
soptions.encodingOut.value());
coptions.maxHistoryLength = get_first_non_empty(coptions.maxHistoryLength.value(),
soptions.maxHistoryLength.value(),
goptions.maxHistoryLength.value());
return coptions;
}
+4 -1
View File
@@ -36,6 +36,7 @@ public:
* Return the object from the db. Create it beforehand (with all default
* values) if it is not already present.
*/
static db::GlobalOptions get_global_options(const std::string& owner);
static db::IrcServerOptions get_irc_server_options(const std::string& owner,
const std::string& server);
static db::IrcChannelOptions get_irc_channel_options(const std::string& owner,
@@ -44,7 +45,9 @@ public:
static db::IrcChannelOptions get_irc_channel_options_with_server_default(const std::string& owner,
const std::string& server,
const std::string& channel);
static db::IrcChannelOptions get_irc_channel_options_with_server_and_global_default(const std::string& owner,
const std::string& server,
const std::string& channel);
static void store_muc_message(const std::string& owner, const Iid& iid,
time_point date, const std::string& body, const std::string& nick);