diff mod_webpresence/mod_webpresence.lua @ 847:1c9a3454eb43

mod_webpresence: Don't calculate the same hash four times.
author Waqas Hussain <waqas20@gmail.com>
date Sat, 13 Oct 2012 03:31:26 +0500
parents 2d83708ea901
children 432dc4056114
line wrap: on
line diff
--- a/mod_webpresence/mod_webpresence.lua	Sat Oct 13 02:33:06 2012 +0500
+++ b/mod_webpresence/mod_webpresence.lua	Sat Oct 13 03:31:26 2012 +0500
@@ -56,14 +56,15 @@
 		statuses[status].image = { status_code = 200, headers = { content_type = "image/png" }, 
 			body = require_resource("status_"..status..".png") };
 	elseif type == "html" then
+		local jid_hash = sha1(jid, true);
 		statuses[status].html = { status_code = 200, headers = { content_type = "text/html" },
-			body = [[<div id="]]..sha1(jid,true)..[[_status" class="xmpp_status">]]..
-					[[<img id="]]..sha1(jid,true)..[[_img" class="xmpp_status_image" ]]..
+			body = [[<div id="]]..jid_hash..[[_status" class="xmpp_status">]]..
+					[[<img id="]]..jid_hash..[[_img" class="xmpp_status_image" ]]..
 						[[src="data:image/png;base64,]]..
 						b64(require_resource("status_"..status..".png"))..[[">]]..
-					[[<span id="]]..sha1(jid,true)..[[_name" ]]..
+					[[<span id="]]..jid_hash..[[_name" ]]..
 						[[class="xmpp_status_name">]]..status..[[</span>]]..
-					(message and [[<span id="]]..sha1(jid,true)..[[_message" ]]..
+					(message and [[<span id="]]..jid_hash..[[_message" ]]..
 						[[class="xmpp_status_message">]]..message..[[</span>]] or "")..
 				[[</div>]] };
 	elseif type == "text" then