local lm = require 'lm'
local activity = require 'lm.activity'
local pubsub = require 'lm.pubsub'
pubsub.handler ( 'http://jabber.org/protocol/activity',
function ( from, node, data )
if not main.yesno ( main.option ( 'lua_pep_notification' ) ) then
return true
end
local item = data:child ()
local activity, desc
while item do
if item:name () == 'text' then
desc = item:value ()
else
activity = item:name ()
local subitem = item:child ()
if subitem then
-- here we can check for non-standard subactivity elements,
-- add subactivity child elements handling
activity = ("%s: %s"):format ( activity, subitem:name () )
end
end
item = item:next ()
end
if activity then
main.print_info ( from, ("Now %s %s"):format ( activity, desc or '' ) )
else
main.print_info ( from, "Buddy hides his activity" )
end
return true
end )
main.command ( 'activity',
function ( args )
local a, text = args[1], args[2]
local act, subact = a:match ( "(.-)%-(.+)" )
if not act then
act = a
end
activity.publish ( lm.connection.bless ( main.connection () ),
function ()
print ( 'Activity published' )
end,
function ( mesg )
print ( 'Error publishing activity: ' .. mesg )
end, act, subact, text )
end, true )
commands_help['activity'] = "[activity[-specific_activity] [text]]\n\nPublishes your activity.\nNote, that for now it does not checks for activity validity, so, see xep0108 for valid activity values."
main.add_feature ( 'http://jabber.org/protocol/activity+notify' )
main.add_feature ( 'http://jabber.org/protocol/activity' )
-- vim: se ts=4: --