# HG changeset patch # User tmolitor # Date 1564444017 -7200 # Node ID 6b0db0f2d57a6fa86a299e99e6c9ccf36044c815 # Parent 83a68f5fde1d2445fa4874da79defd7f55801ea2 mod_csi_battery_saver: add compatibility with mod_csi_muc_priorities, make queue length configurable and update README diff -r 83a68f5fde1d -r 6b0db0f2d57a mod_csi_battery_saver/README.markdown --- a/mod_csi_battery_saver/README.markdown Mon Jul 29 16:10:09 2019 +0200 +++ b/mod_csi_battery_saver/README.markdown Tue Jul 30 01:46:57 2019 +0200 @@ -1,7 +1,5 @@ --- description: CSI module to save battery on mobile devices -labels: -- 'Stage-Alpha' --- Please use this module instead of [mod_csi_pump] if you want timestamping, @@ -18,28 +16,37 @@ bring up their radio for unimportant stanzas. `IQ` stanzas, and `message` stanzas containing a body or being encrypted, -chat markers (see [XEP-0333]) and all nonzas are considered important. +chat markers (see [XEP-0333]) and all *nonzas* are considered important. If the config option `csi_battery_saver_filter_muc` is set to true, groupchat messages must set a subject or have the user's username or nickname -in their messages (or be encrypted) to count as "important", if this option -is set to false (default), all groupchat messages having a body -or being encrypted are considered "important". +mentioned in the messages (or be encrypted) to count as "important". +**Warning:** you should only set this to true if your users can live with +groupchat messages being delayed several minutes! +On the other hand if this option is set to false (*default*), +all groupchat messages having a body or being encrypted are considered "important". +In this case [mod_csi_muc_priorities] can be used to let user configure per groupchat +which of them are important for them (e.g. all messages having a body are important) +and which are not (e.g. only mentions and own messages are important). +If users don't change their settings, [mod_csi_muc_priorities] handles all groupchats +as important (see its docs for more information). `Presence` stanzas are always considered not "important". All buffered stanzas that allow timestamping are properly stamped to reflect their original send time, see [XEP-0203]. Use with other CSI plugins such as [mod_throttle_presence], -[mod_filter_chatstates] or [mod_csi_pump] is *not* supported. +[mod_filter_chatstates], [mod_csi_simple] or [mod_csi_pump] is **not** supported. +Usage of [mod_csi_muc_priorities] is allowed (see configuration). -The internal stanza buffer of this module is hardcoded to 100 stanzas. +*Hint:* [mod_csi_muc_priorities] needs [mod_track_muc_joins] to function properly. 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. + Option Default Description + ---------------------------------- ---------- ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- + `csi_battery_saver_filter_muc` false Controls whether all MUC messages having a body should be considered as important as long as [mod_csi_muc_priorities] doesn't configure them to be **not** 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. + `csi_battery_saver_queue_size` 256 Size of the stanza buffer used for the queue (if the queue is full a flush will be forced) [f70c02c14161]: //hg.prosody.im/prosody-modules/raw-file/f70c02c14161/mod_smacks/mod_smacks.lua \ No newline at end of file diff -r 83a68f5fde1d -r 6b0db0f2d57a mod_csi_battery_saver/mod_csi_battery_saver.lua --- a/mod_csi_battery_saver/mod_csi_battery_saver.lua Mon Jul 29 16:10:09 2019 +0200 +++ b/mod_csi_battery_saver/mod_csi_battery_saver.lua Tue Jul 30 01:46:57 2019 +0200 @@ -3,6 +3,7 @@ -- local filter_muc = module:get_option_boolean("csi_battery_saver_filter_muc", false); +local queue_size = module:get_option_number("csi_battery_saver_queue_size", 256); module:depends"csi" if filter_muc then module:depends"track_muc_joins"; end -- only depend on this module if we actually use it @@ -31,7 +32,7 @@ return message, direction; end -local function new_pump(output, ...) +local function new_pump(session, output, ...) -- luacheck: ignore 212/self local q = new_queue(...); local flush = true; @@ -46,6 +47,7 @@ function q:push(item) local ok = push(self, item); if not ok then + session.log("debug", "mod_csi_battery_saver(%s): Queue full (%d items), forcing flush...", id, q:count()); q:flush(); output(item, self); elseif flush then @@ -115,21 +117,26 @@ -- check xep373 pgp (OX) https://xmpp.org/extensions/xep-0373.html if stanza:get_child("openpgp", "urn:xmpp:openpgp:0") then return true; end + + -- check eme + if stanza:get_child("encryption", "urn:xmpp:eme:0") then return true; end local body = stanza:get_child_text("body"); if st_type == "groupchat" then if stanza:get_child_text("subject") then return true; end 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 not filter_muc then -- default case + local stanza_important = module:fire_event("csi-is-stanza-important", { stanza = stanza, session = session }); + if stanza_important ~= nil then return stanza_important; end + return true; -- deemed unknown/high priority by mod_csi_muc_priorities or some other module + else 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 ~= ""; @@ -144,7 +151,7 @@ session.pump:pause(); else session.log("debug", "mod_csi_battery_saver(%s): Client is inactive the first time, initializing module for this session", id); - local pump = new_pump(session.send, 100); + local pump = new_pump(session, session.send, queue_size); pump:pause(); session.pump = pump; session._pump_orig_send = session.send;