--- a/examples/xep0163.lua Mon Mar 16 18:54:16 2009 +0200
+++ b/examples/xep0163.lua Mon Mar 16 19:57:51 2009 +0200
@@ -72,8 +72,15 @@
end
end
-function pep_publish ( node, data )
- local conn = lm.connection.bless ( main.connection () )
+function pep_publish ( conn, callback, node, data )
+ if not callback then
+ callback =
+ function ( mesg )
+ if mesg then
+ print ( mesg ) -- FIXME
+ end
+ end
+ end
data.xmlns = 'http://jabber.org/protocol/' .. node -- this may modify original data? imo it does not matter.
if conn:status () == 'authenticated' then
-- local bjid = conn:jid():gsub ( '/.*', '' )
@@ -101,12 +108,13 @@
function ( conn, mess )
local mtype, smtype = mess:type ()
if smtype == 'result' then
+ callback ()
return true
elseif smtype == 'error' then
- print ( 'Error publishing to ' .. node .. ': ' .. mess:xml () ) -- FIXME
+ callback ( message:child( 'error' ):children():name () )
return true
else
- print ( 'Weird ansver to publishing request: ' .. mess:xml () )
+ callback ( 'Weird ansver to publishing request: ' .. mess:xml () )
return false
end
end )
@@ -226,7 +234,7 @@
function mpd_callback ()
local sdata = mpd_getstatus ()
if sdata then
- pep_publish ( 'tune', sdata )
+ pep_publish ( lm.connection.bless ( main.connection () ), nil, 'tune', sdata )
end
if tune_enabled then
return true
@@ -277,7 +285,7 @@
if mood then
data[mood] = { }
end
- pep_publish ( 'mood', data )
+ pep_publish ( lm.connection.bless ( main.connection () ), nil, 'mood', data )
end, true )
main.command ( 'activity',
function ( args )
@@ -296,7 +304,7 @@
data[act][subact] = { }
end
end
- pep_publish ( 'activity', data )
+ pep_publish ( lm.connection.bless ( main.connection () ), nil, 'activity', data )
end, true )
main.command ( 'location',
function ( args )
@@ -304,7 +312,7 @@
for key, val in pairs ( args ) do
data[key] = { val }
end
- pep_publish ( 'geoloc', data )
+ pep_publish ( lm.connection.bless ( main.connection () ), nil, 'geoloc', data )
end, true )
commands_help['tune'] = "[enable|disable|on|off|yes|no|true|false]\n\nEnables or disables publishing of notifications about playing music in your player (currently only mpd is supported)."