examples/pubsub.lua
changeset 51 a95a3a73482c
parent 47 aba4bbe32cba
child 53 2162188b20cf
--- a/examples/pubsub.lua	Sun Mar 22 04:54:29 2009 +0200
+++ b/examples/pubsub.lua	Sun Mar 22 05:49:14 2009 +0200
@@ -5,6 +5,7 @@
 
 require 'lm'
 require 'iq'
+require 'x_data'
 
 -- public
 
@@ -68,6 +69,8 @@
 					success ( from, node, item ) -- XXX use registered xmlns handlers for that?
 					item = item:next ()
 				end
+			else
+				-- XXX
 			end
 		end, fail )
 end
@@ -121,41 +124,30 @@
 				configure = { node = node },
 			},
 		},
-		function ( mess ) -- FIXME
+		function ( mess )
 			local x = mess:path ( 'pubsub', 'configure', 'x' )
 			if x then
-				local fid = parse_form ( x )
-				forms[fid].send =
-					function ( form )
+				success ( x_data.parse ( x ),
+					function ( form, success, fail )
+						iq.send ( conn, to, 'set',
+							{
+								pubsub = { xmlns = 'http://jabber.org/protocol/pubsub#owner',
+									configure = form.format ( form, { node = node } ),
+								},
+							}, success, fail )
+					end,
+					function ( form, success, fail )
 						iq.send ( conn, to, 'set',
 							{
 								pubsub = { xmlns = 'http://jabber.org/protocol/pubsub#owner',
 									configure = { node = node,
-										x = { xmlns = 'jabber:x:data', type = 'submit',
-											field = form.val,
-										},
+										x = { xmlns = 'jabber:x:data', type = 'cancel' }, -- FIXME
 									},
 								},
-							},
-							function ( mess )
-								success ()
-								main.print_info ( to, 'Now you can run /form del ' .. fid .. ' to delete form from list' )
-								form.status = 'acquired'
-							end,
-							function ( mesg )
-								if mesg then
-									form.status = 'rejected'
-								else
-									form.status = 'unknown'
-								end
-								fail ( mesg )
-							end )
-						form.status = 'sent'
-					end
-				forms[fid].status = 'filling'
-				main.print_info ( to, 'You have new form. To fill it, use /form ' .. fid .. ' fieldname value' )
+							}, success, fail )
+					end )
 			else
-				main.print_info ( to, 'Weird, no error and no node configuration form: ' .. mess:xml () )
+				fail ( mess:xml () ) -- XXX
 			end
 		end, fail )
 end
@@ -261,8 +253,32 @@
 				end )
 		elseif action:sub ( 1, 4 ) == 'conf' then
 			pubsub.configure_node ( conn, who, node,
-				function ()
-					main.print_info ( who, 'Node configuration accepted' )
+				function ( form, submit, reject )
+					local id = #forms + 1
+					forms[id] = {
+						form = form,
+						submit =
+							function ( form )
+								submit ( form,
+									function ()
+										main.print_info ( who, 'Node configuration completed' )
+									end,
+									function ( mesg )
+										main.print_info ( who, 'Node configuration failed: ' .. mesg )
+									end )
+							end,
+						reject =
+							function ( form )
+								reject ( form,
+									function ()
+										main.print_info ( who, 'Node configuration cancelled' )
+									end,
+									function ( mesg )
+										main.print_info ( who, 'Node configuration cancellation failed: ' .. mesg )
+									end )
+							end,
+					}
+					print ( 'You have new form ' .. id )
 				end,
 				function ( mesg )
 					main.print_info ( who, 'Node configuration failed: ' .. mesg )