From 0b51e3828116f6847865fae93893eb97a10d1cc2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?louiz=E2=80=99?= Date: Thu, 23 Aug 2018 20:30:11 +0200 Subject: MaxHistoryLength now has some sensible default value if the user set a negative one --- src/bridge/bridge.cpp | 9 ++++++--- src/database/database.cpp | 4 ---- src/database/query.cpp | 5 ----- src/database/query.hpp | 9 +++++---- src/utils/optional_bool.hpp | 2 +- 5 files changed, 12 insertions(+), 17 deletions(-) (limited to 'src') diff --git a/src/bridge/bridge.cpp b/src/bridge/bridge.cpp index ad03f38..a69bdff 100644 --- a/src/bridge/bridge.cpp +++ b/src/bridge/bridge.cpp @@ -1007,11 +1007,14 @@ void Bridge::send_room_history(const std::string& hostname, const std::string& c void Bridge::send_room_history(const std::string& hostname, std::string chan_name, const std::string& resource, const HistoryLimit& history_limit) { #ifdef USE_DATABASE - const auto coptions = Database::get_irc_channel_options_with_server_and_global_default(this->user_jid, hostname, chan_name); - auto limit = coptions.col(); + const auto goptions = Database::get_global_options(this->user_jid); + log_debug(goptions.col()); + auto limit = goptions.col(); + if (limit < 0) + limit = 20; if (history_limit.stanzas >= 0 && history_limit.stanzas < limit) limit = history_limit.stanzas; - const auto result = Database::get_muc_logs(this->user_jid, chan_name, hostname, limit, history_limit.since, {}, Id::unset_value, Database::Paging::last); + const auto result = Database::get_muc_logs(this->user_jid, chan_name, hostname, static_cast(limit), history_limit.since, {}, Id::unset_value, Database::Paging::last); const auto& lines = std::get<1>(result); chan_name.append(utils::empty_if_fixed_server("%" + hostname)); for (const auto& line: lines) diff --git a/src/database/database.cpp b/src/database/database.cpp index 3578c04..9037ce1 100644 --- a/src/database/database.cpp +++ b/src/database/database.cpp @@ -162,10 +162,6 @@ Database::IrcChannelOptions Database::get_irc_channel_options_with_server_and_gl coptions.col() = get_first_non_empty(coptions.col(), soptions.col()); - coptions.col() = get_first_non_empty(coptions.col(), - soptions.col(), - goptions.col()); - return coptions; } diff --git a/src/database/query.cpp b/src/database/query.cpp index d72066e..5ec8599 100644 --- a/src/database/query.cpp +++ b/src/database/query.cpp @@ -6,11 +6,6 @@ void actual_bind(Statement& statement, const std::string& value, int index) statement.bind_text(index, value); } -void actual_bind(Statement& statement, const std::int64_t& value, int index) -{ - statement.bind_int64(index, value); -} - void actual_bind(Statement& statement, const OptionalBool& value, int index) { if (!value.is_set) diff --git a/src/database/query.hpp b/src/database/query.hpp index ba28b1a..ae6e946 100644 --- a/src/database/query.hpp +++ b/src/database/query.hpp @@ -12,13 +12,14 @@ #include void actual_bind(Statement& statement, const std::string& value, int index); -void actual_bind(Statement& statement, const std::int64_t& value, int index); -template ::value>* = 0> +void actual_bind(Statement& statement, const OptionalBool& value, int index); +template void actual_bind(Statement& statement, const T& value, int index) { - actual_bind(statement, static_cast(value), index); + static_assert(std::is_integral::value, + "Only a string, an optional-bool or an integer can be used."); + statement.bind_int64(index, static_cast(value)); } -void actual_bind(Statement& statement, const OptionalBool& value, int index); #ifdef DEBUG_SQL_QUERIES #include diff --git a/src/utils/optional_bool.hpp b/src/utils/optional_bool.hpp index 867aca2..3d00d23 100644 --- a/src/utils/optional_bool.hpp +++ b/src/utils/optional_bool.hpp @@ -6,7 +6,7 @@ struct OptionalBool { OptionalBool() = default; - OptionalBool(bool value): + explicit OptionalBool(bool value): is_set(true), value(value) {} void set_value(bool value) -- cgit v1.2.3