comparison mod_csi_battery_saver/mod_csi_battery_saver.lua @ 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 b62cec32680e
children a688b31295ea
comparison
equal deleted inserted replaced
2745:b62cec32680e 2746:d3a2f4bdaf09
13 13
14 local xmlns_delay = "urn:xmpp:delay"; 14 local xmlns_delay = "urn:xmpp:delay";
15 15
16 -- a log id for this module instance 16 -- a log id for this module instance
17 local id = s_sub(require "util.hashes".sha256(datetime.datetime(), true), 1, 4); 17 local id = s_sub(require "util.hashes".sha256(datetime.datetime(), true), 1, 4);
18
19 local filter_muc = module:get_option_boolean("csi_battery_saver_filter_muc", false);
20
18 21
19 -- Patched version of util.stanza:find() that supports giving stanza names 22 -- Patched version of util.stanza:find() that supports giving stanza names
20 -- without their namespace, allowing for every namespace. 23 -- without their namespace, allowing for every namespace.
21 local function find(self, path) 24 local function find(self, path)
22 local pos = 1; 25 local pos = 1;
131 if stanza:get_child("openpgp", "urn:xmpp:openpgp:0") then return true; end 134 if stanza:get_child("openpgp", "urn:xmpp:openpgp:0") then return true; end
132 135
133 local body = stanza:get_child_text("body"); 136 local body = stanza:get_child_text("body");
134 if st_type == "groupchat" then 137 if st_type == "groupchat" then
135 if stanza:get_child_text("subject") then return true; end 138 if stanza:get_child_text("subject") then return true; end
136 if not body then return false; end 139 if body == nil or body == "" then return false; end
137 if body:find(session.username, 1, true) then return true; end 140 -- body contains text, let's see if we want to process it further
138 local rooms = session.rooms_joined; 141 if filter_muc then
139 if not rooms then return false; end 142 if body:find(session.username, 1, true) then return true; end
140 local room_nick = rooms[jid.bare(stanza_direction == "in" and stanza.attr.from or stanza.attr.to)]; 143 local rooms = session.rooms_joined;
141 if room_nick and body:find(room_nick, 1, true) then return true; end 144 if not rooms then return false; end
142 return false; 145 local room_nick = rooms[jid.bare(stanza_direction == "in" and stanza.attr.from or stanza.attr.to)];
146 if room_nick and body:find(room_nick, 1, true) then return true; end
147 return false;
148 else
149 return true;
150 end
143 end 151 end
144 return body ~= nil and body ~= ""; 152 return body ~= nil and body ~= "";
145 end 153 end
146 return true; 154 return true;
147 end 155 end