From b0168fd45b3683c2d6f61ccae67dcd5b918a363d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?louiz=E2=80=99?= Date: Sun, 29 Apr 2018 22:18:26 +0200 Subject: =?UTF-8?q?mam:=20Send=20=E2=80=9Cfin=20complete=E2=80=9D=20only?= =?UTF-8?q?=20when=20appropriate?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Also simplify how we did the whole “limit + 1” And fix one bad interpretation of the XEP for the case where the query has no after or before restriction. fix #3349 --- src/xmpp/biboumi_component.cpp | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) (limited to 'src/xmpp/biboumi_component.cpp') diff --git a/src/xmpp/biboumi_component.cpp b/src/xmpp/biboumi_component.cpp index 6dc5fc5..dbaf8a4 100644 --- a/src/xmpp/biboumi_component.cpp +++ b/src/xmpp/biboumi_component.cpp @@ -743,19 +743,15 @@ bool BiboumiComponent::handle_mam_request(const Stanza& stanza) } // Do not send more than 100 messages, even if the client asked for more, // or if it didn’t specify any limit. - // 101 is just a trick to know if there are more available messages. - // If our query returns 101 message, we know it’s incomplete, but we - // still send only 100 - 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); - bool complete = true; - if (lines.size() > 100) - { - complete = false; - lines.erase(lines.begin(), std::prev(lines.end(), 100)); - } + if (limit < 0 || limit > 100) + limit = 100; + auto result = Database::get_muc_logs(from.bare(), iid.get_local(), iid.get_server(), + limit, + start, end, + reference_record_id, paging_order); + bool complete = std::get(result); + auto& lines = std::get<1>(result); + for (const Database::MucLogLine& line: lines) { if (!line.col().empty()) -- cgit v1.2.3