From 5b6d7a3040458ce290c50276883f6a6cf841e59c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=94=D0=B0=D0=BC=D1=8F=D0=BD=20=D0=9C=D0=B8=D0=BD=D0=BA?= =?UTF-8?q?=D0=BE=D0=B2?= Date: Wed, 23 Aug 2017 16:14:44 -0500 Subject: [PATCH] Skips creating duplicate poltergeists for the same user. (#1925) --- .../prosody-plugins/mod_muc_poltergeist.lua | 20 ++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/resources/prosody-plugins/mod_muc_poltergeist.lua b/resources/prosody-plugins/mod_muc_poltergeist.lua index 8e59d0c4a..0b18eee27 100644 --- a/resources/prosody-plugins/mod_muc_poltergeist.lua +++ b/resources/prosody-plugins/mod_muc_poltergeist.lua @@ -393,13 +393,19 @@ function handle_create_poltergeist (event) return 404; end - local username = generate_uuid(); - store_username(room, user_id, username) - - create_poltergeist_occupant( - room, string.sub(username,0,8), name, avatar, status); - - return 200; + local username = get_username(room, user_id); + if (username ~= nil + and have_poltergeist_occupant(room, string.sub(username, 0, 8))) then + log("warn", "poltergeist for username:%s already in the room:%s", + username, room_name); + return 202; + else + username = generate_uuid(); + store_username(room, user_id, username); + create_poltergeist_occupant( + room, string.sub(username, 0, 8), name, avatar, status); + return 200; + end end --- Handles request for updating poltergeists status