Changeset

2746:d3a2f4bdaf09

mod_csi_battery_saver: Add config option for better muc handling
author tmolitor <thilo@eightysoft.de>
date Fri, 18 Aug 2017 22:56:28 +0200
parents 2745:b62cec32680e
children 2747:a688b31295ea
files mod_csi_battery_saver/README.markdown mod_csi_battery_saver/mod_csi_battery_saver.lua
diffstat 2 files changed, 23 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/mod_csi_battery_saver/README.markdown	Fri Aug 18 01:49:16 2017 +0200
+++ b/mod_csi_battery_saver/README.markdown	Fri Aug 18 22:56:28 2017 +0200
@@ -30,4 +30,12 @@
 
 The internal stanza buffer of this module is hardcoded to 100 stanzas.
 
+Configuration
+=============
+
+  Option                              Default           Description
+  ----------------------------------  ---------- -----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
+  `csi_battery_saver_filter_muc`      false      Controls whether all muc messages having a body should be considered as important (false) or only such containing the user's room nic (true). Warning: you should only set this to true if your users can live with muc messages being delayed several minutes. 
+
+
 [f70c02c14161]: //hg.prosody.im/prosody-modules/raw-file/f70c02c14161/mod_smacks/mod_smacks.lua
\ No newline at end of file
--- a/mod_csi_battery_saver/mod_csi_battery_saver.lua	Fri Aug 18 01:49:16 2017 +0200
+++ b/mod_csi_battery_saver/mod_csi_battery_saver.lua	Fri Aug 18 22:56:28 2017 +0200
@@ -16,6 +16,9 @@
 -- a log id for this module instance
 local id = s_sub(require "util.hashes".sha256(datetime.datetime(), true), 1, 4);
 
+local filter_muc = module:get_option_boolean("csi_battery_saver_filter_muc", false);
+
+
 -- Patched version of util.stanza:find() that supports giving stanza names
 -- without their namespace, allowing for every namespace.
 local function find(self, path)
@@ -133,13 +136,18 @@
 		local body = stanza:get_child_text("body");
 		if st_type == "groupchat" then
 			if stanza:get_child_text("subject") then return true; end
-			if not body then return false; end
-			if body:find(session.username, 1, true) then return true; end
-			local rooms = session.rooms_joined;
-			if not rooms then return false; end
-			local room_nick = rooms[jid.bare(stanza_direction == "in" and stanza.attr.from or stanza.attr.to)];
-			if room_nick and body:find(room_nick, 1, true) then return true; end
-			return false;
+			if body == nil or body == "" then return false; end
+			-- body contains text, let's see if we want to process it further
+			if filter_muc then
+				if body:find(session.username, 1, true) then return true; end
+				local rooms = session.rooms_joined;
+				if not rooms then return false; end
+				local room_nick = rooms[jid.bare(stanza_direction == "in" and stanza.attr.from or stanza.attr.to)];
+				if room_nick and body:find(room_nick, 1, true) then return true; end
+				return false;
+			else
+				return true;
+			end
 		end
 		return body ~= nil and body ~= "";
 	end