Mercurial > prosody-modules
comparison mod_pubsub_feeds/mod_pubsub_feeds.lua @ 2383:18323c6aa133
mod_pubsub_feeds: Halt feed parsing when we see a node we already know about
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Sat, 19 Nov 2016 19:38:14 +0100 |
parents | f159ad7ac18a |
children | feba6439b6fb |
comparison
equal
deleted
inserted
replaced
2382:f159ad7ac18a | 2383:18323c6aa133 |
---|---|
81 local feed = parse_feed(item.data); | 81 local feed = parse_feed(item.data); |
82 local entries = {}; | 82 local entries = {}; |
83 for entry in feed:childtags("entry") do | 83 for entry in feed:childtags("entry") do |
84 table.insert(entries, entry); | 84 table.insert(entries, entry); |
85 end | 85 end |
86 local ok = pubsub.service:get_items(node, true); | 86 local ok, items = pubsub.service:get_items(node, true); |
87 if not ok then | 87 if not ok then |
88 local ok, err = pubsub.service:create(node, true); | 88 local ok, err = pubsub.service:create(node, true); |
89 if not ok then | 89 if not ok then |
90 module:log("error", "Could not create node %s: %s", node, err); | 90 module:log("error", "Could not create node %s: %s", node, err); |
91 return; | 91 return; |
92 end | 92 end |
93 items = {}; | |
93 end | 94 end |
94 for i = #entries, 1, -1 do -- Feeds are usually in reverse order | 95 for i = #entries, 1, -1 do -- Feeds are usually in reverse order |
95 local entry = entries[i]; | 96 local entry = entries[i]; |
96 entry.attr.xmlns = xmlns_atom; | 97 entry.attr.xmlns = xmlns_atom; |
97 | 98 |
109 id = link and link.attr.href; | 110 id = link and link.attr.href; |
110 end | 111 end |
111 if not id then | 112 if not id then |
112 -- Sigh, no link? | 113 -- Sigh, no link? |
113 id = feed.url .. "#" .. hmac_sha1(feed.url, tostring(entry), true) .. "@" .. dt_datetime(timestamp); | 114 id = feed.url .. "#" .. hmac_sha1(feed.url, tostring(entry), true) .. "@" .. dt_datetime(timestamp); |
115 end | |
116 if items[id] then | |
117 -- Assume that this existing means we've added all new items | |
118 break; | |
114 end | 119 end |
115 local xitem = st.stanza("item", { id = id }):add_child(entry); | 120 local xitem = st.stanza("item", { id = id }):add_child(entry); |
116 -- TODO Put data from /feed into item/source | 121 -- TODO Put data from /feed into item/source |
117 | 122 |
118 --module:log("debug", "publishing to %s, id %s", node, id); | 123 --module:log("debug", "publishing to %s, id %s", node, id); |