changeset 2175:cc0cf6748885

mod_presence_cache: Also cache the 'show' value
author Kim Alvefur <zash@zash.se>
date Wed, 11 May 2016 23:12:51 +0200 (2016-05-11)
parents 7be158b3376f
children b76b062e77db
files mod_presence_cache/mod_presence_cache.lua
diffstat 1 files changed, 14 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/mod_presence_cache/mod_presence_cache.lua	Sun May 08 18:05:41 2016 +0200
+++ b/mod_presence_cache/mod_presence_cache.lua	Wed May 11 23:12:51 2016 +0200
@@ -7,7 +7,7 @@
 
 local cache_size = module:get_option_number("presence_cache_size", 100);
 
-local bare_cache = {}; -- [username NUL bare_jid] = { [full_jid] = timestamp, ... }
+local bare_cache = {}; -- [username NUL bare_jid] = { [full_jid] = { timestamp, ... } }
 
 local function on_evict(cache_key)
 	local bare_cache_key = cache_key:match("^%Z+%z[^/]+");
@@ -51,11 +51,14 @@
 			return;
 		end
 
-		local stamp = datetime.datetime();
+		local presence_bits = {
+			stamp = datetime.datetime();
+			show = stanza:get_child_text("show");
+		};
 		if jids then
-			jids[contact_full] = stamp;
+			jids[contact_full] = presence_bits;
 		else
-			jids = { [contact_full] = stamp };
+			jids = { [contact_full] = presence_bits };
 			bare_cache[bare_cache_key] = jids;
 		end
 		presence_cache:set(cache_key, true);
@@ -76,9 +79,14 @@
 
 	local cached = bare_cache[bare_cache_key];
 	if not cached then return end
-	for jid, stamp in pairs(cached) do
+	for jid, presence_bits in pairs(cached) do
 		local presence = st.presence({ to = origin.full_jid, from = jid })
-			:tag("delay", { xmlns = "urn:xmpp:delay", from = module.host, stamp = stamp }):up();
+		if presence_bits.show then
+			presence:tag("show"):text(presence_bits.show):up();
+		end
+		if presence_bits.stamp then
+			presence:tag("delay", { xmlns = "urn:xmpp:delay", from = module.host, stamp = presence_bits.stamp }):up();
+		end
 		origin.send(presence);
 	end
 end