comparison mod_pubsub_feeds/mod_pubsub_feeds.lua @ 2380:2f083426fe98

mod_pubsub_feeds: Use URL as ID if no id set. If that's not there either then hash stuff and call it a day
author Kim Alvefur <zash@zash.se>
date Sat, 19 Nov 2016 19:07:53 +0100
parents bc6e63ab2a7c
children a4614a329bdd
comparison
equal deleted inserted replaced
2379:bc6e63ab2a7c 2380:2f083426fe98
94 94
95 local timestamp = e_updated or e_published or nil; 95 local timestamp = e_updated or e_published or nil;
96 --module:log("debug", "timestamp is %s, item.last_update is %s", tostring(timestamp), tostring(item.last_update)); 96 --module:log("debug", "timestamp is %s, item.last_update is %s", tostring(timestamp), tostring(item.last_update));
97 if not timestamp or not item.last_update or timestamp > item.last_update then 97 if not timestamp or not item.last_update or timestamp > item.last_update then
98 local id = entry:get_child_text("id"); 98 local id = entry:get_child_text("id");
99 id = id or item.url.."#"..dt_datetime(timestamp); -- Missing id, so make one up 99 if not id then
100 local link = entry:get_child("link");
101 id = link and link.attr.href;
102 end
103 if not id then
104 -- Sigh, no link?
105 id = feed.url .. "#" .. hmac_sha1(feed.url, tostring(entry), true) .. "@" .. dt_datetime(timestamp);
106 end
100 local xitem = st.stanza("item", { id = id }):add_child(entry); 107 local xitem = st.stanza("item", { id = id }):add_child(entry);
101 -- TODO Put data from /feed into item/source 108 -- TODO Put data from /feed into item/source
102 109
103 --module:log("debug", "publishing to %s, id %s", node, id); 110 --module:log("debug", "publishing to %s, id %s", node, id);
104 local ok, err = pubsub.service:publish(node, true, id, xitem); 111 local ok, err = pubsub.service:publish(node, true, id, xitem);