Mercurial > prosody-modules
comparison mod_push2/mod_push2.lua @ 6157:c887820cd884
Check both localpart and host
In case sending a message to someone with same username as you
| author | Stephen Paul Weber <singpolyma@singpolyma.net> |
|---|---|
| date | Mon, 03 Feb 2025 17:04:23 -0500 |
| parents | 9b50ee822638 |
| children | 1cf563a94620 |
comparison
equal
deleted
inserted
replaced
| 6156:56d1e059f68c | 6157:c887820cd884 |
|---|---|
| 507 -- This is a problem if you wan to to also hook offline message storage for example | 507 -- This is a problem if you wan to to also hook offline message storage for example |
| 508 local stanza = st.clone(event.stanza) | 508 local stanza = st.clone(event.stanza) |
| 509 stanza:tag("stanza-id", { xmlns = "urn:xmpp:sid:0", by = event.for_user.."@"..module.host, id = event.id }):up() | 509 stanza:tag("stanza-id", { xmlns = "urn:xmpp:sid:0", by = event.for_user.."@"..module.host, id = event.id }):up() |
| 510 local user_session = host_sessions[event.for_user] and host_sessions[event.for_user].sessions or {} | 510 local user_session = host_sessions[event.for_user] and host_sessions[event.for_user].sessions or {} |
| 511 local to = stanza.attr.to | 511 local to = stanza.attr.to |
| 512 to = to and jid.split(to) or event.origin.username | 512 local to_user, to_host = to and jid.split(to) |
| 513 to_user = to_user or event.origin.username | |
| 514 to_host = to_host or module.host | |
| 513 | 515 |
| 514 -- only notify if the stanza destination is the mam user we store it for | 516 -- only notify if the stanza destination is the mam user we store it for |
| 515 if event.for_user == to then | 517 if event.for_user == to_user and to_host == module.host then |
| 516 local user_push_services = push2_registrations:get(to) or {} | 518 local user_push_services = push2_registrations:get(to_user) or {} |
| 517 | 519 |
| 518 -- Urgent stanzas are time-sensitive (e.g. calls) and should | 520 -- Urgent stanzas are time-sensitive (e.g. calls) and should |
| 519 -- be pushed immediately to avoid getting stuck in the smacks | 521 -- be pushed immediately to avoid getting stuck in the smacks |
| 520 -- queue in case of dead connections, for example | 522 -- queue in case of dead connections, for example |
| 521 local is_voip_stanza, urgent_reason = is_voip(stanza); | 523 local is_voip_stanza, urgent_reason = is_voip(stanza); |
| 522 | 524 |
| 523 local notify_push_services; | 525 local notify_push_services; |
| 524 if is_voip_stanza then | 526 if is_voip_stanza then |
| 525 module:log("debug", "Urgent push for %s (%s)", to, urgent_reason); | 527 module:log("debug", "Urgent push for %s@%s (%s)", to_user, to_host, urgent_reason); |
| 526 notify_push_services = user_push_services; | 528 notify_push_services = user_push_services; |
| 527 else | 529 else |
| 528 -- only notify nodes with no active sessions (smacks is counted as active and handled separate) | 530 -- only notify nodes with no active sessions (smacks is counted as active and handled separate) |
| 529 notify_push_services = {}; | 531 notify_push_services = {}; |
| 530 for identifier, push_info in pairs(user_push_services) do | 532 for identifier, push_info in pairs(user_push_services) do |
| 541 notify_push_services[identifier] = push_info | 543 notify_push_services[identifier] = push_info |
| 542 end | 544 end |
| 543 end | 545 end |
| 544 end | 546 end |
| 545 | 547 |
| 546 handle_notify_request(stanza, to, notify_push_services, true); | 548 handle_notify_request(stanza, to_user, notify_push_services, true); |
| 547 end | 549 end |
| 548 end | 550 end |
| 549 | 551 |
| 550 module:hook("smacks-hibernation-start", hibernate_session); | 552 module:hook("smacks-hibernation-start", hibernate_session); |
| 551 module:hook("smacks-hibernation-end", restore_session); | 553 module:hook("smacks-hibernation-end", restore_session); |
