comparison mod_pubsub_feeds/mod_pubsub_feeds.lua @ 762:0a06cf46c263

mod_pubsub_feeds: Use the "superactor" instead of module.host/module.name
author Kim Alvefur <zash@zash.se>
date Wed, 01 Aug 2012 16:08:15 +0200
parents a37e4149ccd1
children bcf0c9fff512
comparison
equal deleted inserted replaced
761:48f8b312a509 762:0a06cf46c263
69 end 69 end
70 end 70 end
71 update_config(); 71 update_config();
72 module:hook_global("config-reloaded", update_config); 72 module:hook_global("config-reloaded", update_config);
73 73
74 local actor = module.host.."/"..module.name;
75
76 function update_entry(item) 74 function update_entry(item)
77 local node = item.node; 75 local node = item.node;
78 module:log("debug", "parsing %d bytes of data in node %s", #item.data or 0, node) 76 module:log("debug", "parsing %d bytes of data in node %s", #item.data or 0, node)
79 local feed = parse_feed(item.data); 77 local feed = parse_feed(item.data);
80 for _, entry in ipairs(feed) do 78 for _, entry in ipairs(feed) do
92 id = id or item.url.."#"..dt_datetime(timestamp); -- Missing id, so make one up 90 id = id or item.url.."#"..dt_datetime(timestamp); -- Missing id, so make one up
93 local xitem = st.stanza("item", { id = id }):add_child(entry); 91 local xitem = st.stanza("item", { id = id }):add_child(entry);
94 -- TODO Put data from /feed into item/source 92 -- TODO Put data from /feed into item/source
95 93
96 --module:log("debug", "publishing to %s, id %s", node, id); 94 --module:log("debug", "publishing to %s, id %s", node, id);
97 local ok, err = modules.pubsub.service:publish(node, actor, id, xitem); 95 local ok, err = modules.pubsub.service:publish(node, true, id, xitem);
98 if not ok then 96 if not ok then
99 if err == "item-not-found" then -- try again 97 if err == "item-not-found" then -- try again
100 --module:log("debug", "got item-not-found, creating %s and trying again", node); 98 --module:log("debug", "got item-not-found, creating %s and trying again", node);
101 local ok, err = modules.pubsub.service:create(node, actor); 99 local ok, err = modules.pubsub.service:create(node, true);
102 if not ok then 100 if not ok then
103 module:log("error", "could not create node %s: %s", node, err); 101 module:log("error", "could not create node %s: %s", node, err);
104 return; 102 return;
105 end 103 end
106 local ok, err = modules.pubsub.service:publish(node, actor, id, xitem); 104 local ok, err = modules.pubsub.service:publish(node, true, id, xitem);
107 if not ok then 105 if not ok then
108 module:log("error", "could not create or publish node %s: %s", node, err); 106 module:log("error", "could not create or publish node %s: %s", node, err);
109 return 107 return
110 end 108 end
111 else 109 else