annotate mod_map/mod_map.lua @ 3514:8811b7dbe6e2

mod_pubsub_github: Add support for specifying an actor with less privileges
author Kim Alvefur <zash@zash.se>
date Sun, 31 Mar 2019 17:59:17 +0200
parents 262e68821f3f
children 30743ae1fe1a
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3496
262e68821f3f mod_map: Experimental module exposing MAM summary
Kim Alvefur <zash@zash.se>
parents:
diff changeset
1
262e68821f3f mod_map: Experimental module exposing MAM summary
Kim Alvefur <zash@zash.se>
parents:
diff changeset
2 local st = require "util.stanza";
262e68821f3f mod_map: Experimental module exposing MAM summary
Kim Alvefur <zash@zash.se>
parents:
diff changeset
3 local jid_bare = require "util.jid".bare;
262e68821f3f mod_map: Experimental module exposing MAM summary
Kim Alvefur <zash@zash.se>
parents:
diff changeset
4 local rsm = require "util.rsm";
262e68821f3f mod_map: Experimental module exposing MAM summary
Kim Alvefur <zash@zash.se>
parents:
diff changeset
5 local dataform = require "util.dataforms".new;
262e68821f3f mod_map: Experimental module exposing MAM summary
Kim Alvefur <zash@zash.se>
parents:
diff changeset
6
262e68821f3f mod_map: Experimental module exposing MAM summary
Kim Alvefur <zash@zash.se>
parents:
diff changeset
7 local archive = module:open_store("archive", "archive");
262e68821f3f mod_map: Experimental module exposing MAM summary
Kim Alvefur <zash@zash.se>
parents:
diff changeset
8
262e68821f3f mod_map: Experimental module exposing MAM summary
Kim Alvefur <zash@zash.se>
parents:
diff changeset
9 local query_form = dataform {
262e68821f3f mod_map: Experimental module exposing MAM summary
Kim Alvefur <zash@zash.se>
parents:
diff changeset
10 { name = "with"; type = "jid-single"; };
262e68821f3f mod_map: Experimental module exposing MAM summary
Kim Alvefur <zash@zash.se>
parents:
diff changeset
11 { name = "start"; type = "text-single" };
262e68821f3f mod_map: Experimental module exposing MAM summary
Kim Alvefur <zash@zash.se>
parents:
diff changeset
12 { name = "end"; type = "text-single"; };
262e68821f3f mod_map: Experimental module exposing MAM summary
Kim Alvefur <zash@zash.se>
parents:
diff changeset
13 };
262e68821f3f mod_map: Experimental module exposing MAM summary
Kim Alvefur <zash@zash.se>
parents:
diff changeset
14
262e68821f3f mod_map: Experimental module exposing MAM summary
Kim Alvefur <zash@zash.se>
parents:
diff changeset
15 if not archive.summary then
262e68821f3f mod_map: Experimental module exposing MAM summary
Kim Alvefur <zash@zash.se>
parents:
diff changeset
16 module:log("error", "The archive:summary() API is not supported by %s", archive._provided_by);
262e68821f3f mod_map: Experimental module exposing MAM summary
Kim Alvefur <zash@zash.se>
parents:
diff changeset
17 return
262e68821f3f mod_map: Experimental module exposing MAM summary
Kim Alvefur <zash@zash.se>
parents:
diff changeset
18 end
262e68821f3f mod_map: Experimental module exposing MAM summary
Kim Alvefur <zash@zash.se>
parents:
diff changeset
19
262e68821f3f mod_map: Experimental module exposing MAM summary
Kim Alvefur <zash@zash.se>
parents:
diff changeset
20 module:hook("iq-get/self/xmpp:prosody.im/mod_map:summary", function(event)
262e68821f3f mod_map: Experimental module exposing MAM summary
Kim Alvefur <zash@zash.se>
parents:
diff changeset
21 local origin, stanza = event.origin, event.stanza;
262e68821f3f mod_map: Experimental module exposing MAM summary
Kim Alvefur <zash@zash.se>
parents:
diff changeset
22
262e68821f3f mod_map: Experimental module exposing MAM summary
Kim Alvefur <zash@zash.se>
parents:
diff changeset
23 local query = stanza.tags[1];
262e68821f3f mod_map: Experimental module exposing MAM summary
Kim Alvefur <zash@zash.se>
parents:
diff changeset
24
262e68821f3f mod_map: Experimental module exposing MAM summary
Kim Alvefur <zash@zash.se>
parents:
diff changeset
25 -- Search query parameters
262e68821f3f mod_map: Experimental module exposing MAM summary
Kim Alvefur <zash@zash.se>
parents:
diff changeset
26 local qwith, qstart, qend;
262e68821f3f mod_map: Experimental module exposing MAM summary
Kim Alvefur <zash@zash.se>
parents:
diff changeset
27 local form = query:get_child("x", "jabber:x:data");
262e68821f3f mod_map: Experimental module exposing MAM summary
Kim Alvefur <zash@zash.se>
parents:
diff changeset
28 if form then
262e68821f3f mod_map: Experimental module exposing MAM summary
Kim Alvefur <zash@zash.se>
parents:
diff changeset
29 local err;
262e68821f3f mod_map: Experimental module exposing MAM summary
Kim Alvefur <zash@zash.se>
parents:
diff changeset
30 form, err = query_form:data(form);
262e68821f3f mod_map: Experimental module exposing MAM summary
Kim Alvefur <zash@zash.se>
parents:
diff changeset
31 if err then
262e68821f3f mod_map: Experimental module exposing MAM summary
Kim Alvefur <zash@zash.se>
parents:
diff changeset
32 origin.send(st.error_reply(stanza, "modify", "bad-request", select(2, next(err))));
262e68821f3f mod_map: Experimental module exposing MAM summary
Kim Alvefur <zash@zash.se>
parents:
diff changeset
33 return true;
262e68821f3f mod_map: Experimental module exposing MAM summary
Kim Alvefur <zash@zash.se>
parents:
diff changeset
34 end
262e68821f3f mod_map: Experimental module exposing MAM summary
Kim Alvefur <zash@zash.se>
parents:
diff changeset
35 qwith, qstart, qend = form["with"], form["start"], form["end"];
262e68821f3f mod_map: Experimental module exposing MAM summary
Kim Alvefur <zash@zash.se>
parents:
diff changeset
36 qwith = qwith and jid_bare(qwith); -- dataforms does jidprep
262e68821f3f mod_map: Experimental module exposing MAM summary
Kim Alvefur <zash@zash.se>
parents:
diff changeset
37 end
262e68821f3f mod_map: Experimental module exposing MAM summary
Kim Alvefur <zash@zash.se>
parents:
diff changeset
38
262e68821f3f mod_map: Experimental module exposing MAM summary
Kim Alvefur <zash@zash.se>
parents:
diff changeset
39 local qset = rsm.get(query);
262e68821f3f mod_map: Experimental module exposing MAM summary
Kim Alvefur <zash@zash.se>
parents:
diff changeset
40 local qmax = qset and qset.max;
262e68821f3f mod_map: Experimental module exposing MAM summary
Kim Alvefur <zash@zash.se>
parents:
diff changeset
41 local before, after = qset and qset.before, qset and qset.after;
262e68821f3f mod_map: Experimental module exposing MAM summary
Kim Alvefur <zash@zash.se>
parents:
diff changeset
42 if type(before) ~= "string" then before = nil; end
262e68821f3f mod_map: Experimental module exposing MAM summary
Kim Alvefur <zash@zash.se>
parents:
diff changeset
43
262e68821f3f mod_map: Experimental module exposing MAM summary
Kim Alvefur <zash@zash.se>
parents:
diff changeset
44 local summary = archive:summary(origin.username, {
262e68821f3f mod_map: Experimental module exposing MAM summary
Kim Alvefur <zash@zash.se>
parents:
diff changeset
45 start = qstart; ["end"] = qend; -- Time range
262e68821f3f mod_map: Experimental module exposing MAM summary
Kim Alvefur <zash@zash.se>
parents:
diff changeset
46 with = qwith;
262e68821f3f mod_map: Experimental module exposing MAM summary
Kim Alvefur <zash@zash.se>
parents:
diff changeset
47 limit = qmax;
262e68821f3f mod_map: Experimental module exposing MAM summary
Kim Alvefur <zash@zash.se>
parents:
diff changeset
48 before = before; after = after;
262e68821f3f mod_map: Experimental module exposing MAM summary
Kim Alvefur <zash@zash.se>
parents:
diff changeset
49 });
262e68821f3f mod_map: Experimental module exposing MAM summary
Kim Alvefur <zash@zash.se>
parents:
diff changeset
50 if not summary then
262e68821f3f mod_map: Experimental module exposing MAM summary
Kim Alvefur <zash@zash.se>
parents:
diff changeset
51 module:send(st.error_reply(stanza, "wait", "internal-server-error"));
262e68821f3f mod_map: Experimental module exposing MAM summary
Kim Alvefur <zash@zash.se>
parents:
diff changeset
52 return true;
262e68821f3f mod_map: Experimental module exposing MAM summary
Kim Alvefur <zash@zash.se>
parents:
diff changeset
53 end
262e68821f3f mod_map: Experimental module exposing MAM summary
Kim Alvefur <zash@zash.se>
parents:
diff changeset
54
262e68821f3f mod_map: Experimental module exposing MAM summary
Kim Alvefur <zash@zash.se>
parents:
diff changeset
55 local reply = st.reply(stanza);
262e68821f3f mod_map: Experimental module exposing MAM summary
Kim Alvefur <zash@zash.se>
parents:
diff changeset
56 reply:tag("summary", { xmlns = "xmpp:prosody.im/mod_map" });
262e68821f3f mod_map: Experimental module exposing MAM summary
Kim Alvefur <zash@zash.se>
parents:
diff changeset
57 for jid, count in pairs(summary) do
262e68821f3f mod_map: Experimental module exposing MAM summary
Kim Alvefur <zash@zash.se>
parents:
diff changeset
58 reply:tag("item", { jid = jid });
262e68821f3f mod_map: Experimental module exposing MAM summary
Kim Alvefur <zash@zash.se>
parents:
diff changeset
59 if type(count) == "number" then
262e68821f3f mod_map: Experimental module exposing MAM summary
Kim Alvefur <zash@zash.se>
parents:
diff changeset
60 reply:text_tag("count", ("%d"):format(count));
262e68821f3f mod_map: Experimental module exposing MAM summary
Kim Alvefur <zash@zash.se>
parents:
diff changeset
61 end
262e68821f3f mod_map: Experimental module exposing MAM summary
Kim Alvefur <zash@zash.se>
parents:
diff changeset
62 reply:up();
262e68821f3f mod_map: Experimental module exposing MAM summary
Kim Alvefur <zash@zash.se>
parents:
diff changeset
63 end
262e68821f3f mod_map: Experimental module exposing MAM summary
Kim Alvefur <zash@zash.se>
parents:
diff changeset
64
262e68821f3f mod_map: Experimental module exposing MAM summary
Kim Alvefur <zash@zash.se>
parents:
diff changeset
65 module:send(reply);
262e68821f3f mod_map: Experimental module exposing MAM summary
Kim Alvefur <zash@zash.se>
parents:
diff changeset
66 return true;
262e68821f3f mod_map: Experimental module exposing MAM summary
Kim Alvefur <zash@zash.se>
parents:
diff changeset
67 end);