Pubsub uses new forms
authorMyhailo Danylenko <isbear@ukrpost.net>
Sun, 22 Mar 2009 05:49:14 +0200
changeset 51 a95a3a73482c
parent 50 12d8dd774fcc
child 52 50d4e9bc622d
Pubsub uses new forms
examples/ibb.lua
examples/pubsub.lua
examples/remote.lua
--- a/examples/ibb.lua	Sun Mar 22 04:54:29 2009 +0200
+++ b/examples/ibb.lua	Sun Mar 22 05:49:14 2009 +0200
@@ -42,8 +42,7 @@
 							},
 							function ()
 								success ( 'end' ) -- XXX
-							end,
-							fail )
+							end, fail )
 					elseif data ~= '' then
 						local encoded = base64.encode ( data )
 						while encoded:len () > 0 and noerr do
@@ -67,8 +66,7 @@
 						end
 					end
 				end )
-		end,
-		fail )
+		end, fail )
 end
 
 -- private
@@ -103,16 +101,16 @@
 						conn:send (
 							lm.message.create { to = from, mtype = 'iq-error', id = id,
 								error = { code = '405', type = 'cancel',
-									['not-allowed'] = { xmlns = 'urn:ietf:params:xml:ns:xmpp-stanzas' }
-								}
+									['not-allowed'] = { xmlns = 'urn:ietf:params:xml:ns:xmpp-stanzas' },
+								},
 							} )
 					end )
 			else
 				conn:send (
 					lm.message.create { to = from, mtype = 'iq-error', id = id,
 						error = { code = '409', type = 'cancel',
-							conflict = { xmlns = 'urn:ietf:params:xml:ns:xmpp-stanzas' }
-						}
+							conflict = { xmlns = 'urn:ietf:params:xml:ns:xmpp-stanzas' },
+						},
 					} )
 			end
 		elseif action == 'data' then
@@ -129,15 +127,15 @@
 					conn:send (
 						lm.message.create { to = from, mtype = 'iq-error', id = id,
 							error = { code = '409', type = 'cancel',
-								conflict = { xmlns = 'urn:ietf:params:xml:ns:xmpp-stanzas' }
-							}
+								conflict = { xmlns = 'urn:ietf:params:xml:ns:xmpp-stanzas' },
+							},
 						} )
 				else
 					conn:send (
 						lm.message.create { to = from, mtype = 'iq-error', id = id,
 							error = { code = '404', type = 'cancel', -- XXX: check
-								['item-not-found'] = { xmlns = 'urn:ietf:params:xml:ns:xmpp-stanzas' }
-							}
+								['item-not-found'] = { xmlns = 'urn:ietf:params:xml:ns:xmpp-stanzas' },
+							},
 						} )
 				end
 			end
@@ -158,15 +156,15 @@
 					conn:send (
 						lm.message.create { to = from, mtype = 'iq-error', id = id,
 							error = { code = '409', type = 'cancel',
-								conflict = { xmlns = 'urn:ietf:params:xml:ns:xmpp-stanzas' }
-							}
+								conflict = { xmlns = 'urn:ietf:params:xml:ns:xmpp-stanzas' },
+							},
 						} )
 				else
 					conn:send (
 						lm.message.create { to = from, mtype = 'iq-error', id = id,
 							error = { code = '404', type = 'cancel', -- XXX: check
-								['item-not-found'] = { xmlns = 'urn:ietf:params:xml:ns:xmpp-stanzas' }
-							}
+								['item-not-found'] = { xmlns = 'urn:ietf:params:xml:ns:xmpp-stanzas' },
+							},
 						} )
 				end
 			end
--- 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 )
--- a/examples/remote.lua	Sun Mar 22 04:54:29 2009 +0200
+++ b/examples/remote.lua	Sun Mar 22 05:49:14 2009 +0200
@@ -48,7 +48,12 @@
 									end, fail )
 							end,
 							function ( form, success, fail )
-								success ()
+								iq.send ( conn, to, 'set',
+									{
+										command = { xmlns = 'http://jabber.org/protocol/commands', node = command, sessionid = sid,
+											x = { xmlns = 'jabber:x:data', type = 'cancel' }, -- FIXME
+										},
+									}, success, fail )
 							end )
 					else
 						fail ( mess:xml () ) -- XXX