Changeset

1682:6b2122630b92

mod_mam: Support the mandatory 'complete' attribute by requesting one extra item from storage
author Kim Alvefur <zash@zash.se>
date Sun, 03 May 2015 13:21:15 +0200
parents 1681:d20cfc5ba827
children 1683:cc3fad4198bc
files mod_mam/mod_mam.lua
diffstat 1 files changed, 9 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/mod_mam/mod_mam.lua	Sun May 03 13:20:04 2015 +0200
+++ b/mod_mam/mod_mam.lua	Sun May 03 13:21:15 2015 +0200
@@ -124,7 +124,7 @@
 	local data, err = archive:find(origin.username, {
 		start = qstart; ["end"] = qend; -- Time range
 		with = qwith;
-		limit = qmax;
+		limit = qmax + 1;
 		before = before; after = after;
 		reverse = reverse;
 		total = true;
@@ -141,7 +141,14 @@
 
 	-- Wrap it in stuff and deliver
 	local fwd_st, first, last;
+	local count = 0;
+	local complete = "true";
 	for id, item, when in data do
+		count = count + 1;
+		if count > qmax then
+			complete = nil;
+			break;
+		end
 		fwd_st = st.message(msg_reply_attr)
 			:tag("result", { xmlns = xmlns_mam, queryid = qid, id = id })
 				:tag("forwarded", { xmlns = xmlns_forward })
@@ -163,7 +170,7 @@
 
 	if reverse then first, last = last, first; end
 	origin.send(st.message(msg_reply_attr)
-		:tag("fin", { xmlns = xmlns_mam, queryid = qid })
+		:tag("fin", { xmlns = xmlns_mam, queryid = qid, complete = complete })
 			:add_child(rsm.generate {
 				first = first, last = last, count = count }));
 	return true;