Software /
code /
prosody-modules
Comparison
mod_mam/mod_mam.lua @ 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 |
parent | 1681:d20cfc5ba827 |
child | 1683:cc3fad4198bc |
comparison
equal
deleted
inserted
replaced
1681:d20cfc5ba827 | 1682:6b2122630b92 |
---|---|
122 | 122 |
123 -- Load all the data! | 123 -- Load all the data! |
124 local data, err = archive:find(origin.username, { | 124 local data, err = archive:find(origin.username, { |
125 start = qstart; ["end"] = qend; -- Time range | 125 start = qstart; ["end"] = qend; -- Time range |
126 with = qwith; | 126 with = qwith; |
127 limit = qmax; | 127 limit = qmax + 1; |
128 before = before; after = after; | 128 before = before; after = after; |
129 reverse = reverse; | 129 reverse = reverse; |
130 total = true; | 130 total = true; |
131 }); | 131 }); |
132 | 132 |
139 origin.send(st.reply(stanza)) | 139 origin.send(st.reply(stanza)) |
140 local msg_reply_attr = { to = stanza.attr.from, from = stanza.attr.to }; | 140 local msg_reply_attr = { to = stanza.attr.from, from = stanza.attr.to }; |
141 | 141 |
142 -- Wrap it in stuff and deliver | 142 -- Wrap it in stuff and deliver |
143 local fwd_st, first, last; | 143 local fwd_st, first, last; |
144 local count = 0; | |
145 local complete = "true"; | |
144 for id, item, when in data do | 146 for id, item, when in data do |
147 count = count + 1; | |
148 if count > qmax then | |
149 complete = nil; | |
150 break; | |
151 end | |
145 fwd_st = st.message(msg_reply_attr) | 152 fwd_st = st.message(msg_reply_attr) |
146 :tag("result", { xmlns = xmlns_mam, queryid = qid, id = id }) | 153 :tag("result", { xmlns = xmlns_mam, queryid = qid, id = id }) |
147 :tag("forwarded", { xmlns = xmlns_forward }) | 154 :tag("forwarded", { xmlns = xmlns_forward }) |
148 :tag("delay", { xmlns = xmlns_delay, stamp = timestamp(when) }):up(); | 155 :tag("delay", { xmlns = xmlns_delay, stamp = timestamp(when) }):up(); |
149 | 156 |
161 -- That's all folks! | 168 -- That's all folks! |
162 module:log("debug", "Archive query %s completed", tostring(qid)); | 169 module:log("debug", "Archive query %s completed", tostring(qid)); |
163 | 170 |
164 if reverse then first, last = last, first; end | 171 if reverse then first, last = last, first; end |
165 origin.send(st.message(msg_reply_attr) | 172 origin.send(st.message(msg_reply_attr) |
166 :tag("fin", { xmlns = xmlns_mam, queryid = qid }) | 173 :tag("fin", { xmlns = xmlns_mam, queryid = qid, complete = complete }) |
167 :add_child(rsm.generate { | 174 :add_child(rsm.generate { |
168 first = first, last = last, count = count })); | 175 first = first, last = last, count = count })); |
169 return true; | 176 return true; |
170 end); | 177 end); |
171 | 178 |