Software /
code /
prosody
Comparison
plugins/mod_mam/mod_mam.lua @ 10737:b2ede421adeb
mod_mam: Rework hints handling
Improved readability and early returns definite yes/no answer.
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Tue, 21 Apr 2020 01:01:25 +0200 |
parent | 10736:c5a3576a5335 |
child | 10738:19ffb2ebf114 |
comparison
equal
deleted
inserted
replaced
10736:c5a3576a5335 | 10737:b2ede421adeb |
---|---|
265 | 265 |
266 local function should_store(stanza) --> boolean, reason: string | 266 local function should_store(stanza) --> boolean, reason: string |
267 local st_type = stanza.attr.type or "normal"; | 267 local st_type = stanza.attr.type or "normal"; |
268 local st_to_full = (stanza.attr.to or ""):find("/"); | 268 local st_to_full = (stanza.attr.to or ""):find("/"); |
269 | 269 |
270 -- or if hints suggest we shouldn't | |
271 if not stanza:get_child("store", "urn:xmpp:hints") then -- No hint telling us we should store | |
272 if stanza:get_child("no-permanent-store", "urn:xmpp:hints") | |
273 or stanza:get_child("no-store", "urn:xmpp:hints") then -- Hint telling us we should NOT store | |
274 return false, "hint"; | |
275 end | |
276 end | |
277 if st_type == "headline" then | 270 if st_type == "headline" then |
278 -- Headline messages are ephemeral by definition | 271 -- Headline messages are ephemeral by definition |
279 return false, "headline"; | 272 return false, "headline"; |
280 end | 273 end |
281 if st_type == "groupchat" and st_to_full then | 274 if st_type == "groupchat" and st_to_full then |
282 -- MUC messages always go to the full JID, usually archived by the MUC | 275 -- MUC messages always go to the full JID, usually archived by the MUC |
283 return false, "groupchat"; | 276 return false, "groupchat"; |
277 end | |
278 if stanza:get_child("no-permanent-store", "urn:xmpp:hints") then | |
279 return false, "hint"; | |
280 end | |
281 if stanza:get_child("store", "urn:xmpp:hints") then | |
282 return true, "hint"; | |
284 end | 283 end |
285 if stanza:get_child("body") then | 284 if stanza:get_child("body") then |
286 return true, "body"; | 285 return true, "body"; |
287 end | 286 end |
288 | 287 |