plugins/browsing.lua

Thu, 23 Mar 2023 18:56:32 +0000

author
Matthew Wild <mwild1@gmail.com>
date
Thu, 23 Mar 2023 18:56:32 +0000
changeset 485
c9a144591649
parent 466
1eaec52ff71a
permissions
-rw-r--r--

component: Avoid adding to the global stream metatable

This allows component and client connections to be made side-by-side.
Previous to this change, loading this connection module would break the
ability to make client connections, due to overriding stream methods such as
:reopen() and :reset().

A next step would be to share the methods that the two connection modules have
in common.

local verse = require "verse";

local xmlns_browsing = "urn:xmpp:browsing:0";

function verse.plugins.browsing(stream)
	stream:add_plugin("pep");
	function stream:browsing(infos, callback)
		if type(infos) == "string" then
			infos = {uri = infos};
		end

		local link = verse.stanza("page", {xmlns = xmlns_browsing})
		for info, value in pairs(infos) do
			link:tag(info):text(value):up();
		end
		return stream:publish_pep(link, callback);
	end

	stream:hook_pep(xmlns_browsing, function(event)
		local item = event.item;
		return stream:event("browsing", {
			from = event.from;
			description = item:get_child_text "description";
			keywords = item:get_child_text "keywords";
			title = item:get_child_text "title";
			uri = item:get_child_text "uri";
		});
	end);
end

mercurial