Software /
code /
prosody-modules
Comparison
mod_csi_battery_saver/mod_csi_battery_saver.lua @ 5918:423163b65bb1
mod_csi_battery_saver: Some more improvements (handling of errors, muc invites, special data)
author | tmolitor <thilo@eightysoft.de> |
---|---|
date | Mon, 29 Apr 2024 02:00:34 +0200 |
parent | 5917:5db53d619e66 |
comparison
equal
deleted
inserted
replaced
5917:5db53d619e66 | 5918:423163b65bb1 |
---|---|
83 stanza = stanza:tag("delay", { xmlns = xmlns_delay, from = bare_jid, stamp = datetime.datetime()}); | 83 stanza = stanza:tag("delay", { xmlns = xmlns_delay, from = bare_jid, stamp = datetime.datetime()}); |
84 return stanza; | 84 return stanza; |
85 end | 85 end |
86 | 86 |
87 local function is_important(stanza, session) | 87 local function is_important(stanza, session) |
88 -- some special handlings | |
89 if stanza == " " then -- whitespace keepalive | |
90 return true; | |
91 elseif type(stanza) == "string" then -- raw data | |
92 return true; | |
93 elseif not st.is_stanza(stanza) then -- this should probably never happen | |
94 return true; | |
95 end | |
96 if stanza.attr.xmlns ~= nil then -- nonzas (stream errors, stream management etc.) | |
97 return true; | |
98 end | |
88 local st_name = stanza and stanza.name or nil; | 99 local st_name = stanza and stanza.name or nil; |
89 if not st_name then return true; end -- nonzas are always important | 100 if not st_name then return true; end -- nonzas are always important |
90 if st_name == "presence" then | 101 if st_name == "presence" then |
91 local st_type = stanza.attr.type; | 102 local st_type = stanza.attr.type; |
92 -- subscription requests are important | 103 -- subscription requests are important |
102 --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)); | 113 --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)); |
103 if carbon then stanza = carbon; end | 114 if carbon then stanza = carbon; end |
104 | 115 |
105 local st_type = stanza.attr.type; | 116 local st_type = stanza.attr.type; |
106 | 117 |
118 -- errors are always important | |
119 if st_type == "error" then return true; end; | |
120 | |
107 -- headline message are always not important, with some exceptions | 121 -- headline message are always not important, with some exceptions |
108 if st_type == "headline" then | 122 if st_type == "headline" then |
109 -- allow headline pushes of mds updates (XEP-0490) | 123 -- allow headline pushes of mds updates (XEP-0490) |
110 if stanza:find("{http://jabber.org/protocol/pubsub#event}event/items@node") == "urn:xmpp:mds:displayed:0" then return true; end; | 124 if stanza:find("{http://jabber.org/protocol/pubsub#event}event/items@node") == "urn:xmpp:mds:displayed:0" then return true; end; |
111 return false | 125 return false |
112 end | 126 end |
127 | |
128 -- mediated muc invites | |
129 if stanza:find("{http://jabber.org/protocol/muc#user}x/invite") then return true; end; | |
130 if stanza:get_child("x", "jabber:x:conference") then return true; end; | |
113 | 131 |
114 -- chat markers (XEP-0333) are important, too, because some clients use them to update their notifications | 132 -- chat markers (XEP-0333) are important, too, because some clients use them to update their notifications |
115 if stanza:child_with_ns("urn:xmpp:chat-markers:0") then return true; end; | 133 if stanza:child_with_ns("urn:xmpp:chat-markers:0") then return true; end; |
116 | 134 |
117 -- XEP-0353: Jingle Message Initiation incoming call messages | 135 -- XEP-0353: Jingle Message Initiation incoming call messages |