aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKim Alvefur <zash@zash.se>2013-10-04 16:40:27 +0200
committerKim Alvefur <zash@zash.se>2013-10-04 16:40:27 +0200
commit76b14ec39b95d3f7b09b4cd3766e87c9fdd7fcd6 (patch)
tree526d84ef711408b482ad52210129c4fa45ffa031
parent6f46b6cd1a2f6cc65a55cbca524c664b78f219f5 (diff)
downloadprosody-76b14ec39b95d3f7b09b4cd3766e87c9fdd7fcd6.tar.gz
prosody-76b14ec39b95d3f7b09b4cd3766e87c9fdd7fcd6.zip
mod_pubsub, util.pubsub: Keep track of the order of items
-rw-r--r--plugins/mod_pubsub/mod_pubsub.lua2
-rw-r--r--plugins/mod_pubsub/pubsub.lib.lua4
-rw-r--r--util/pubsub.lua9
3 files changed, 11 insertions, 4 deletions
diff --git a/plugins/mod_pubsub/mod_pubsub.lua b/plugins/mod_pubsub/mod_pubsub.lua
index 81a66f8b..2868d409 100644
--- a/plugins/mod_pubsub/mod_pubsub.lua
+++ b/plugins/mod_pubsub/mod_pubsub.lua
@@ -103,7 +103,7 @@ module:hook("host-disco-items-node", function (event)
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;
diff --git a/plugins/mod_pubsub/pubsub.lib.lua b/plugins/mod_pubsub/pubsub.lib.lua
index 2b015e34..4e9acd68 100644
--- a/plugins/mod_pubsub/pubsub.lib.lua
+++ b/plugins/mod_pubsub/pubsub.lib.lua
@@ -42,8 +42,8 @@ function handlers.get_items(origin, stanza, items, service)
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
diff --git a/util/pubsub.lua b/util/pubsub.lua
index 0dfd196b..e0d428c0 100644
--- a/util/pubsub.lua
+++ b/util/pubsub.lua
@@ -258,6 +258,7 @@ function service:publish(node, actor, id, item)
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 @@ function service:retract(node, actor, id, retract)
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 @@ function service:get_items(node, actor, id)
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