mod_pubsub_serverinfo/mod_pubsub_serverinfo.lua
changeset 5820 45d0802d0787
parent 5819 77c5709bd57a
child 5821 7905766d01f6
equal deleted inserted replaced
5819:77c5709bd57a 5820:45d0802d0787
     6 local service = module:get_option(module.name .. "_service") or "pubsub." .. local_domain;
     6 local service = module:get_option(module.name .. "_service") or "pubsub." .. local_domain;
     7 local node = module:get_option(module.name .. "_node") or "serverinfo";
     7 local node = module:get_option(module.name .. "_node") or "serverinfo";
     8 local actor = module.host .. "/modules/" .. module.name;
     8 local actor = module.host .. "/modules/" .. module.name;
     9 local publication_interval = module:get_option(module.name .. "_publication_interval") or 300;
     9 local publication_interval = module:get_option(module.name .. "_publication_interval") or 300;
    10 local cache_ttl = module:get_option(module.name .. "_cache_ttl") or 3600;
    10 local cache_ttl = module:get_option(module.name .. "_cache_ttl") or 3600;
       
    11 local delete_node_on_unload = module:get_option_boolean(module.name.."_delete_node_on_unload", false);
       
    12 local persist_items = module:get_option_boolean(module.name.."_persist_items", true);
    11 
    13 
    12 local xmlns_pubsub = "http://jabber.org/protocol/pubsub";
    14 local xmlns_pubsub = "http://jabber.org/protocol/pubsub";
    13 
    15 
    14 function module.load()
    16 function module.load()
    15 	discover_node():next(
    17 	discover_node():next(
    37 	module:add_timer(10, publish_serverinfo);
    39 	module:add_timer(10, publish_serverinfo);
    38 end
    40 end
    39 
    41 
    40 function module.unload()
    42 function module.unload()
    41 	-- This removes all subscribers, which may or may not be desirable, depending on the reason for the unload.
    43 	-- This removes all subscribers, which may or may not be desirable, depending on the reason for the unload.
    42 	delete_node(); -- Should this block, to delay unload() until the node is deleted?
    44 	if delete_node_on_unload then
       
    45 		delete_node();
       
    46 	end
    43 end
    47 end
    44 
    48 
    45 -- Returns a promise of a boolean
    49 -- Returns a promise of a boolean
    46 function discover_node()
    50 function discover_node()
    47 	local request = st.iq({ type = "get", to = service, from = actor, id = new_id() })
    51 	local request = st.iq({ type = "get", to = service, from = actor, id = new_id() })
    82 						:up()
    86 						:up()
    83 					:tag("field", { var = "pubsub#max_items" })
    87 					:tag("field", { var = "pubsub#max_items" })
    84 						:text_tag("value", "1")
    88 						:text_tag("value", "1")
    85 						:up()
    89 						:up()
    86 					:tag("field", { var = "pubsub#persist_items" })
    90 					:tag("field", { var = "pubsub#persist_items" })
    87 						:text_tag("value", "0")
    91 						:text_tag("value", persist_items and "1" or "0")
    88 
    92 
    89 	module:log("debug", "Sending request to create pub/sub node '%s' at %s", node, service)
    93 	module:log("debug", "Sending request to create pub/sub node '%s' at %s", node, service)
    90 	return module:send_iq(request):next(
    94 	return module:send_iq(request):next(
    91 		function(response)
    95 		function(response)
    92 			if response.stanza == nil or response.stanza.attr.type ~= "result" then
    96 			if response.stanza == nil or response.stanza.attr.type ~= "result" then