examples/attention.lua
changeset 111 5bcdb71ef2f2
parent 99 ed4676536ed9
child 121 75a7d595817c
equal deleted inserted replaced
110:bd9f24178d67 111:5bcdb71ef2f2
    46 		if connection then
    46 		if connection then
    47 			lm.connection.bless(connection):handler ( attention_handler, 'message', 'normal' )
    47 			lm.connection.bless(connection):handler ( attention_handler, 'message', 'normal' )
    48 			attention_handler_registered = true
    48 			attention_handler_registered = true
    49 		end
    49 		end
    50 	end
    50 	end
    51 main.hook ( 'hook-post-connect', attention_pc_handler )
    51 local attention_pd_handler = 
    52 main.hook ( 'hook-pre-disconnect',
       
    53 	function ( args )
    52 	function ( args )
    54 		if attention_handler_registered then
    53 		if attention_handler_registered then
    55 			local connection = main.connection ()
    54 			local connection = main.connection ()
    56 			if connection then
    55 			if connection then
    57 				lm.connection.bless(connection):handler ( attention_handler, 'message' )
    56 				lm.connection.bless(connection):handler ( attention_handler, 'message' )
    58 			end
    57 			end
    59 			attention_handler_registered = false
    58 			attention_handler_registered = false
    60 		end
    59 		end
    61 	end )
    60 	end
       
    61 main.hook ( 'hook-post-connect',   attention_pc_handler )
       
    62 main.hook ( 'hook-pre-disconnect', attention_pd_handler )
    62 
    63 
    63 -- register handler, if we are already connected
    64 -- register handler, if we are already connected
    64 main.hook ( 'hook-lua-start',
    65 main.hook ( 'hook-lua-start',
    65 	function ( args )
    66 	function ( args )
    66 		main.add_feature ( 'urn:xmpp:attention:0' )
    67 		main.add_feature ( 'urn:xmpp:attention:0' )
    67 		attention_pc_handler ()
    68 		attention_pc_handler ()
    68 	end )
    69 	end )
    69 main.hook ('hook-lua-quit',
    70 main.hook ('hook-lua-quit',
    70 	function ( args )
    71 	function ( args )
    71 		main.del_feature ( 'urn:xmpp:attention:0' )
    72 		main.del_feature ( 'urn:xmpp:attention:0' )
       
    73 		attention_pd_handler ()
    72 	end )
    74 	end )
    73 
    75 
    74 -- vim: se ts=4 sw=4: --
    76 -- vim: se ts=4 sw=4: --