Diff

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
parent 6353:a868d5d6a83f
child 6843:161cccfdf015
line wrap: on
line diff
--- a/plugins/mod_private.lua	Mon Sep 21 23:00:49 2015 +0200
+++ b/plugins/mod_private.lua	Mon Sep 21 23:06:22 2015 +0200
@@ -17,19 +17,23 @@
 	local origin, stanza = event.origin, event.stanza;
 	local query = stanza.tags[1];
 	if #query.tags ~= 1 then
-		return origin.send(st.error_reply(stanza, "modify", "bad-format"));
+		origin.send(st.error_reply(stanza, "modify", "bad-format"));
+		return true;
 	end
 	local tag = query.tags[1];
 	local key = tag.name..":"..tag.attr.xmlns;
 	local data, err = private_storage:get(origin.username);
 	if err then
-		return origin.send(st.error_reply(stanza, "wait", "internal-server-error", err));
+		origin.send(st.error_reply(stanza, "wait", "internal-server-error", err));
+		return true;
 	end
 	if stanza.attr.type == "get" then
 		if data and data[key] then
-			return origin.send(st.reply(stanza):query("jabber:iq:private"):add_child(st.deserialize(data[key])));
+			origin.send(st.reply(stanza):query("jabber:iq:private"):add_child(st.deserialize(data[key])));
+			return true;
 		else
-			return origin.send(st.reply(stanza):add_child(query));
+			origin.send(st.reply(stanza):add_child(query));
+			return true;
 		end
 	else -- type == set
 		if not data then data = {}; end;
@@ -41,8 +45,10 @@
 		-- TODO delete datastore if empty
 		local ok, err = private_storage:set(origin.username, data);
 		if not ok then
-			return origin.send(st.error_reply(stanza, "wait", "internal-server-error", err));
+			origin.send(st.error_reply(stanza, "wait", "internal-server-error", err));
+			return true;
 		end
-		return origin.send(st.reply(stanza));
+		origin.send(st.reply(stanza));
+		return true;
 	end
 end);