Comparison

mod_conversejs/mod_conversejs.lua @ 3313:d6b922191aeb

mod_conversejs: Factor out option handling into a function for future reuse
author Kim Alvefur <zash@zash.se>
date Mon, 10 Sep 2018 15:07:07 +0200
parent 3312:e714be00aaad
child 3314:ab67f222d88b
comparison
equal deleted inserted replaced
3312:e714be00aaad 3313:d6b922191aeb
44 44
45 js_template = "converse.initialize(%s);"; 45 js_template = "converse.initialize(%s);";
46 46
47 local more_options = module:get_option("conversejs_options"); 47 local more_options = module:get_option("conversejs_options");
48 48
49 local function get_converse_options()
50 local allow_registration = module:get_option_boolean("allow_registration", false);
51 local converse_options = {
52 bosh_service_url = module:http_url("bosh","/http-bind");
53 websocket_url = has_ws and module:http_url("websocket","xmpp-websocket"):gsub("^http", "ws") or nil;
54 authentication = module:get_option_string("authentication") == "anonymous" and "anonymous" or "login";
55 jid = module.host;
56 default_domain = module.host;
57 domain_placeholder = module.host;
58 allow_registration = allow_registration;
59 registration_domain = allow_registration and module.host or nil;
60 };
61
62 if type(more_options) == "table" then
63 for k,v in pairs(more_options) do
64 converse_options[k] = v;
65 end
66 end
67
68 return converse_options;
69 end
70
49 module:provides("http", { 71 module:provides("http", {
50 route = { 72 route = {
51 GET = function (event) 73 GET = function (event)
52 local allow_registration = module:get_option_boolean("allow_registration", false); 74 local converse_options = get_converse_options();
53 local converse_options = {
54 bosh_service_url = module:http_url("bosh","/http-bind");
55 websocket_url = has_ws and module:http_url("websocket","xmpp-websocket"):gsub("^http", "ws") or nil;
56 authentication = module:get_option_string("authentication") == "anonymous" and "anonymous" or "login";
57 jid = module.host;
58 default_domain = module.host;
59 domain_placeholder = module.host;
60 allow_registration = allow_registration;
61 registration_domain = allow_registration and module.host or nil;
62 };
63
64 if type(more_options) == "table" then
65 for k,v in pairs(more_options) do
66 converse_options[k] = v;
67 end
68 end
69 75
70 event.response.headers.content_type = "text/html"; 76 event.response.headers.content_type = "text/html";
71 return html_template:format(js_template:format(json_encode(converse_options))); 77 return html_template:format(js_template:format(json_encode(converse_options)));
72 end; 78 end;
73 } 79 }