# HG changeset patch # User Kim Alvefur # Date 1605543338 -3600 # Node ID 93eda3dd85f733859c03933b7567f32b62e75ca3 # Parent 8815232cbbeb8eb5db4cc50a67f5bbb7a1566438 clix.watch_pep: Allow watching more than one PEP node diff -r 8815232cbbeb -r 93eda3dd85f7 clix/watch_pep.lua --- a/clix/watch_pep.lua Sun Nov 15 20:45:50 2020 +0100 +++ b/clix/watch_pep.lua Mon Nov 16 17:15:38 2020 +0100 @@ -3,26 +3,30 @@ return function (opts, arg) if opts.short_help or not arg[1] then print("Watches PEP notifications from all contacts") - print("clix watch_pep [--noempty] PEP-NODE") + print("clix watch_pep [--noempty] PEP-NODE+") return; end + local function handle_notification(event) + local payload = event.item; + if not payload then return end + if opts.noempty and not payload[1] then return end + if event.from then + io.stderr:write("# From "..event.from.."\n"); + end + if payload.attr.xmlns == "urn:xmpp:json:0" then + print(payload:get_tex()) + elseif opts.pretty then + print(payload:indent(nil, " ")); + else + print(payload); + end + end + local function onconnect(conn) - conn:hook_pep(arg[1], function (event) - local payload = event.item; - if not payload then return end - if opts.noempty and not payload[1] then return end - if event.from then - io.stderr:write("# From "..event.from.."\n"); - end - if payload.attr.xmlns == "urn:xmpp:json:0" then - print(payload:get_tex()) - elseif opts.pretty then - print(payload:indent(nil, " ")); - else - print(payload); - end - end); + for _, node in ipairs(arg) do + conn:hook_pep(node, handle_notification); + end if not opts.presence then conn:send(verse.presence()); end