Comparison

plugins/mod_mam/mod_mam.lua @ 11280:e35e98541ca0

mod_mam: Allow querying by set of IDs
author Kim Alvefur <zash@zash.se>
date Tue, 12 Jan 2021 19:00:44 +0100
parent 11272:44c9cb4094bb
child 11281:142fb655b885
comparison
equal deleted inserted replaced
11279:f225070e2b8a 11280:e35e98541ca0
86 if archive.caps and archive.caps.full_id_range then 86 if archive.caps and archive.caps.full_id_range then
87 table.insert(query_form, { name = "before-id"; type = "text-single"; }); 87 table.insert(query_form, { name = "before-id"; type = "text-single"; });
88 table.insert(query_form, { name = "after-id"; type = "text-single"; }); 88 table.insert(query_form, { name = "after-id"; type = "text-single"; });
89 end 89 end
90 90
91 if archive.caps and archive.caps.ids then
92 table.insert(query_form, { name = "ids"; type = "list-multi"; });
93 end
94
95
91 -- Serve form 96 -- Serve form
92 module:hook("iq-get/self/"..xmlns_mam..":query", function(event) 97 module:hook("iq-get/self/"..xmlns_mam..":query", function(event)
93 local origin, stanza = event.origin, event.stanza; 98 local origin, stanza = event.origin, event.stanza;
94 get_prefs(origin.username, true); 99 get_prefs(origin.username, true);
95 origin.send(st.reply(stanza):query(xmlns_mam):add_child(query_form:form())); 100 origin.send(st.reply(stanza):query(xmlns_mam):add_child(query_form:form()));
105 origin.mam_requested = true; 110 origin.mam_requested = true;
106 111
107 get_prefs(origin.username, true); 112 get_prefs(origin.username, true);
108 113
109 -- Search query parameters 114 -- Search query parameters
110 local qwith, qstart, qend, qbefore, qafter; 115 local qwith, qstart, qend, qbefore, qafter, qids;
111 local form = query:get_child("x", "jabber:x:data"); 116 local form = query:get_child("x", "jabber:x:data");
112 if form then 117 if form then
113 local form_type, err = get_form_type(form); 118 local form_type, err = get_form_type(form);
114 if not form_type then 119 if not form_type then
115 origin.send(st.error_reply(stanza, "modify", "bad-request", "Invalid dataform: "..err)); 120 origin.send(st.error_reply(stanza, "modify", "bad-request", "Invalid dataform: "..err));
123 origin.send(st.error_reply(stanza, "modify", "bad-request", select(2, next(err)))); 128 origin.send(st.error_reply(stanza, "modify", "bad-request", select(2, next(err))));
124 return true; 129 return true;
125 end 130 end
126 qwith, qstart, qend = form["with"], form["start"], form["end"]; 131 qwith, qstart, qend = form["with"], form["start"], form["end"];
127 qbefore, qafter = form["before-id"], form["after-id"]; 132 qbefore, qafter = form["before-id"], form["after-id"];
133 qids = form["ids"];
128 qwith = qwith and jid_bare(qwith); -- dataforms does jidprep 134 qwith = qwith and jid_bare(qwith); -- dataforms does jidprep
129 end 135 end
130 136
131 if qstart or qend then -- Validate timestamps 137 if qstart or qend then -- Validate timestamps
132 local vstart, vend = (qstart and timestamp_parse(qstart)), (qend and timestamp_parse(qend)); 138 local vstart, vend = (qstart and timestamp_parse(qstart)), (qend and timestamp_parse(qend));
162 local data, err = archive:find(origin.username, { 168 local data, err = archive:find(origin.username, {
163 start = qstart; ["end"] = qend; -- Time range 169 start = qstart; ["end"] = qend; -- Time range
164 with = qwith; 170 with = qwith;
165 limit = qmax == 0 and 0 or qmax + 1; 171 limit = qmax == 0 and 0 or qmax + 1;
166 before = before; after = after; 172 before = before; after = after;
173 ids = qids;
167 reverse = reverse; 174 reverse = reverse;
168 total = use_total or qmax == 0; 175 total = use_total or qmax == 0;
169 }); 176 });
170 177
171 if not data then 178 if not data then
559 -- Stanzas to local clients 566 -- Stanzas to local clients
560 module:hook("message/bare", message_handler, 0); 567 module:hook("message/bare", message_handler, 0);
561 module:hook("message/full", message_handler, 0); 568 module:hook("message/full", message_handler, 0);
562 569
563 local advertise_extended = module:get_option_boolean("mam_advertise_extend", false); 570 local advertise_extended = module:get_option_boolean("mam_advertise_extend", false);
564 -- TODO ids
565 -- TODO delete feature flag option 571 -- TODO delete feature flag option
566 572
567 module:hook("account-disco-info", function(event) 573 module:hook("account-disco-info", function(event)
568 (event.reply or event.stanza):tag("feature", {var=xmlns_mam}):up(); 574 (event.reply or event.stanza):tag("feature", {var=xmlns_mam}):up();
569 if advertise_extended then 575 if advertise_extended then