Diff

plugins/mod_mam/mod_mam.lua @ 10736:c5a3576a5335

mod_mam: Invert check for type This is based on code in mod_csi_simple and aiming towards being more flexible and maintainable than a couple of tests for when not to store.
author Kim Alvefur <zash@zash.se>
date Tue, 21 Apr 2020 00:56:56 +0200
parent 10735:f2838ffcc499
child 10737:b2ede421adeb
line wrap: on
line diff
--- a/plugins/mod_mam/mod_mam.lua	Tue Apr 21 00:53:23 2020 +0200
+++ b/plugins/mod_mam/mod_mam.lua	Tue Apr 21 00:56:56 2020 +0200
@@ -264,11 +264,8 @@
 end
 
 local function should_store(stanza) --> boolean, reason: string
-	local orig_type = stanza.attr.type or "normal";
-	-- We store chat messages or normal messages that have a body
-	if not(orig_type == "chat" or (orig_type == "normal" and stanza:get_child("body")) ) then
-		return false, "type";
-	end
+	local st_type = stanza.attr.type or "normal";
+	local st_to_full = (stanza.attr.to or ""):find("/");
 
 	-- or if hints suggest we shouldn't
 	if not stanza:get_child("store", "urn:xmpp:hints") then -- No hint telling us we should store
@@ -277,6 +274,17 @@
 			return false, "hint";
 		end
 	end
+	if st_type == "headline" then
+		-- Headline messages are ephemeral by definition
+		return false, "headline";
+	end
+	if st_type == "groupchat" and st_to_full then
+		-- MUC messages always go to the full JID, usually archived by the MUC
+		return false, "groupchat";
+	end
+	if stanza:get_child("body") then
+		return true, "body";
+	end
 
 	return true, "default";
 end