Software /
code /
prosody
Comparison
plugins/mod_mam/mod_mam.lua @ 10736:c5a3576a5335
mod_mam: Invert check for type
This is based on code in mod_csi_simple and aiming towards being more
flexible and maintainable than a couple of tests for when not to store.
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Tue, 21 Apr 2020 00:56:56 +0200 |
parent | 10735:f2838ffcc499 |
child | 10737:b2ede421adeb |
comparison
equal
deleted
inserted
replaced
10735:f2838ffcc499 | 10736:c5a3576a5335 |
---|---|
262 end | 262 end |
263 return stanza; | 263 return stanza; |
264 end | 264 end |
265 | 265 |
266 local function should_store(stanza) --> boolean, reason: string | 266 local function should_store(stanza) --> boolean, reason: string |
267 local orig_type = stanza.attr.type or "normal"; | 267 local st_type = stanza.attr.type or "normal"; |
268 -- We store chat messages or normal messages that have a body | 268 local st_to_full = (stanza.attr.to or ""):find("/"); |
269 if not(orig_type == "chat" or (orig_type == "normal" and stanza:get_child("body")) ) then | |
270 return false, "type"; | |
271 end | |
272 | 269 |
273 -- or if hints suggest we shouldn't | 270 -- or if hints suggest we shouldn't |
274 if not stanza:get_child("store", "urn:xmpp:hints") then -- No hint telling us we should store | 271 if not stanza:get_child("store", "urn:xmpp:hints") then -- No hint telling us we should store |
275 if stanza:get_child("no-permanent-store", "urn:xmpp:hints") | 272 if stanza:get_child("no-permanent-store", "urn:xmpp:hints") |
276 or stanza:get_child("no-store", "urn:xmpp:hints") then -- Hint telling us we should NOT store | 273 or stanza:get_child("no-store", "urn:xmpp:hints") then -- Hint telling us we should NOT store |
277 return false, "hint"; | 274 return false, "hint"; |
278 end | 275 end |
276 end | |
277 if st_type == "headline" then | |
278 -- Headline messages are ephemeral by definition | |
279 return false, "headline"; | |
280 end | |
281 if st_type == "groupchat" and st_to_full then | |
282 -- MUC messages always go to the full JID, usually archived by the MUC | |
283 return false, "groupchat"; | |
284 end | |
285 if stanza:get_child("body") then | |
286 return true, "body"; | |
279 end | 287 end |
280 | 288 |
281 return true, "default"; | 289 return true, "default"; |
282 end | 290 end |
283 | 291 |