mod_pubsub, util.pubsub: Keep track of the order of items
authorKim Alvefur <zash@zash.se>
Fri, 04 Oct 2013 16:40:27 +0200
changeset 5851 cdcfd93e2f43
parent 5850 e8c743f4213f
child 5852 84bdac93910f
mod_pubsub, util.pubsub: Keep track of the order of items
plugins/mod_pubsub/mod_pubsub.lua
plugins/mod_pubsub/pubsub.lib.lua
util/pubsub.lua
--- a/plugins/mod_pubsub/mod_pubsub.lua	Mon Sep 30 23:46:38 2013 +0100
+++ b/plugins/mod_pubsub/mod_pubsub.lua	Fri Oct 04 16:40:27 2013 +0200
@@ -103,7 +103,7 @@
 		return origin.send(pubsub_error_reply(stanza, ret));
 	end
 
-	for id, item in pairs(ret) do
+	for _, id in ipairs(ret) do
 		reply:tag("item", { jid = module.host, name = id }):up();
 	end
 	event.exists = true;
--- a/plugins/mod_pubsub/pubsub.lib.lua	Mon Sep 30 23:46:38 2013 +0100
+++ b/plugins/mod_pubsub/pubsub.lib.lua	Fri Oct 04 16:40:27 2013 +0200
@@ -42,8 +42,8 @@
 	end
 
 	local data = st.stanza("items", { node = node });
-	for _, entry in pairs(results) do
-		data:add_child(entry);
+	for _, id in ipairs(results) do
+		data:add_child(results[id]);
 	end
 	local reply;
 	if data then
--- a/util/pubsub.lua	Mon Sep 30 23:46:38 2013 +0100
+++ b/util/pubsub.lua	Fri Oct 04 16:40:27 2013 +0200
@@ -258,6 +258,7 @@
 		end
 		node_obj = self.nodes[node];
 	end
+	node_obj.data[#node_obj.data + 1] = id;
 	node_obj.data[id] = item;
 	self.events.fire_event("item-published", { node = node, actor = actor, id = id, item = item });
 	self.config.broadcaster("items", node, node_obj.subscribers, item);
@@ -275,6 +276,12 @@
 		return false, "item-not-found";
 	end
 	node_obj.data[id] = nil;
+	for i, _id in ipairs(node_obj.data) do
+		if id == _id then
+			table.remove(node_obj, i);
+			break;
+		end
+	end
 	if retract then
 		self.config.broadcaster("items", node, node_obj.subscribers, retract);
 	end
@@ -309,7 +316,7 @@
 		return false, "item-not-found";
 	end
 	if id then -- Restrict results to a single specific item
-		return true, { [id] = node_obj.data[id] };
+		return true, { id, [id] = node_obj.data[id] };
 	else
 		return true, node_obj.data;
 	end