[patch] [update] MUC: Check for an existing occupant when a pre-* hook changes the nickname. Fixes #1739.

10 views
Skip to first unread message

John Regan

unread,
Apr 7, 2022, 10:39:06 AM4/7/22
to proso...@googlegroups.com
Hi all - apologies for the double-email, I realized I didn't match the
Prosody style in my previous patch. This is essentially the same, just
with a clearer comment and with semicolons at the end of expressions.
Original description below:

When a user joins a MUC, and a pre-join hook changes their nickname -
it may have been changed into an existing occupant. When this occurs,
the room creates a new occupant, and an existing occupant winds up
being disassociated from the room.

This patch makes the room re-run the existing occupant check when a
nick change has occurred.

Apologies for the git formatting, I don't know mercurial very well - I
just downloaded the latest source, made a git repo, did my changes in
there, and exported as a patch. Hopefully it's easy to apply.

---
plugins/muc/muc.lib.lua | 10 ++++++++++
1 file changed, 10 insertions(+)

diff --git a/plugins/muc/muc.lib.lua b/plugins/muc/muc.lib.lua
index 01427db..9466e73 100644
--- a/plugins/muc/muc.lib.lua
+++ b/plugins/muc/muc.lib.lua
@@ -684,6 +684,16 @@ function room_mt:handle_normal_presence(origin, stanza)
if module:fire_event(event_name, event) then return true; end

local nick_changed = dest_occupant and orig_nick ~= dest_occupant.nick;
+ if nick_changed then
+ -- nick may now be an existing occupant
+ local orig_dest_occupant = dest_occupant;
+ dest_occupant = self:get_occupant_by_nick(dest_occupant.nick);
+ if dest_occupant then
+ is_first_dest_session = false;
+ else
+ dest_occupant = orig_dest_occupant;
+ end
+ end

-- Check for nick conflicts
if dest_occupant ~= nil and not is_first_dest_session
--
2.35.1

John Regan

unread,
Apr 7, 2022, 10:39:06 AM4/7/22
to proso...@googlegroups.com
Hi all - included is a patched for https://issues.prosody.im/1739

When a user joins a MUC, and a pre-join hook changes their nickname -
it may have been changed into an existing occupant. When this occurs,
the room creates a new occupant, and an existing occupant winds up
being disassociated from the room.

This patch makes the room re-run the existing occupant check when a
nick change has occurred.

Apologies for the git formatting, I don't know mercurial very well - I
just downloaded the latest source, made a git repo, did my changes in
there, and exported as a patch. Hopefully it's easy to apply.

---
plugins/muc/muc.lib.lua | 11 +++++++++++
1 file changed, 11 insertions(+)

diff --git a/plugins/muc/muc.lib.lua b/plugins/muc/muc.lib.lua
index 01427db..4902283 100644
--- a/plugins/muc/muc.lib.lua
+++ b/plugins/muc/muc.lib.lua
@@ -684,6 +684,17 @@ function room_mt:handle_normal_presence(origin, stanza)
if module:fire_event(event_name, event) then return true; end

local nick_changed = dest_occupant and orig_nick ~= dest_occupant.nick;
+ if nick_changed then
+ -- nick may have changed into an existing occupant
+ local orig_dest_occupant = dest_occupant
+ dest_occupant = self:get_occupant_by_nick(dest_occupant.nick)
+ if dest_occupant then
+ is_first_dest_session = false;
+ else
+ dest_occupant = orig_dest_occupant
+ end
+ end
+

Kim Alvefur

unread,
Jun 5, 2022, 3:11:50 PM6/5/22
to proso...@googlegroups.com
Hi,

On Thu, Apr 07, 2022 at 09:18:20AM -0400, John Regan wrote:
>When a user joins a MUC, and a pre-join hook changes their nickname -
>it may have been changed into an existing occupant. When this occurs,
>the room creates a new occupant, and an existing occupant winds up
>being disassociated from the room.
>
>This patch makes the room re-run the existing occupant check when a
>nick change has occurred.

Sorry for not replying earlier. Thanks for the patch. It seems to be
fixing the issue described. I'd like to test some other things such as
attempts by other participants to use nicknames already in used by
others and such variations to make sure everything works as intended.
Will most likely merge the patch after that.

>Apologies for the git formatting, I don't know mercurial very well - I
>just downloaded the latest source, made a git repo, did my changes in
>there, and exported as a patch. Hopefully it's easy to apply.

Did you see our page https://prosody.im/doc/contributing ?

--
Regards,
Kim "Zash" Alvefur
Reply all
Reply to author
Forward
0 new messages