Diff

plugins/muc/lock.lib.lua @ 7408:cf53081ce767

MUC: Use a timestamp to keep track of when to unlock room instead of a timer (so timer does not unlock an evicted room)
author Kim Alvefur <zash@zash.se>
date Thu, 28 Apr 2016 23:20:41 +0200
parent 7407:e465b584547b
child 7999:980606856882
line wrap: on
line diff
--- a/plugins/muc/lock.lib.lua	Thu Apr 28 23:14:09 2016 +0200
+++ b/plugins/muc/lock.lib.lua	Thu Apr 28 23:20:41 2016 +0200
@@ -14,14 +14,19 @@
 
 local function lock(room)
 	module:fire_event("muc-room-locked", {room = room;});
-	room._data.locked = true;
+	room._data.locked = os.time() + lock_room_timeout;
 end
 local function unlock(room)
 	module:fire_event("muc-room-unlocked", {room = room;});
 	room._data.locked = nil;
 end
 local function is_locked(room)
-	return not not room._data.locked;
+	local ts = room._data.locked or false;
+	if ts then
+		if ts < os.time() then return true; end
+		unlock(room);
+	end
+	return false;
 end
 
 if lock_rooms then
@@ -31,13 +36,6 @@
 		-- Lock room at creation
 		local room = event.room;
 		lock(room);
-		if lock_room_timeout and lock_room_timeout > 0 then
-			module:add_timer(lock_room_timeout, function ()
-				if is_locked(room) then
-					room:destroy(); -- Not unlocked in time
-				end
-			end);
-		end
 	end, 10);
 end