Changeset

451:a0c55329c38d

Merge with MattJ
author Kim Alvefur <zash@zash.se>
date Wed, 03 Aug 2022 02:47:55 +0200
parents 450:e72deac76e0e (current diff) 438:98dc1750584d (diff)
children 452:628896d39d8e
files
diffstat 1 files changed, 41 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/plugins/pubsub.lua	Sat Feb 19 15:57:24 2022 +0100
+++ b/plugins/pubsub.lua	Wed Aug 03 02:47:55 2022 +0200
@@ -58,11 +58,19 @@
 
 -- Helper function for iq+pubsub tags
 
-local function pubsub_iq(iq_type, to, ns, op, node, jid, item_id)
+local function pubsub_iq(iq_type, to, ns, op, node, jid, item_id, op_attr_extra)
 	local st = verse.iq{ type = iq_type or "get", to = to }
 		:tag("pubsub", { xmlns = ns or xmlns_pubsub }) -- ns would be ..#owner
-			if op then st:tag(op, { node = node, jid = jid }); end
-				if item_id then st:tag("item", { id = item_id ~= true and item_id or nil }); end
+			local op_attr = { node = node, jid = jid };
+			if op_attr_extra then
+				for k, v in pairs(op_attr_extra) do
+					op_attr[k] = v;
+				end
+			end
+			if op then st:tag(op, op_attr); end
+			if item_id then
+				st:tag("item", { id = item_id ~= true and item_id or nil });
+			end
 	return st;
 end
 
@@ -248,15 +256,39 @@
 	, callback);
 end
 
-function pubsub_node:retract(id, callback)
-	self.stream:send_iq(pubsub_iq("set", self.service, nil, "retract", self.node, nil, id)
-	, callback);
+function pubsub_node:retract(id, notify, callback)
+	if type(notify) == "function" then -- COMPAT w/ older versions before 'notify' was added
+		notify, callback = false, notify;
+	end
+	self.stream:send_iq(
+		pubsub_iq(
+			"set",
+			self.service,
+			nil,
+			"retract",
+			self.node,
+			nil,
+			id,
+			{ notify = notify and "1" or nil }
+		),
+		callback
+	);
 end
 
 function pubsub_node:purge(notify, callback)
-	assert(not notify, "Not implemented yet.");
-	self.stream:send_iq(pubsub_iq("set", self.service, xmlns_pubsub_owner, "purge", self.node)
-	, callback);
+	self.stream:send_iq(
+		pubsub_iq(
+			"set",
+			self.service,
+			xmlns_pubsub_owner,
+			"purge",
+			self.node,
+			nil,
+			nil,
+			{ notify = notify and "1" or nil }
+		),
+		callback
+	);
 end
 
 function pubsub_node:delete(redirect_uri, callback)