Mercurial > prosody-modules
diff mod_pubsub_feed/mod_pubsub_feed.lua @ 455:52f2188ec47d
mod_default_vcard: Sets initial vCard from data enterd on registration
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Sat, 15 Oct 2011 13:43:37 +0200 |
parents | fe4fdba21a23 |
children | bbea8081c865 |
line wrap: on
line diff
--- a/mod_pubsub_feed/mod_pubsub_feed.lua Tue Oct 11 01:42:31 2011 +0100 +++ b/mod_pubsub_feed/mod_pubsub_feed.lua Sat Oct 15 13:43:37 2011 +0200 @@ -38,19 +38,33 @@ local urldecode = http.urldecode; local urlencode = http.urlencode; +local feed_list = {}; +local refresh_interval; + +-- Dynamicaly reloadable config. +local function update_config() local config = module:get_option("feeds") or { planet_jabber = "http://planet.jabber.org/atom.xml"; prosody_blog = "http://blog.prosody.im/feed/atom.xml"; }; -local refresh_interval = module:get_option_number("feed_pull_interval", 15) * 60; -local use_pubsubhubub = module:get_option_boolean("use_pubsubhubub", true); -- HTTP by default or not? -local httphost = module:get_option_string("pubsubhubub_httphost", module.host); -- If module.host IN A doesn't point to this server, use this to override. -local feed_list = { } + refresh_interval = module:get_option_number("feed_pull_interval", 15) * 60; + local new_feed_list; for node, url in pairs(config) do + local new_feed_list[node] = true; + if not feed_list[node] then feed_list[node] = { url = url; node = node; last_update = 0 }; + else + feed_list[node].url = url; end --- TODO module:hook("config-reloaded", above loop); --- Also, keeping it somewhere persistent in order to avoid duplicated publishes? + end + for node in pairs(feed_list) do + if not new_feed_list[node] then + feed_list[node] = nil; + end + end +end +update_config(); +module:hook("config-reloaded", update_config); -- Used to kill the timer local module_unloaded = false; @@ -58,6 +72,13 @@ module_unloaded = true; end +-- Config stuff that can't be reloaded, since it would need to re-bind HTTP stuff. + +-- If module.host IN A doesn't point to this server, use this to override. +local httphost = module:get_option_string("pubsubhubub_httphost", module.host); +-- HTTP by default or not? +local use_pubsubhubub = module:get_option_boolean("use_pubsubhubub", true); + -- Thanks to Maranda for this local port, base, ssl = 5280, "callback", false; local ports = module:get_option("feeds_ports") or { port = port, base = base, ssl = ssl }; @@ -169,12 +190,13 @@ end function refresh_feeds() + local now = time(); if module_unloaded then return end --module:log("debug", "Refreshing feeds"); for node, item in pairs(feed_list) do --FIXME Don't fetch feeds which have a subscription -- Otoho, what if the subscription expires or breaks? - if item.last_update + refresh_interval < time() then + if item.last_update + refresh_interval < now then module:log("debug", "checking %s", item.node); fetch(item, update_entry); end