mod_mix_pam: Use send_to_available_resources instead

This commit is contained in:
PapaTutuWawa 2021-05-24 20:19:55 +02:00
parent 372a4ef18b
commit 5f973c19d0

View File

@ -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);