Software / code / prosody-modules
Comparison
mod_cloud_notify/mod_cloud_notify.lua @ 4273:8bf83e883593
mod_cloud_notify: Modernize interface to mod_smacks
| author | tmolitor <thilo@eightysoft.de> |
|---|---|
| date | Tue, 24 Nov 2020 01:52:33 +0100 |
| parent | 4221:e5998f53f4ff |
| child | 4295:d44a8d3dd571 |
comparison
equal
deleted
inserted
replaced
| 4272:91b951fb3018 | 4273:8bf83e883593 |
|---|---|
| 405 if notified.unimportant and notified.important then break; end -- stop processing the queue if all push types are exhausted | 405 if notified.unimportant and notified.important then break; end -- stop processing the queue if all push types are exhausted |
| 406 end | 406 end |
| 407 end | 407 end |
| 408 | 408 |
| 409 -- publish on unacked smacks message (use timer to send out push for all stanzas submitted in a row only once) | 409 -- publish on unacked smacks message (use timer to send out push for all stanzas submitted in a row only once) |
| 410 local function process_smacks_stanza(stanza, session) | 410 local function process_smacks_stanza(event) |
| 411 local session = event.origin; | |
| 412 local stanza = event.stanza; | |
| 411 if session.push_identifier then | 413 if session.push_identifier then |
| 414 session.log("debug", "adding new stanza to push_queue"); | |
| 412 if not session.push_queue then session.push_queue = {}; end | 415 if not session.push_queue then session.push_queue = {}; end |
| 413 local queue = session.push_queue; | 416 local queue = session.push_queue; |
| 414 queue[#queue+1] = st.clone(stanza); | 417 queue[#queue+1] = st.clone(stanza); |
| 415 if #queue == 1 then -- first stanza --> start timer | 418 if #queue == 1 then -- first stanza --> start timer |
| 416 session.log("debug", "Invoking cloud handle_notify_request() for newly smacks queued stanza (in a moment)"); | 419 session.log("debug", "Invoking cloud handle_notify_request() for newly smacks queued stanza (in a moment)"); |
| 418 session.log("debug", "Invoking cloud handle_notify_request() for newly smacks queued stanzas (now in timer)"); | 421 session.log("debug", "Invoking cloud handle_notify_request() for newly smacks queued stanzas (now in timer)"); |
| 419 process_stanza_queue(session.push_queue, session, "push"); | 422 process_stanza_queue(session.push_queue, session, "push"); |
| 420 session.push_queue = {}; -- clean up queue after push | 423 session.push_queue = {}; -- clean up queue after push |
| 421 end); | 424 end); |
| 422 end | 425 end |
| 426 else | |
| 427 session.log("debug", "NOT invoking cloud handle_notify_request() for newly smacks queued stanza (session.push_identifier is not set: %s)", session.push_identifier); | |
| 423 end | 428 end |
| 424 return stanza; | 429 return stanza; |
| 425 end | 430 end |
| 426 | 431 |
| 427 -- smacks hibernation is started | 432 -- smacks hibernation is started |
| 429 local session = event.origin; | 434 local session = event.origin; |
| 430 local queue = event.queue; | 435 local queue = event.queue; |
| 431 session.first_hibernated_push = nil; | 436 session.first_hibernated_push = nil; |
| 432 -- process unacked stanzas | 437 -- process unacked stanzas |
| 433 process_stanza_queue(queue, session, "smacks"); | 438 process_stanza_queue(queue, session, "smacks"); |
| 434 -- process future unacked (hibernated) stanzas | |
| 435 filters.add_filter(session, "stanzas/out", process_smacks_stanza, -990); | |
| 436 end | 439 end |
| 437 | 440 |
| 438 -- smacks hibernation is ended | 441 -- smacks hibernation is ended |
| 439 local function restore_session(event) | 442 local function restore_session(event) |
| 440 local session = event.resumed; | 443 local session = event.resumed; |
| 441 if session then -- older smacks module versions send only the "intermediate" session in event.session and no session.resumed one | 444 if session then -- older smacks module versions send only the "intermediate" session in event.session and no session.resumed one |
| 442 filters.remove_filter(session, "stanzas/out", process_smacks_stanza); | |
| 443 if session.awaiting_push_timer then session.awaiting_push_timer:stop(); end | 445 if session.awaiting_push_timer then session.awaiting_push_timer:stop(); end |
| 444 session.first_hibernated_push = nil; | 446 session.first_hibernated_push = nil; |
| 445 end | 447 end |
| 446 end | 448 end |
| 447 | 449 |
| 490 end | 492 end |
| 491 | 493 |
| 492 module:hook("smacks-hibernation-start", hibernate_session); | 494 module:hook("smacks-hibernation-start", hibernate_session); |
| 493 module:hook("smacks-hibernation-end", restore_session); | 495 module:hook("smacks-hibernation-end", restore_session); |
| 494 module:hook("smacks-ack-delayed", ack_delayed); | 496 module:hook("smacks-ack-delayed", ack_delayed); |
| 497 module:hook("smacks-hibernation-stanza-queued", process_smacks_stanza); | |
| 495 module:hook("archive-message-added", archive_message_added); | 498 module:hook("archive-message-added", archive_message_added); |
| 496 | 499 |
| 497 local function send_ping(event) | 500 local function send_ping(event) |
| 498 local user = event.user; | 501 local user = event.user; |
| 499 local push_services = event.push_services or push_store:get(user); | 502 local push_services = event.push_services or push_store:get(user); |
| 504 -- can be used by other modules to ping one or more (or all) push endpoints | 507 -- can be used by other modules to ping one or more (or all) push endpoints |
| 505 module:hook("cloud-notify-ping", send_ping); | 508 module:hook("cloud-notify-ping", send_ping); |
| 506 | 509 |
| 507 module:log("info", "Module loaded"); | 510 module:log("info", "Module loaded"); |
| 508 function module.unload() | 511 function module.unload() |
| 512 module:log("info", "Unloading module"); | |
| 513 -- cleanup some settings, reloading this module can cause process_smacks_stanza() to stop working otherwise | |
| 514 for user, _ in pairs(host_sessions) do | |
| 515 for sessionid, session in pairs(host_sessions[user].sessions) do | |
| 516 if session.awaiting_push_timer then session.awaiting_push_timer:stop(); end | |
| 517 session.awaiting_push_timer = nil; | |
| 518 session.first_hibernated_push = nil; | |
| 519 session.push_queue = nil; | |
| 520 end | |
| 521 end | |
| 509 module:log("info", "Module unloaded"); | 522 module:log("info", "Module unloaded"); |
| 510 end | 523 end |