Software / code / prosody
Comparison
plugins/adhoc/adhoc.lib.lua @ 4632:52b6901cabb0
mod_adhoc: Always allow at least the "complete" action
| author | Florian Zeitz <florob@babelmonkeys.de> |
|---|---|
| date | Fri, 13 Apr 2012 00:39:00 +0200 |
| parent | 3540:bc139431830b |
| child | 4858:33458e1d84c8 |
comparison
equal
deleted
inserted
replaced
| 4631:fc5d3b053454 | 4632:52b6901cabb0 |
|---|---|
| 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; | |
| 28 local sessionid = stanza.tags[1].attr.sessionid or uuid.generate(); | 29 local sessionid = stanza.tags[1].attr.sessionid or uuid.generate(); |
| 29 local dataIn = {}; | 30 local dataIn = {}; |
| 30 dataIn.to = stanza.attr.to; | 31 dataIn.to = stanza.attr.to; |
| 31 dataIn.from = stanza.attr.from; | 32 dataIn.from = stanza.attr.from; |
| 32 dataIn.action = stanza.tags[1].attr.action or "execute"; | 33 dataIn.action = stanza.tags[1].attr.action or "execute"; |
| 56 elseif name == "warn" then | 57 elseif name == "warn" then |
| 57 cmdtag:tag("note", {type="warn"}):text(content):up(); | 58 cmdtag:tag("note", {type="warn"}):text(content):up(); |
| 58 elseif name == "error" then | 59 elseif name == "error" then |
| 59 cmdtag:tag("note", {type="error"}):text(content.message):up(); | 60 cmdtag:tag("note", {type="error"}):text(content.message):up(); |
| 60 elseif name =="actions" then | 61 elseif name =="actions" then |
| 61 local actions = st.stanza("actions"); | 62 actions = st.stanza("actions"); |
| 62 for _, action in ipairs(content) do | 63 for _, action in ipairs(content) do |
| 63 if (action == "prev") or (action == "next") or (action == "complete") then | 64 if (action == "prev") or (action == "next") or (action == "complete") then |
| 64 actions:tag(action):up(); | 65 actions:tag(action):up(); |
| 65 else | 66 else |
| 66 module:log("error", 'Command "'..command.name.. | 67 module:log("error", 'Command "'..command.name.. |
| 67 '" at node "'..command.node..'" provided an invalid action "'..action..'"'); | 68 '" at node "'..command.node..'" provided an invalid action "'..action..'"'); |
| 68 end | 69 end |
| 69 end | 70 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 | |
| 79 stanza:add_child(cmdtag); | 86 stanza:add_child(cmdtag); |
| 80 origin.send(stanza); | 87 origin.send(stanza); |
| 81 | 88 |
| 82 return true; | 89 return true; |
| 83 end | 90 end |