Changeset

3260:9bb317400c4c

mod_group_bookmarks: Use iq-get event instead of checking for stanza.attr.type == "get".
author Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
date Fri, 24 Aug 2018 19:34:30 +0200
parents 3259:6824a1f3d8c0
children 3261:c2b1f64aaf97
files mod_group_bookmarks/mod_group_bookmarks.lua
diffstat 1 files changed, 14 insertions(+), 17 deletions(-) [+]
line wrap: on
line diff
--- a/mod_group_bookmarks/mod_group_bookmarks.lua	Fri Aug 24 19:29:34 2018 +0200
+++ b/mod_group_bookmarks/mod_group_bookmarks.lua	Fri Aug 24 19:34:30 2018 +0200
@@ -42,9 +42,8 @@
 	return data;
 end
 
-module:hook("iq/self/jabber:iq:private:query", function(event)
+module:hook("iq-get/self/jabber:iq:private:query", function(event)
 	local origin, stanza = event.origin, event.stanza;
-	local type = stanza.attr.type;
 	local query = stanza.tags[1];
 	if #query.tags == 1 then
 		local tag = query.tags[1];
@@ -54,23 +53,21 @@
 			origin.send(st.error_reply(stanza, "wait", "internal-server-error"));
 			return true;
 		end
-		if stanza.attr.type == "get" then
-			local data = data and data[key];
-			if (not data) and key == "storage:storage:bookmarks" then
-				data = st.stanza("storage", { xmlns = "storage:bookmarks" });
+		local data = data and data[key];
+		if (not data) and key == "storage:storage:bookmarks" then
+			data = st.stanza("storage", { xmlns = "storage:bookmarks" });
+		end
+		if data then
+			data = st.deserialize(data);
+			if key == "storage:storage:bookmarks" then
+				data = inject_bookmarks(origin.username, origin.host, data);
 			end
-			if data then
-				data = st.deserialize(data);
-				if key == "storage:storage:bookmarks" then
-					data = inject_bookmarks(origin.username, origin.host, data);
-				end
-				origin.send(st.reply(stanza):tag("query", {xmlns = "jabber:iq:private"})
-					:add_child(data));
-			else
-				origin.send(st.reply(stanza):add_child(stanza.tags[1]));
-			end
-			return true;
+			origin.send(st.reply(stanza):tag("query", {xmlns = "jabber:iq:private"})
+				:add_child(data));
+		else
+			origin.send(st.reply(stanza):add_child(stanza.tags[1]));
 		end
+		return true;
 	end
 end, 1);