Software / code / verse
Comparison
plugins/pubsub.lua @ 283:39ce7535887c
plugins.pubsub: Add a local variable to save some table lookups
| author | Kim Alvefur <zash@zash.se> |
|---|---|
| date | Mon, 05 Mar 2012 20:18:54 +0100 |
| parent | 272:e1833e9bd25b |
| child | 332:6ecf44918156 |
comparison
equal
deleted
inserted
replaced
| 282:52b971d9ebc3 | 283:39ce7535887c |
|---|---|
| 12 local pubsub_mt = { __index = pubsub }; | 12 local pubsub_mt = { __index = pubsub }; |
| 13 | 13 |
| 14 function verse.plugins.pubsub(stream) | 14 function verse.plugins.pubsub(stream) |
| 15 stream.pubsub = setmetatable({ stream = stream }, pubsub_mt); | 15 stream.pubsub = setmetatable({ stream = stream }, pubsub_mt); |
| 16 stream:hook("message", function (message) | 16 stream:hook("message", function (message) |
| 17 local m_from = message.attr.from; | |
| 17 for pubsub_event in message:childtags("event", xmlns_pubsub_event) do | 18 for pubsub_event in message:childtags("event", xmlns_pubsub_event) do |
| 18 local items = pubsub_event:get_child("items"); | 19 local items = pubsub_event:get_child("items"); |
| 19 if items then | 20 if items then |
| 20 local node = items.attr.node; | 21 local node = items.attr.node; |
| 21 for item in items:childtags("item") do | 22 for item in items:childtags("item") do |
| 22 stream:event("pubsub/event", { | 23 stream:event("pubsub/event", { |
| 23 from = message.attr.from; | 24 from = m_from; |
| 24 node = node; | 25 node = node; |
| 25 item = item; | 26 item = item; |
| 26 }); | 27 }); |
| 27 end | 28 end |
| 28 end | 29 end |
| 163 | 164 |
| 164 -- <configure/> and <default/> rolled into one | 165 -- <configure/> and <default/> rolled into one |
| 165 function pubsub_node:configure(config, callback) | 166 function pubsub_node:configure(config, callback) |
| 166 if config ~= nil then | 167 if config ~= nil then |
| 167 error("Not implemented yet."); | 168 error("Not implemented yet."); |
| 168 -- if config == true then | 169 --[[ |
| 170 if config == true then | |
| 171 self.stream:send_iq(pubsub_iq("get", self.service, nil, "configure", self.node) | |
| 172 , function(reply) | |
| 173 local form = reply:get_child("pubsub"):get_child("configure"):get_cild("x"); | |
| 174 local config = callback(require"util.dataforms".something(form)) | |
| 175 self.stream:send_iq(pubsub_iq("set", config, ...)) | |
| 176 end); | |
| 177 end | |
| 178 --]] | |
| 169 -- fetch form and pass it to the callback | 179 -- fetch form and pass it to the callback |
| 170 -- which would process it and pass it back | 180 -- which would process it and pass it back |
| 171 -- and then we submit it | 181 -- and then we submit it |
| 172 -- elseif type(config) == "table" then | 182 -- elseif type(config) == "table" then |
| 173 -- it's a form or stanza that we submit | 183 -- it's a form or stanza that we submit |