changeset 4522:08b71d02c6dc

mod_pubsub_post: Allow specifying item id by a special mapping If `{http://jabber.org/protocol/pubsub}id` exists as an attribute at the top level then it is used, otherwise the previous behavior (.id if string)
author Kim Alvefur <zash@zash.se>
date Mon, 22 Mar 2021 21:20:03 +0100
parents f7381268a597
children 6e20e6bf96f0
files mod_pubsub_post/mod_pubsub_post.lua
diffstat 1 files changed, 8 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/mod_pubsub_post/mod_pubsub_post.lua	Mon Mar 22 21:18:35 2021 +0100
+++ b/mod_pubsub_post/mod_pubsub_post.lua	Mon Mar 22 21:20:03 2021 +0100
@@ -63,7 +63,14 @@
 		return { status_code = 400; body = "object or array expected"; };
 	end
 	local payload = wrap(node, parsed, data)
-	return publish_payload(node, actor, type(parsed.id) == "string" and parsed.id or "current", payload);
+	local item_id = "current";
+	if payload.attr["http://jabber.org/protocol/pubsub\1id"] then
+		item_id = payload.attr["http://jabber.org/protocol/pubsub\1id"];
+		payload.attr["http://jabber.org/protocol/pubsub\1id"] = nil;
+	elseif type(parsed.id) == "string" then
+		item_id = parsed.id;
+	end
+	return publish_payload(node, actor, item_id, payload);
 end
 
 local function publish_atom(node, actor, feed)