# HG changeset patch # User Kim Alvefur # Date 1463322234 -7200 # Node ID 6f4f60ebb79672e07ca0f8b9e4a2d3d0b09b8a9a # Parent 81b109281879b381e021884a34993eb2020614f0 Add plugin for XEP-0195: User Browsing diff -r 81b109281879 -r 6f4f60ebb796 plugins/browsing.lua --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/plugins/browsing.lua Sun May 15 16:23:54 2016 +0200 @@ -0,0 +1,30 @@ +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 +