comparison mod_csi_battery_saver/mod_csi_battery_saver.lua @ 2754:d1aa5fc005f7

mod_csi_battery_saver: Consider chat markers and outgoing carbon copies as important. Both are used by some clients (eg. Conversations) to update system notifications.
author tmolitor <thilo@eightysoft.de>
date Sun, 27 Aug 2017 21:11:58 +0200
parents a688b31295ea
children 595d9d68fd11
comparison
equal deleted inserted replaced
2751:6b710a8bdf03 2754:d1aa5fc005f7
105 return false; 105 return false;
106 elseif st_name == "message" then 106 elseif st_name == "message" then
107 -- unpack carbon copies 107 -- unpack carbon copies
108 local stanza_direction = "in"; 108 local stanza_direction = "in";
109 local carbon; 109 local carbon;
110 local st_type;
110 -- support carbon copied message stanzas having an arbitrary message-namespace or no message-namespace at all 111 -- support carbon copied message stanzas having an arbitrary message-namespace or no message-namespace at all
111 if not carbon then carbon = find(stanza, "{urn:xmpp:carbons:2}/forwarded/message"); end 112 if not carbon then carbon = find(stanza, "{urn:xmpp:carbons:2}/forwarded/message"); end
112 if not carbon then carbon = find(stanza, "{urn:xmpp:carbons:1}/forwarded/message"); end 113 if not carbon then carbon = find(stanza, "{urn:xmpp:carbons:1}/forwarded/message"); end
113 stanza_direction = carbon and stanza:child_with_name("sent") and "out" or "in"; 114 stanza_direction = carbon and stanza:child_with_name("sent") and "out" or "in";
114 --session.log("debug", "mod_csi_battery_saver(%s): stanza_direction = %s, carbon = %s, stanza = %s", id, stanza_direction, carbon and "true" or "false", tostring(stanza)); 115 --session.log("debug", "mod_csi_battery_saver(%s): stanza_direction = %s, carbon = %s, stanza = %s", id, stanza_direction, carbon and "true" or "false", tostring(stanza));
115 if carbon then stanza = carbon; end 116 if carbon then stanza = carbon; end
116 -- carbon copied outgoing messages aren't important (but incoming carbon copies are!) 117 st_type = stanza.attr.type;
117 if carbon and stanza_direction == "out" then return false; end 118
118 119 -- headline message are always not important
119 local st_type = stanza.attr.type; 120 if st_type == "headline" then return false; end
120 if st_type == "headline" then 121
121 return false; 122 -- chat markers (XEP-0333) are important, too, because some clients use them to update their notifications
122 end 123 if find(stanza, "{urn:xmpp:chat-markers:0}") then return true; end;
123 124
124 -- We can't check for nick in encrypted groupchat messages, so let's treat them as important 125 -- carbon copied outgoing messages are important (some clients update their notifications upon receiving those) --> don't return false here
125 -- Some clients don't set a body or an empty body for encrypted messages 126 --if carbon and stanza_direction == "out" then return false; end
126 127
128 -- We can't check for body contents in encrypted messages, so let's treat them as important
129 -- Some clients don't even set a body or an empty body for encrypted messages
130
127 -- check omemo https://xmpp.org/extensions/inbox/omemo.html 131 -- check omemo https://xmpp.org/extensions/inbox/omemo.html
128 if stanza:get_child("encrypted", "eu.siacs.conversations.axolotl") or stanza:get_child("encrypted", "urn:xmpp:omemo:0") then return true; end 132 if stanza:get_child("encrypted", "eu.siacs.conversations.axolotl") or stanza:get_child("encrypted", "urn:xmpp:omemo:0") then return true; end
129 133
130 -- check xep27 pgp https://xmpp.org/extensions/xep-0027.html 134 -- check xep27 pgp https://xmpp.org/extensions/xep-0027.html
131 if stanza:get_child("x", "jabber:x:encrypted") then return true; end 135 if stanza:get_child("x", "jabber:x:encrypted") then return true; end
132 136
133 -- check xep373 pgp (OX) https://xmpp.org/extensions/xep-0373.html 137 -- check xep373 pgp (OX) https://xmpp.org/extensions/xep-0373.html
134 if stanza:get_child("openpgp", "urn:xmpp:openpgp:0") then return true; end 138 if stanza:get_child("openpgp", "urn:xmpp:openpgp:0") then return true; end
135 139
136 local body = stanza:get_child_text("body"); 140 local body = stanza:get_child_text("body");
137 if st_type == "groupchat" then 141 if st_type == "groupchat" then
138 if stanza:get_child_text("subject") then return true; end 142 if stanza:get_child_text("subject") then return true; end
139 if body == nil or body == "" then return false; end 143 if body == nil or body == "" then return false; end
140 -- body contains text, let's see if we want to process it further 144 -- body contains text, let's see if we want to process it further