diff --git a/resources/prosody-plugins/mod_fmuc.lua b/resources/prosody-plugins/mod_fmuc.lua index cc99ac8686..ee617486a6 100644 --- a/resources/prosody-plugins/mod_fmuc.lua +++ b/resources/prosody-plugins/mod_fmuc.lua @@ -211,6 +211,20 @@ local function cancel_destroy_timer(room) end end +local function destroy_with_conference_ended(room) + -- if the room is being destroyed, ignore + if room.destroying then + return; + end + + cancel_destroy_timer(room); + + local main_count, visitors_count = get_occupant_counts(room); + module:log('info', 'Will destroy:%s main_occupants:%s visitors:%s', room.jid, main_count, visitors_count); + room:destroy(nil, 'Conference ended.'); + return true; +end + -- schedules a new destroy timer which will destroy the room if there are no visitors after the timeout local function schedule_destroy_timer(room) cancel_destroy_timer(room); @@ -271,6 +285,10 @@ module:hook('muc-occupant-left', function (event) if visitors_count == 0 then schedule_destroy_timer(room); end + + if main_count == 0 then + destroy_with_conference_ended(room); + end end); -- forward visitor presences to jicofo @@ -407,7 +425,6 @@ local function stanza_handler(event) local room = get_room_from_jid(room_jid_match_rewrite(room_jid)); if not room then - module:log('warn', 'No room found %s in stanza_handler', room_jid); return; end @@ -619,12 +636,7 @@ local function iq_from_main_handler(event) respond_iq_result(origin, stanza); if process_disconnect then - cancel_destroy_timer(room); - - local main_count, visitors_count = get_occupant_counts(room); - module:log('info', 'Will destroy:%s main_occupants:%s visitors:%s', room.jid, main_count, visitors_count); - room:destroy(nil, 'Conference ended.'); - return true; + return destroy_with_conference_ended(room); end -- if there is password supplied use it