summaryrefslogtreecommitdiff
path: root/src/database/database.cpp
diff options
context:
space:
mode:
authorlouiz’ <louiz@louiz.org>2016-08-22 00:38:44 +0200
committerlouiz’ <louiz@louiz.org>2016-08-22 00:38:44 +0200
commit6776b827d243ec0e018eac8233c5df402030640e (patch)
tree261c35a77dacc928270601ac56424cab82de5b59 /src/database/database.cpp
parent992fa938951558f4515145c9b82af0123c979a29 (diff)
downloadbiboumi-6776b827d243ec0e018eac8233c5df402030640e.tar.gz
biboumi-6776b827d243ec0e018eac8233c5df402030640e.tar.bz2
biboumi-6776b827d243ec0e018eac8233c5df402030640e.tar.xz
biboumi-6776b827d243ec0e018eac8233c5df402030640e.zip
Add a global configure ad-hoc command, with max history length
Diffstat (limited to 'src/database/database.cpp')
-rw-r--r--src/database/database.cpp36
1 files changed, 36 insertions, 0 deletions
diff --git a/src/database/database.cpp b/src/database/database.cpp
index 3891f41..acf57d1 100644
--- a/src/database/database.cpp
+++ b/src/database/database.cpp
@@ -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;
}