summaryrefslogtreecommitdiff
path: root/src/xmpp
diff options
context:
space:
mode:
authorlouiz’ <louiz@louiz.org>2018-01-30 09:07:21 +0100
committerlouiz’ <louiz@louiz.org>2018-01-30 09:07:21 +0100
commitcb831788942b49a28bd79fd62dbdc3d00f15b227 (patch)
tree9725df99c9294389d998910aa3243f469df3c6b4 /src/xmpp
parent17f2cb5c93e2c86f68cda97fed43fb617bd75ff1 (diff)
downloadbiboumi-cb831788942b49a28bd79fd62dbdc3d00f15b227.tar.gz
biboumi-cb831788942b49a28bd79fd62dbdc3d00f15b227.tar.bz2
biboumi-cb831788942b49a28bd79fd62dbdc3d00f15b227.tar.xz
biboumi-cb831788942b49a28bd79fd62dbdc3d00f15b227.zip
Add the complete='true' attribute only when appropriate
Diffstat (limited to 'src/xmpp')
-rw-r--r--src/xmpp/biboumi_component.cpp25
1 files changed, 19 insertions, 6 deletions
diff --git a/src/xmpp/biboumi_component.cpp b/src/xmpp/biboumi_component.cpp
index ee8a502..dd66aca 100644
--- a/src/xmpp/biboumi_component.cpp
+++ b/src/xmpp/biboumi_component.cpp
@@ -721,13 +721,25 @@ bool BiboumiComponent::handle_mam_request(const Stanza& stanza)
if (max)
limit = std::atoi(max->get_inner().data());
}
- // If the archive is really big, and the client didn’t specify any
- // limit, we avoid flooding it: we set an arbitrary max limit.
- if (limit == -1 && start.empty() && end.empty())
+ // Do 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;
+ log_debug("limit: ", limit);
+ auto lines = Database::get_muc_logs(from.bare(), iid.get_local(), iid.get_server(), limit, start, end);
+ bool complete = true;
+ if (lines.size() > 100)
{
- limit = 100;
+ log_debug("incomplete");
+ complete = false;
+ log_debug("size of lines before erase: ", lines.size());
+ lines.erase(lines.begin(), std::prev(lines.end(), 100));
+ log_debug("size of lines after erase: ", lines.size());
}
- const auto lines = Database::get_muc_logs(from.bare(), iid.get_local(), iid.get_server(), limit, start, end);
for (const Database::MucLogLine& line: lines)
{
if (!line.col<Database::Nick>().empty())
@@ -738,7 +750,8 @@ bool BiboumiComponent::handle_mam_request(const Stanza& stanza)
{
XmlNode& fin = *(fin_ptr.get());
fin["xmlns"] = MAM_NS;
- fin["complete"] = "true";
+ if (complete)
+ fin["complete"] = "true";
XmlSubNode set(fin, "set");
set["xmlns"] = RSM_NS;
if (!lines.empty())