mod_mix: Add events and fix <nick> when joining

This commit is contained in:
PapaTutuWawa 2021-02-22 08:45:35 +01:00
parent 08c513a957
commit 15c1179f4d

View File

@ -350,7 +350,7 @@ module:hook("iq-set/bare/"..mix_core_xmlns..":leave", function(event)
return true; return true;
end end
local j, _ = channel:find_participant(from); local j, participant = channel:find_participant(from);
if j == -1 then if j == -1 then
origin.send(st.error_reply(stanza, origin.send(st.error_reply(stanza,
"cancel", "cancel",
@ -379,6 +379,8 @@ module:hook("iq-set/bare/"..mix_core_xmlns..":leave", function(event)
table.remove(channel.participants, j); table.remove(channel.participants, j);
channel:save_state(); channel:save_state();
module:fire_event("mix-channel-leave", { channel = channel, participant = participant });
origin.send(st.reply(stanza):tag("leave", { xmlns = mix_core_xmlns })); origin.send(st.reply(stanza):tag("leave", { xmlns = mix_core_xmlns }));
return true; return true;
end); end);
@ -475,7 +477,9 @@ module:hook("iq-set/bare/"..mix_core_xmlns..":join", function(event)
publish_participant(srv, channel, spid, participant); publish_participant(srv, channel, spid, participant);
channel:save_state(); channel:save_state();
reply:add_child(nick); module:fire_event("mix-channel-join", { channel = channel, participant = participant });
reply:add_child(nick_tag);
reply:tag("x", { xmlns = "jabber:x:data", type = "result" }) reply:tag("x", { xmlns = "jabber:x:data", type = "result" })
:tag("field", { var = "FORM_TYPE", type = "hidden" }) :tag("field", { var = "FORM_TYPE", type = "hidden" })
:tag("value"):text(mix_anon_xmlns):up():up() :tag("value"):text(mix_anon_xmlns):up():up()
@ -524,6 +528,8 @@ module:hook("iq-set/bare/"..mix_core_xmlns..":setnick", function(event)
--local participant = channel.participants[participant_index]; --local participant = channel.participants[participant_index];
publish_participant(srv, channel, channel:get_spid(participant.jid), participant); publish_participant(srv, channel, channel:get_spid(participant.jid), participant);
module:fire_event("mix-change-nick", { channel = channel, participant = participant });
origin.send(st.reply(stanza) origin.send(st.reply(stanza)
:tag("setnick", { xmlns = mix_core_xmlns }) :tag("setnick", { xmlns = mix_core_xmlns })
:tag("nick"):text(nick:get_text())); :tag("nick"):text(nick:get_text()));
@ -628,6 +634,7 @@ module:hook("iq-set/host/"..mix_core_xmlns..":create", function(event)
create_channel(node, from, true); create_channel(node, from, true);
end end
module:log("debug", "Channel %s created with %s as owner", node, from); module:log("debug", "Channel %s created with %s as owner", node, from);
-- TODO: Add an event
origin.send(st.reply(stanza) origin.send(st.reply(stanza)
:tag("create", { xmlns = mix_core_xmlns, channel = node })); :tag("create", { xmlns = mix_core_xmlns, channel = node }));
@ -662,6 +669,7 @@ module:hook("iq-set/host/"..mix_core_xmlns..":destroy", function(event)
end end
table.remove(channels, i); table.remove(channels, i);
module:fire_event("mix-destroy-channel", { channel = channel });
module:log("debug", "Channel %s destroyed", node); module:log("debug", "Channel %s destroyed", node);
origin.send(st.reply(stanza)); origin.send(st.reply(stanza));
@ -703,7 +711,7 @@ module:hook("message/bare", function(event)
message_archive:append(stanza.attr.to, mam_id, msg, time.now()); message_archive:append(stanza.attr.to, mam_id, msg, time.now());
msg.attr.from = channel.jid.."/"..channel:get_spid(from); msg.attr.from = channel.jid.."/"..channel:get_spid(from);
if module:fire_event("mix-broadcast-message", msg) then if module:fire_event("mix-broadcast-message", { message = msg, channel = channel }) then
return true; return true;
end end