diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/database/database.cpp | 16 | ||||
-rw-r--r-- | src/database/database.hpp | 2 | ||||
-rw-r--r-- | src/xmpp/biboumi_component.cpp | 17 |
3 files changed, 26 insertions, 9 deletions
diff --git a/src/database/database.cpp b/src/database/database.cpp index 2a63a6b..b2413d0 100644 --- a/src/database/database.cpp +++ b/src/database/database.cpp @@ -165,7 +165,7 @@ 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, Database::Paging paging) + int limit, const std::string& start, const std::string& end, const Id::real_type reference_record_id, Database::Paging paging) { if (limit == 0) return {}; @@ -187,15 +187,21 @@ std::vector<Database::MucLogLine> Database::get_muc_logs(const std::string& owne if (end_time != -1) request << " and " << Database::Date{} << "<=" << end_time; } - if (after_id != Id::unset_value) + if (reference_record_id != Id::unset_value) { - request << " and " << Id{} << ">" << after_id; + request << " and " << Id{}; + if (paging == Database::Paging::first) + request << ">"; + else + request << "<"; + request << reference_record_id; } + request.order_by() << Id{}; if (paging == Database::Paging::first) - request.order_by() << Id{} << " ASC "; + request << " ASC "; else - request.order_by() << Id{} << " DESC "; + request << " DESC "; if (limit >= 0) request.limit() << limit; diff --git a/src/database/database.hpp b/src/database/database.hpp index 9c483f4..ce7595b 100644 --- a/src/database/database.hpp +++ b/src/database/database.hpp @@ -126,7 +126,7 @@ 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, Paging=Paging::first); + const Id::real_type reference_record_id=Id::unset_value, 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 75a55e6..fe6cc1b 100644 --- a/src/xmpp/biboumi_component.cpp +++ b/src/xmpp/biboumi_component.cpp @@ -720,7 +720,8 @@ bool BiboumiComponent::handle_mam_request(const Stanza& stanza) } const XmlNode* set = query->get_child("set", RSM_NS); int limit = -1; - Id::real_type after_id{Id::unset_value}; + Id::real_type reference_record_id{Id::unset_value}; + Database::Paging paging_order{Database::Paging::first}; if (set) { const XmlNode* max = set->get_child("max", RSM_NS); @@ -731,7 +732,17 @@ bool BiboumiComponent::handle_mam_request(const Stanza& stanza) { auto after_record = Database::get_muc_log(from.bare(), iid.get_local(), iid.get_server(), after->get_inner(), start, end); - after_id = after_record.col<Id>(); + reference_record_id = after_record.col<Id>(); + } + const XmlNode* before = set->get_child("before", RSM_NS); + if (before) + { + 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<Id>(); + } } } // Do not send more than 100 messages, even if the client asked for more, @@ -742,7 +753,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, after_id); + auto lines = Database::get_muc_logs(from.bare(), iid.get_local(), iid.get_server(), limit, start, end, reference_record_id, paging_order); bool complete = true; if (lines.size() > 100) { |