From 5ef7ba08028065b03d51d1dc70bb35aeb41ae19d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?louiz=E2=80=99?= Date: Sat, 14 Apr 2018 19:48:45 +0200 Subject: Use the Date to find a next page in RSM, not the id This way, it works, whatever the order of insertion in the database was. fix #3343 --- src/bridge/bridge.cpp | 2 +- src/database/database.cpp | 9 +++++---- src/database/database.hpp | 2 +- src/xmpp/biboumi_component.cpp | 14 ++++++++------ 4 files changed, 15 insertions(+), 12 deletions(-) diff --git a/src/bridge/bridge.cpp b/src/bridge/bridge.cpp index 2598f51..afc8ad3 100644 --- a/src/bridge/bridge.cpp +++ b/src/bridge/bridge.cpp @@ -1005,7 +1005,7 @@ void Bridge::send_room_history(const std::string& hostname, std::string chan_nam auto limit = coptions.col(); if (history_limit.stanzas >= 0 && history_limit.stanzas < limit) limit = history_limit.stanzas; - const auto lines = Database::get_muc_logs(this->user_jid, chan_name, hostname, limit, history_limit.since, {}, Id::unset_value, Database::Paging::last); + const auto lines = Database::get_muc_logs(this->user_jid, chan_name, hostname, limit, history_limit.since, {}, {}, 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 c935139..fb24ad3 100644 --- a/src/database/database.cpp +++ b/src/database/database.cpp @@ -192,7 +192,7 @@ std::string Database::store_muc_message(const std::string& owner, const std::str } std::vector 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 reference_record_id, Database::Paging paging) + int limit, const std::string& start, const std::string& end, const std::string& reference_uuid, Database::Paging paging) { if (limit == 0) return {}; @@ -222,14 +222,15 @@ std::vector Database::get_muc_logs(const std::string& owne request << " and " << Database::Date{} << "<=" << writer; } } - if (reference_record_id != Id::unset_value) + if (!reference_uuid.empty()) { - request << " and " << Id{}; + request << " and " << Database::Date{}; if (paging == Database::Paging::first) request << ">"; else request << "<"; - request << reference_record_id; + request << "(SELECT " << Database::Date{} << " FROM " << Database::muc_log_lines.get_name().data() + << " WHERE " << Database::Uuid{} << " = " << reference_uuid << ")"; } if (paging == Database::Paging::first) diff --git a/src/database/database.hpp b/src/database/database.hpp index 75ff8f3..b4c4fa0 100644 --- a/src/database/database.hpp +++ b/src/database/database.hpp @@ -135,7 +135,7 @@ class Database */ static std::vector 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 reference_record_id=Id::unset_value, Paging=Paging::first); + const std::string& reference_record_id={}, Paging=Paging::first); /** * Get just one single record matching the given uuid, between (optional) end and start. diff --git a/src/xmpp/biboumi_component.cpp b/src/xmpp/biboumi_component.cpp index acaac34..f82a923 100644 --- a/src/xmpp/biboumi_component.cpp +++ b/src/xmpp/biboumi_component.cpp @@ -719,7 +719,7 @@ bool BiboumiComponent::handle_mam_request(const Stanza& stanza) } const XmlNode* set = query->get_child("set", RSM_NS); int limit = -1; - Id::real_type reference_record_id{Id::unset_value}; + std::string reference_uuid{}; Database::Paging paging_order{Database::Paging::first}; if (set) { @@ -729,9 +729,10 @@ bool BiboumiComponent::handle_mam_request(const Stanza& stanza) const XmlNode* after = set->get_child("after", RSM_NS); if (after) { - auto after_record = Database::get_muc_log(from.bare(), iid.get_local(), iid.get_server(), + // Will throw if the uuid does not exist, that’s all. + Database::get_muc_log(from.bare(), iid.get_local(), iid.get_server(), after->get_inner(), start, end); - reference_record_id = after_record.col(); + reference_uuid = after->get_inner(); } const XmlNode* before = set->get_child("before", RSM_NS); if (before) @@ -739,8 +740,9 @@ bool BiboumiComponent::handle_mam_request(const Stanza& stanza) paging_order = Database::Paging::last; if (!before->get_inner().empty()) { - auto before_record = Database::get_muc_log(from.bare(), iid.get_local(), iid.get_server(), before->get_inner(), start, end); - reference_record_id = before_record.col(); + // Will throw if the uuid does not exist + Database::get_muc_log(from.bare(), iid.get_local(), iid.get_server(), before->get_inner(), start, end); + reference_uuid = before->get_inner(); } } } @@ -752,7 +754,7 @@ bool BiboumiComponent::handle_mam_request(const Stanza& stanza) if ((limit == -1 && start.empty() && end.empty()) || limit > 100) limit = 101; - auto lines = Database::get_muc_logs(from.bare(), iid.get_local(), iid.get_server(), limit, start, end, reference_record_id, paging_order); + auto lines = Database::get_muc_logs(from.bare(), iid.get_local(), iid.get_server(), limit, start, end, reference_uuid, paging_order); bool complete = true; if (lines.size() > 100) { -- cgit v1.2.3