Diff

mod_webpresence/mod_webpresence.lua @ 5633:758866b43aa4

mod_webpresence: use module:http_url() to get the correct url.
author Trần H. Trung <xmpp:trần.h.trung@trung.fun>
date Sat, 29 Jul 2023 18:08:58 +0700
parent 5594:14480ca9576e
line wrap: on
line diff
--- a/mod_webpresence/mod_webpresence.lua	Thu Jul 27 18:41:06 2023 +0700
+++ b/mod_webpresence/mod_webpresence.lua	Sat Jul 29 18:08:58 2023 +0700
@@ -58,21 +58,23 @@
 	};
 };
 
-local function webpresence_url(jid_bare)
-	local config, path = module:get_option("http_paths");
+local function webpresence_url(jid)
+	local path = "/status";
+	local config = module:get_option("http_paths");
 	if config then
 		for k, v in pairs(config) do
-			if k == moduleName then path = v;
-			else path = "/status" .. "/"; end
+			if k == moduleName then 
+				path = v;
+				break;
+			end
 		end
-	else path = "/status" .. "/"; end
+	end
 
-	local urlConfig = module:get_option_string("http_external_link");
-	local urlBase = urlConfig..path..jid_bare;
-	local style = { "/text", "/message", "/json", "/html" };
-	local urlResult = urlBase.."\n";
+	local urlBase = module:context(module.host):http_url(module.name, path);
+	local style = { "text", "message", "json", "html" };
+	local urlResult = urlBase.."/"..jid.."\n";
 	for _, v in ipairs(style) do
-		urlResult = urlResult..urlBase..v.."\n";
+		urlResult = urlResult..urlBase.."/"..jid.."/"..v.."\n";
 	end
 	return urlResult;
 end
@@ -110,7 +112,7 @@
 	else
 		local resultSet, resultErr = webpresence_set(user, newValue)
 		if not resultSet or resultErr then
-			module:log(error, "Could not set value: %s", errOut);
+			module:log("error", moduleName..": ".."Could not set value for "..user.."@"..host..": %s", errOut);
 			return {
 				status = "completed";
 				info = "Could not set value: "..tostring(data.from).." …\n"