Software /
code /
prosody-modules
Comparison
mod_atom/mod_atom.lua @ 3423:4a8fa0364f35
mod_atom: Unpack event object
Improves readability and reduces table indexing.
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Thu, 03 Jan 2019 11:36:01 +0100 |
parent | 3276:cb4b26221cf6 |
child | 3424:6ae875c98daf |
comparison
equal
deleted
inserted
replaced
3422:ba3c79ef2253 | 3423:4a8fa0364f35 |
---|---|
8 | 8 |
9 module:depends("http") | 9 module:depends("http") |
10 module:provides("http", { | 10 module:provides("http", { |
11 route = { | 11 route = { |
12 ["GET /*"] = function (event, user) | 12 ["GET /*"] = function (event, user) |
13 local actor = event.request.ip; | 13 local request, response = event.request, event.response; |
14 local actor = request.ip; | |
14 | 15 |
15 user = nodeprep(user); | 16 user = nodeprep(user); |
16 if not user then return 400; end | 17 if not user then return 400; end |
17 | 18 |
18 local pubsub_service = mod_pep.get_pep_service(user); | 19 local pubsub_service = mod_pep.get_pep_service(user); |
19 local ok, items = pubsub_service:get_items("urn:xmpp:microblog:0", actor); | 20 local ok, items = pubsub_service:get_items("urn:xmpp:microblog:0", actor); |
20 if ok then | 21 if ok then |
21 event.response.headers.content_type = "application/atom+xml"; | 22 response.headers.content_type = "application/xml"; |
22 local feed = st.stanza("feed", { xmlns = "http://www.w3.org/2005/Atom" }) | 23 local feed = st.stanza("feed", { xmlns = "http://www.w3.org/2005/Atom" }) |
23 :text_tag("generator", "Prosody", { uri = "xmpp:prosody.im", version = prosody.version }) | 24 :text_tag("generator", "Prosody", { uri = "xmpp:prosody.im", version = prosody.version }) |
24 :text_tag("title", pubsub_service.nodes["urn:xmpp:microblog:0"].config.title or "Microblog feed") | 25 :text_tag("title", pubsub_service.nodes["urn:xmpp:microblog:0"].config.title or "Microblog feed") |
25 :text_tag("subtitle", pubsub_service.nodes["urn:xmpp:microblog:0"].config.description) | 26 :text_tag("subtitle", pubsub_service.nodes["urn:xmpp:microblog:0"].config.description) |
26 :tag("author") | 27 :tag("author") |
34 feed:reset(); | 35 feed:reset(); |
35 | 36 |
36 for i = #items, 1, -1 do | 37 for i = #items, 1, -1 do |
37 feed:add_direct_child(items[items[i]].tags[1]); | 38 feed:add_direct_child(items[items[i]].tags[1]); |
38 end | 39 end |
39 event.response.headers.content_type = "application/atom+xml"; | |
40 return tostring(feed); | 40 return tostring(feed); |
41 elseif items == "forbidden" then | 41 elseif items == "forbidden" then |
42 return 403; | 42 return 403; |
43 elseif items == "item-not-found" then | 43 elseif items == "item-not-found" then |
44 return 404; | 44 return 404; |