diff options
author | louiz’ <louiz@louiz.org> | 2018-02-13 03:10:00 +0100 |
---|---|---|
committer | louiz’ <louiz@louiz.org> | 2018-02-13 03:10:00 +0100 |
commit | fd7c365288b9c4db1d441b553d42b26e81715b36 (patch) | |
tree | ebd99e3af5ccffd605a65c5446c6d7deec9dd872 /src | |
parent | fd9c7139386e773ee64fe970089d77fede75181f (diff) | |
download | biboumi-fd7c365288b9c4db1d441b553d42b26e81715b36.tar.gz biboumi-fd7c365288b9c4db1d441b553d42b26e81715b36.tar.bz2 biboumi-fd7c365288b9c4db1d441b553d42b26e81715b36.tar.xz biboumi-fd7c365288b9c4db1d441b553d42b26e81715b36.zip |
Use the same function for both history orders
Diffstat (limited to 'src')
-rw-r--r-- | src/bridge/bridge.cpp | 2 | ||||
-rw-r--r-- | src/database/database.cpp | 40 | ||||
-rw-r--r-- | src/database/database.hpp | 8 |
3 files changed, 16 insertions, 34 deletions
diff --git a/src/bridge/bridge.cpp b/src/bridge/bridge.cpp index acb8e18..fefab40 100644 --- a/src/bridge/bridge.cpp +++ b/src/bridge/bridge.cpp @@ -1020,7 +1020,7 @@ void Bridge::send_room_history(const std::string& hostname, std::string chan_nam auto limit = coptions.col<Database::MaxHistoryLength>(); if (history_limit.stanzas >= 0 && history_limit.stanzas < limit) limit = history_limit.stanzas; - const auto lines = Database::get_muc_most_recent_logs(this->user_jid, chan_name, hostname, limit, history_limit.since); + const auto lines = Database::get_muc_logs(this->user_jid, chan_name, hostname, limit, history_limit.since, {}, Id::unset_value, Database::Paging::last); 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 2d6fbbd..2a63a6b 100644 --- a/src/database/database.cpp +++ b/src/database/database.cpp @@ -165,8 +165,11 @@ std::string Database::store_muc_message(const std::string& owner, const std::str } std::vector<Database::MucLogLine> Database::get_muc_logs(const std::string& owner, const std::string& chan_name, const std::string& server, - int limit, const std::string& start, const std::string& end, const Id::real_type after_id) + int limit, const std::string& start, const std::string& end, const Id::real_type after_id, Database::Paging paging) { + if (limit == 0) + return {}; + auto request = Database::muc_log_lines.select(); request.where() << Database::Owner{} << "=" << owner << \ " and " << Database::IrcChanName{} << "=" << chan_name << \ @@ -189,37 +192,20 @@ std::vector<Database::MucLogLine> Database::get_muc_logs(const std::string& owne request << " and " << Id{} << ">" << after_id; } - if (limit >= 0) - request.limit() << limit; - - auto result = request.execute(*Database::db); - - return {result.cbegin(), result.cend()}; -} - -std::vector<Database::MucLogLine> Database::get_muc_most_recent_logs(const std::string& owner, const std::string& chan_name, const std::string& server, - int limit, const std::string& start) -{ - auto request = Database::muc_log_lines.select(); - request.where() << Database::Owner{} << "=" << owner << \ - " and " << Database::IrcChanName{} << "=" << chan_name << \ - " and " << Database::IrcServerName{} << "=" << server; - - if (!start.empty()) - { - const auto start_time = utils::parse_datetime(start); - if (start_time != -1) - request << " and " << Database::Date{} << ">=" << start_time; - } - - request.order_by() << Id{} << " DESC "; + if (paging == Database::Paging::first) + request.order_by() << Id{} << " ASC "; + else + request.order_by() << Id{} << " DESC "; if (limit >= 0) request.limit() << limit; auto result = request.execute(*Database::db); - - return {result.crbegin(), result.crend()}; + + if (paging == Database::Paging::first) + return result; + else + return {result.crbegin(), result.crend()}; } Database::MucLogLine Database::get_muc_log(const std::string& owner, const std::string& chan_name, const std::string& server, diff --git a/src/database/database.hpp b/src/database/database.hpp index fb62c34..9c483f4 100644 --- a/src/database/database.hpp +++ b/src/database/database.hpp @@ -23,6 +23,7 @@ class Database public: using time_point = std::chrono::system_clock::time_point; struct RecordNotFound: public std::exception {}; + enum class Paging { first, last }; struct Uuid: Column<std::string> { static constexpr auto name = "uuid_"; }; @@ -125,14 +126,9 @@ class Database */ static std::vector<MucLogLine> get_muc_logs(const std::string& owner, const std::string& chan_name, const std::string& server, int limit=-1, const std::string& start="", const std::string& end="", - const Id::real_type after_id=Id::unset_value); + const Id::real_type after_id=Id::unset_value, Paging=Paging::first); /** - * Get the most recent messages from the archive, with optional limit and start date - */ - static std::vector<MucLogLine> get_muc_most_recent_logs(const std::string& owner, const std::string& chan_name, const std::string& server, - int limit=-1, const std::string& start=""); - /** * Get just one single record matching the given uuid, between (optional) end and start. * If it does not exist (or is not between end and start), throw a RecordNotFound exception. */ |