Comparison

mod_push2/mod_push2.lua @ 5687:4b052598e435

mod_push2: restore offline message hook Filtering is mostly handled in handle_notify_request now
author Stephen Paul Weber <singpolyma@singpolyma.net>
date Thu, 21 Sep 2023 18:47:27 -0500
parent 5686:a1d22d6efb3d
child 5869:83ee752f148c
comparison
equal deleted inserted replaced
5686:a1d22d6efb3d 5687:4b052598e435
379 local node = to and jid.split(to) or session.username 379 local node = to and jid.split(to) or session.username
380 local user_push_services = push2_registrations:get(node) 380 local user_push_services = push2_registrations:get(node)
381 return node, (user_push_services or {}) 381 return node, (user_push_services or {})
382 end 382 end
383 383
384 -- publish on offline message
385 module:hook("message/offline/handle", function(event)
386 local node, user_push_services = get_push_settings(event.stanza, event.origin);
387 module:log("debug", "Invoking handle_notify_request() for offline stanza");
388 handle_notify_request(event.stanza, node, user_push_services, true);
389 end, 1);
390
384 -- publish on bare groupchat 391 -- publish on bare groupchat
385 -- this picks up MUC messages when there are no devices connected 392 -- this picks up MUC messages when there are no devices connected
386 module:hook("message/bare/groupchat", function(event) 393 module:hook("message/bare/groupchat", function(event)
387 local node, user_push_services = get_push_settings(event.stanza, event.origin); 394 local node, user_push_services = get_push_settings(event.stanza, event.origin);
388 local notify_push_services = {}; 395 local notify_push_services = {};
399 handle_notify_request(event.stanza, node, notify_push_services, true); 406 handle_notify_request(event.stanza, node, notify_push_services, true);
400 end, 1); 407 end, 1);
401 408
402 local function process_stanza_queue(queue, session, queue_type) 409 local function process_stanza_queue(queue, session, queue_type)
403 if not session.push_registration_id then return; end 410 if not session.push_registration_id then return; end
404 for _, match in ipairs(session.push_settings.matches) do
405 if match.match == "urn:xmpp:push2:match:archived-with-body" or match.match == "urn:xmpp:push2:match:archived" then
406 module:log("debug", "Not pushing because we are not archiving this stanza: %s", session.push_registration_id)
407 return
408 end
409 end
410 local user_push_services = {[session.push_registration_id] = session.push_settings}; 411 local user_push_services = {[session.push_registration_id] = session.push_settings};
411 local notified = { unimportant = false; important = false } 412 local notified = { unimportant = false; important = false }
412 for i=1, #queue do 413 for i=1, #queue do
413 local stanza = queue[i]; 414 local stanza = queue[i];
414 -- fast ignore of already pushed stanzas 415 -- fast ignore of already pushed stanzas
521 end 522 end
522 523
523 -- archive message added 524 -- archive message added
524 local function archive_message_added(event) 525 local function archive_message_added(event)
525 -- event is: { origin = origin, stanza = stanza, for_user = store_user, id = id } 526 -- event is: { origin = origin, stanza = stanza, for_user = store_user, id = id }
526 if not event.for_user then return; end 527 -- only notify for new mam messages when at least one device is online
528 if not event.for_user or not host_sessions[event.for_user] then return; end
527 -- Note that the stanza in the event is a clone not the same as other hooks, so dedupe doesn't work 529 -- Note that the stanza in the event is a clone not the same as other hooks, so dedupe doesn't work
528 -- This is a problem if you wan to to also hook offline message storage for example 530 -- This is a problem if you wan to to also hook offline message storage for example
529 local stanza = st.clone(event.stanza) 531 local stanza = st.clone(event.stanza)
530 stanza:tag("stanza-id", { xmlns = "urn:xmpp:sid:0", by = event.for_user.."@"..module.host, id = event.id }):up() 532 stanza:tag("stanza-id", { xmlns = "urn:xmpp:sid:0", by = event.for_user.."@"..module.host, id = event.id }):up()
531 local user_session = host_sessions[event.for_user] and host_sessions[event.for_user].sessions or {} 533 local user_session = host_sessions[event.for_user] and host_sessions[event.for_user].sessions or {}
556 break; 558 break;
557 end 559 end
558 end 560 end
559 if identifier_found then 561 if identifier_found then
560 identifier_found.log("debug", "Not pushing '%s' of new MAM stanza (session still alive)", identifier) 562 identifier_found.log("debug", "Not pushing '%s' of new MAM stanza (session still alive)", identifier)
561 elseif not has_body(stanza) then
562 for _, match in ipairs(push_info.matches) do
563 if match.match == "urn:xmpp:push2:match:archived-with-body" then
564 identifier_found.log("debug", "Not pushing '%s' of new MAM stanza (no body)", identifier)
565 else
566 notify_push_services[identifier] = push_info
567 end
568 end
569 else 563 else
570 notify_push_services[identifier] = push_info 564 notify_push_services[identifier] = push_info
571 end 565 end
572 end 566 end
573 end 567 end