Muc room configuration by owner
authorMyhailo Danylenko <isbear@ukrpost.net>
Sun, 26 Jul 2009 15:15:20 +0300
changeset 77 8a7f7829f4df
parent 76 11bd9d10ee3b
child 78 1253cacc0f21
Muc room configuration by owner
examples/lm/muc.lua
examples/mcabberrc.lua
examples/muc.lua
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/examples/lm/muc.lua	Sun Jul 26 15:15:20 2009 +0300
@@ -0,0 +1,41 @@
+
+-- MULTI-USER CHAT (XEP-0045)
+-- only owner room configuration
+
+-- library
+
+local iq     = require 'lm.iq'
+local x_data = require 'lm.x_data'
+
+--
+
+local F = { }
+
+function F.owner_config ( conn, to, success, fail )
+	iq.send ( conn, to, 'get',
+		{
+			query = { xmlns = 'http://jabber.org/protocol/muc#owner' },
+		},
+		function ( mess )
+			local x = mess:path ( 'query', 'x' )
+			if x then
+				success ( x_data.parse ( x ),
+					function ( form, success, fail )
+						iq.send ( conn, to, 'set',
+							{
+								command = form:format ( { xmlns = 'http://jabber.org/protocol/muc#owner' }, 'submit' ),
+							}, success, fail )
+					end,
+					function ( form, success, fail )
+						iq.send ( conn, to, 'set',
+							{
+								command = form:format ( { xmlns = 'http://jabber.org/protocol/muc#owner' }, 'cancel' ),
+							}, success, fail )
+					end )
+			end
+		end, fail )
+end
+
+return F
+
+-- vim: se ts=4: --
--- a/examples/mcabberrc.lua	Sun Jul 26 12:23:13 2009 +0300
+++ b/examples/mcabberrc.lua	Sun Jul 26 15:15:20 2009 +0300
@@ -278,6 +278,10 @@
 
 require 'disco'
 
+-- MULTI-USER CHAT (XEP-0045)
+
+require 'muc'
+
 -- IN-BAND BYTESTREAMS (XEP-0047)
 
 require 'ibb'
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/examples/muc.lua	Sun Jul 26 15:15:20 2009 +0300
@@ -0,0 +1,43 @@
+
+local lm  = require 'lm'
+local muc = require 'lm.muc'
+
+main.command ( 'room-config',
+	function ( args )
+		local who
+		if args then
+			who = args
+		else
+			who = main.current_buddy ()
+		end
+		local conn = lm.connection.bless ( main.connection () )
+		muc.owner_config ( conn, who,
+			function ( form, submit, reject )
+				insert_form ( form,
+					function ( form )
+						submit ( form,
+							function ()
+								main.print_info ( who, 'Room configuratino accepted' )
+							end,
+							function ( mesg )
+								main.print_info ( who, ('Room configuration failed: %s'):format ( mesg ) )
+							end )
+					end,
+					function ( form )
+						reject ( form,
+							function ()
+								main.print_info ( who, 'Room configuration cancelled' )
+							end,
+							function ( mesg )
+								main.print_info ( who, ('Room configuration cancellation failed: %s'):format ( mesg ) )
+							end )
+					end )
+			end,
+			function ( mesg )
+				main.print_info ( who, ('Room configutarion request failed: %s'):format ( mesg ) )
+			end )
+	end, false, 'jid' )
+
+commands_help['room-config'] = "[room_jid]\n\nRequests room configuration form from server. You must be owner of this room."
+
+-- vim: se ts=4: --