Mercurial > prosody-hg
comparison plugins/mod_private.lua @ 6841:be87ab2d611c
plugins: Explicitly return to halt event propagation (session.send sometimes does not return true)
| author | Kim Alvefur <zash@zash.se> |
|---|---|
| date | Mon, 21 Sep 2015 23:06:22 +0200 |
| parents | a868d5d6a83f |
| children | 161cccfdf015 |
comparison
equal
deleted
inserted
replaced
| 6840:eeefe8d42b8b | 6841:be87ab2d611c |
|---|---|
| 15 | 15 |
| 16 module:hook("iq/self/jabber:iq:private:query", function(event) | 16 module:hook("iq/self/jabber:iq:private:query", function(event) |
| 17 local origin, stanza = event.origin, event.stanza; | 17 local origin, stanza = event.origin, event.stanza; |
| 18 local query = stanza.tags[1]; | 18 local query = stanza.tags[1]; |
| 19 if #query.tags ~= 1 then | 19 if #query.tags ~= 1 then |
| 20 return origin.send(st.error_reply(stanza, "modify", "bad-format")); | 20 origin.send(st.error_reply(stanza, "modify", "bad-format")); |
| 21 return true; | |
| 21 end | 22 end |
| 22 local tag = query.tags[1]; | 23 local tag = query.tags[1]; |
| 23 local key = tag.name..":"..tag.attr.xmlns; | 24 local key = tag.name..":"..tag.attr.xmlns; |
| 24 local data, err = private_storage:get(origin.username); | 25 local data, err = private_storage:get(origin.username); |
| 25 if err then | 26 if err then |
| 26 return origin.send(st.error_reply(stanza, "wait", "internal-server-error", err)); | 27 origin.send(st.error_reply(stanza, "wait", "internal-server-error", err)); |
| 28 return true; | |
| 27 end | 29 end |
| 28 if stanza.attr.type == "get" then | 30 if stanza.attr.type == "get" then |
| 29 if data and data[key] then | 31 if data and data[key] then |
| 30 return origin.send(st.reply(stanza):query("jabber:iq:private"):add_child(st.deserialize(data[key]))); | 32 origin.send(st.reply(stanza):query("jabber:iq:private"):add_child(st.deserialize(data[key]))); |
| 33 return true; | |
| 31 else | 34 else |
| 32 return origin.send(st.reply(stanza):add_child(query)); | 35 origin.send(st.reply(stanza):add_child(query)); |
| 36 return true; | |
| 33 end | 37 end |
| 34 else -- type == set | 38 else -- type == set |
| 35 if not data then data = {}; end; | 39 if not data then data = {}; end; |
| 36 if #tag == 0 then | 40 if #tag == 0 then |
| 37 data[key] = nil; | 41 data[key] = nil; |
| 39 data[key] = st.preserialize(tag); | 43 data[key] = st.preserialize(tag); |
| 40 end | 44 end |
| 41 -- TODO delete datastore if empty | 45 -- TODO delete datastore if empty |
| 42 local ok, err = private_storage:set(origin.username, data); | 46 local ok, err = private_storage:set(origin.username, data); |
| 43 if not ok then | 47 if not ok then |
| 44 return origin.send(st.error_reply(stanza, "wait", "internal-server-error", err)); | 48 origin.send(st.error_reply(stanza, "wait", "internal-server-error", err)); |
| 49 return true; | |
| 45 end | 50 end |
| 46 return origin.send(st.reply(stanza)); | 51 origin.send(st.reply(stanza)); |
| 52 return true; | |
| 47 end | 53 end |
| 48 end); | 54 end); |
