Mercurial > prosody-hg
comparison plugins/adhoc/adhoc.lib.lua @ 4858:33458e1d84c8
Backed out changeset 52b6901cabb0 (to be replaced)
| author | Matthew Wild <mwild1@gmail.com> |
|---|---|
| date | Fri, 11 May 2012 21:35:02 +0100 |
| parents | 52b6901cabb0 |
| children | b66e73793cb7 |
comparison
equal
deleted
inserted
replaced
| 4632:52b6901cabb0 | 4858:33458e1d84c8 |
|---|---|
| 23 function _M.new(name, node, handler, permission) | 23 function _M.new(name, node, handler, permission) |
| 24 return { name = name, node = node, handler = handler, cmdtag = _cmdtag, permission = (permission or "user") }; | 24 return { name = name, node = node, handler = handler, cmdtag = _cmdtag, permission = (permission or "user") }; |
| 25 end | 25 end |
| 26 | 26 |
| 27 function _M.handle_cmd(command, origin, stanza) | 27 function _M.handle_cmd(command, origin, stanza) |
| 28 local cmdtag, actions; | |
| 29 local sessionid = stanza.tags[1].attr.sessionid or uuid.generate(); | 28 local sessionid = stanza.tags[1].attr.sessionid or uuid.generate(); |
| 30 local dataIn = {}; | 29 local dataIn = {}; |
| 31 dataIn.to = stanza.attr.to; | 30 dataIn.to = stanza.attr.to; |
| 32 dataIn.from = stanza.attr.from; | 31 dataIn.from = stanza.attr.from; |
| 33 dataIn.action = stanza.tags[1].attr.action or "execute"; | 32 dataIn.action = stanza.tags[1].attr.action or "execute"; |
| 57 elseif name == "warn" then | 56 elseif name == "warn" then |
| 58 cmdtag:tag("note", {type="warn"}):text(content):up(); | 57 cmdtag:tag("note", {type="warn"}):text(content):up(); |
| 59 elseif name == "error" then | 58 elseif name == "error" then |
| 60 cmdtag:tag("note", {type="error"}):text(content.message):up(); | 59 cmdtag:tag("note", {type="error"}):text(content.message):up(); |
| 61 elseif name =="actions" then | 60 elseif name =="actions" then |
| 62 actions = st.stanza("actions"); | 61 local actions = st.stanza("actions"); |
| 63 for _, action in ipairs(content) do | 62 for _, action in ipairs(content) do |
| 64 if (action == "prev") or (action == "next") or (action == "complete") then | 63 if (action == "prev") or (action == "next") or (action == "complete") then |
| 65 actions:tag(action):up(); | 64 actions:tag(action):up(); |
| 66 else | 65 else |
| 67 module:log("error", 'Command "'..command.name.. | 66 module:log("error", 'Command "'..command.name.. |
| 68 '" at node "'..command.node..'" provided an invalid action "'..action..'"'); | 67 '" at node "'..command.node..'" provided an invalid action "'..action..'"'); |
| 69 end | 68 end |
| 70 end | 69 end |
| 70 cmdtag:add_child(actions); | |
| 71 elseif name == "form" then | 71 elseif name == "form" then |
| 72 cmdtag:add_child((content.layout or content):form(content.values)); | 72 cmdtag:add_child((content.layout or content):form(content.values)); |
| 73 elseif name == "result" then | 73 elseif name == "result" then |
| 74 cmdtag:add_child((content.layout or content):form(content.values, "result")); | 74 cmdtag:add_child((content.layout or content):form(content.values, "result")); |
| 75 elseif name == "other" then | 75 elseif name == "other" then |
| 76 cmdtag:add_child(content); | 76 cmdtag:add_child(content); |
| 77 end | 77 end |
| 78 end | 78 end |
| 79 | |
| 80 if not actions then | |
| 81 actions = st.stanza("actions"); | |
| 82 actions:tag("complete"):up(); | |
| 83 end | |
| 84 cmdtag:add_child(actions); | |
| 85 | |
| 86 stanza:add_child(cmdtag); | 79 stanza:add_child(cmdtag); |
| 87 origin.send(stanza); | 80 origin.send(stanza); |
| 88 | 81 |
| 89 return true; | 82 return true; |
| 90 end | 83 end |
