From 5f973c19d0d1ea94f55da96f4f5cd6459c85a774 Mon Sep 17 00:00:00 2001 From: Alexander PapaTutuWawa Date: Mon, 24 May 2021 20:19:55 +0200 Subject: [PATCH] mod_mix_pam: Use send_to_available_resources instead --- mod_mix_pam/mod_mix_pam.lua | 18 ++++-------------- 1 file changed, 4 insertions(+), 14 deletions(-) diff --git a/mod_mix_pam/mod_mix_pam.lua b/mod_mix_pam/mod_mix_pam.lua index efa5bf5..b67a228 100644 --- a/mod_mix_pam/mod_mix_pam.lua +++ b/mod_mix_pam/mod_mix_pam.lua @@ -1,12 +1,8 @@ local module_host = module:get_host(); ---[[ -if module_host ~= "*" then - module:log("error", "mix_pam should be used on the user host!"); -end -]]-- local jid = require("util.jid"); local st = require("util.stanza"); +local send_to_available_resources = require("core.sessionmanager").send_to_available_resources; local rm_remove_from_roster = require("core.rostermanager").remove_from_roster; local rm_add_to_roster = require("core.rostermanager").add_to_roster; local rm_roster_push = require("core.rostermanager").roster_push; @@ -98,7 +94,6 @@ local function handle_client_join(event) -- Client requests to join module:log("debug", "client-join received"); local stanza, origin = event.stanza, event.origin; - local from = jid.bare(stanza.attr.from); local client_join = stanza:get_child("client-join", mix_pam_xmlns); if client_join.attr.channel == nil then @@ -130,7 +125,6 @@ local function handle_client_leave(event) -- Client requests to leave module:log("debug", "client-leave received"); local stanza, origin = event.stanza, event.origin; - local from = jid.bare(stanza.attr.from); local client_leave = stanza:get_child("client-leave", mix_pam_xmlns); if client_leave.attr.channel == nil then @@ -293,12 +287,8 @@ module:hook("message/bare", function(event) if not is_mix_message(stanza) then return; end -- Per XEP we know that stanza.attr.to is the user's bare JID - for _, session in pairs(prosody.bare_sessions[stanza.attr.to].sessions) do - -- TODO: Only send to resources that advertise support for MIX (When MIX clients are available for testing) - local msg = st.clone(stanza); - msg.attr.to = stanza.attr.to.."/"..session.resource; - session:send(msg); - module:log("debug", "Sent message to %s", msg.attr.to); - end + -- TODO: Only send to resources that advertise support for MIX (When MIX clients are available for testing) + local to = stanza.attr.to; + send_to_available_resources(jid.node(to), jid.host(to), stanza); return true; end);