Software / code / prosody
Comparison
plugins/mod_mam/mod_mam.lua @ 10758:d0e6d5bc7ea2
Merge with upstream trunk
| author | Matthew Wild <mwild1@gmail.com> |
|---|---|
| date | Thu, 23 Apr 2020 13:53:18 +0100 |
| parent | 10752:930f38939f1e |
| child | 10773:3e1046b39484 |
comparison
equal
deleted
inserted
replaced
| 10757:9dec7cddb40b | 10758:d0e6d5bc7ea2 |
|---|---|
| 261 end); | 261 end); |
| 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 | |
| 267 local st_type = stanza.attr.type or "normal"; | |
| 268 -- FIXME pass direction of stanza and use that along with bare/full JID addressing | |
| 269 -- for more accurate MUC / type=groupchat check | |
| 270 | |
| 271 if st_type == "headline" then | |
| 272 -- Headline messages are ephemeral by definition | |
| 273 return false, "headline"; | |
| 274 end | |
| 275 if st_type == "error" then | |
| 276 return true, "bounce"; | |
| 277 end | |
| 278 if st_type == "groupchat" then | |
| 279 -- MUC messages always go to the full JID, usually archived by the MUC | |
| 280 return false, "groupchat"; | |
| 281 end | |
| 282 if stanza:get_child("no-store", "urn:xmpp:hints") | |
| 283 or stanza:get_child("no-permanent-store", "urn:xmpp:hints") then | |
| 284 -- XXX Experimental XEP | |
| 285 return false, "hint"; | |
| 286 end | |
| 287 if stanza:get_child("store", "urn:xmpp:hints") then | |
| 288 return true, "hint"; | |
| 289 end | |
| 290 if stanza:get_child("body") then | |
| 291 return true, "body"; | |
| 292 end | |
| 293 if stanza:get_child("subject") then | |
| 294 -- XXX Who would send a message with a subject but without a body? | |
| 295 return true, "subject"; | |
| 296 end | |
| 297 if stanza:get_child("encryption", "urn:xmpp:eme:0") then | |
| 298 -- Since we can't know what an encrypted message contains, we assume it's important | |
| 299 -- XXX Experimental XEP | |
| 300 return true, "encrypted"; | |
| 301 end | |
| 302 if stanza:get_child(nil, "urn:xmpp:receipts") then | |
| 303 -- If it's important enough to ask for a receipt then it's important enough to archive | |
| 304 -- and the same applies to the receipt | |
| 305 return true, "receipt"; | |
| 306 end | |
| 307 if stanza:get_child(nil, "urn:xmpp:chat-markers:0") then | |
| 308 -- XXX Experimental XEP | |
| 309 return true, "marker"; | |
| 310 end | |
| 311 if stanza:get_child("x", "jabber:x:conference") | |
| 312 or stanza:find("{http://jabber.org/protocol/muc#user}x/invite") then | |
| 313 return true, "invite"; | |
| 314 end | |
| 315 | |
| 316 -- The IM-NG thing to do here would be to return `not st_to_full` | |
| 317 -- One day ... | |
| 318 return false, "default"; | |
| 319 end | |
| 320 | |
| 266 -- Handle messages | 321 -- Handle messages |
| 267 local function message_handler(event, c2s) | 322 local function message_handler(event, c2s) |
| 268 local origin, stanza = event.origin, event.stanza; | 323 local origin, stanza = event.origin, event.stanza; |
| 269 local log = c2s and origin.log or module._log; | 324 local log = c2s and origin.log or module._log; |
| 270 local orig_type = stanza.attr.type or "normal"; | |
| 271 local orig_from = stanza.attr.from; | 325 local orig_from = stanza.attr.from; |
| 272 local orig_to = stanza.attr.to or orig_from; | 326 local orig_to = stanza.attr.to or orig_from; |
| 273 -- Stanza without 'to' are treated as if it was to their own bare jid | 327 -- Stanza without 'to' are treated as if it was to their own bare jid |
| 274 | 328 |
| 275 -- Whos storage do we put it in? | 329 -- Whos storage do we put it in? |
| 278 local with = jid_bare(c2s and orig_to or orig_from); | 332 local with = jid_bare(c2s and orig_to or orig_from); |
| 279 | 333 |
| 280 -- Filter out <stanza-id> that claim to be from us | 334 -- Filter out <stanza-id> that claim to be from us |
| 281 event.stanza = strip_stanza_id(stanza, store_user); | 335 event.stanza = strip_stanza_id(stanza, store_user); |
| 282 | 336 |
| 283 -- We store chat messages or normal messages that have a body | 337 local should, why = should_store(stanza); |
| 284 if not(orig_type == "chat" or (orig_type == "normal" and stanza:get_child("body")) ) then | 338 if not should then |
| 285 log("debug", "Not archiving stanza: %s (type)", stanza:top_tag()); | 339 log("debug", "Not archiving stanza: %s (%s)", stanza:top_tag(), why); |
| 286 return; | 340 return; |
| 287 end | |
| 288 | |
| 289 -- or if hints suggest we shouldn't | |
| 290 if not stanza:get_child("store", "urn:xmpp:hints") then -- No hint telling us we should store | |
| 291 if stanza:get_child("no-permanent-store", "urn:xmpp:hints") | |
| 292 or stanza:get_child("no-store", "urn:xmpp:hints") then -- Hint telling us we should NOT store | |
| 293 log("debug", "Not archiving stanza: %s (hint)", stanza:top_tag()); | |
| 294 return; | |
| 295 end | |
| 296 end | 341 end |
| 297 | 342 |
| 298 local clone_for_storage; | 343 local clone_for_storage; |
| 299 if not strip_tags:empty() then | 344 if not strip_tags:empty() then |
| 300 clone_for_storage = st.clone(stanza); | 345 clone_for_storage = st.clone(stanza); |
| 313 clone_for_storage = stanza; | 358 clone_for_storage = stanza; |
| 314 end | 359 end |
| 315 | 360 |
| 316 -- Check with the users preferences | 361 -- Check with the users preferences |
| 317 if shall_store(store_user, with) then | 362 if shall_store(store_user, with) then |
| 318 log("debug", "Archiving stanza: %s", stanza:top_tag()); | 363 log("debug", "Archiving stanza: %s (%s)", stanza:top_tag(), why); |
| 319 | 364 |
| 320 -- And stash it | 365 -- And stash it |
| 321 local time = time_now(); | 366 local time = time_now(); |
| 322 local ok, err = archive:append(store_user, nil, clone_for_storage, time, with); | 367 local ok, err = archive:append(store_user, nil, clone_for_storage, time, with); |
| 323 if not ok and err == "quota-limit" then | 368 if not ok and err == "quota-limit" then |