mod_blocklist: Store timestamp of blocking to allow age to be determined
authorKim Alvefur <zash@zash.se>
Thu, 15 Feb 2018 03:00:32 +0100
changeset 9251 1d6a2cc389eb
parent 9250 26854d7a4947
child 9252 506aabdb13bc
mod_blocklist: Store timestamp of blocking to allow age to be determined
plugins/mod_blocklist.lua
--- a/plugins/mod_blocklist.lua	Sat Sep 01 21:18:30 2018 +0200
+++ b/plugins/mod_blocklist.lua	Thu Feb 15 03:00:32 2018 +0100
@@ -114,12 +114,14 @@
 -- Add or remove some jid(s) from the blocklist
 -- We want this to be atomic and not do a partial update
 local function edit_blocklist(event)
+	local now = os.time();
 	local origin, stanza = event.origin, event.stanza;
 	local username = origin.username;
 	local action = stanza.tags[1]; -- "block" or "unblock"
-	local is_blocking = action.name == "block" or nil; -- nil if unblocking
+	local is_blocking = action.name == "block" and now or nil; -- nil if unblocking
 	local new = {}; -- JIDs to block depending or unblock on action
 
+
 	-- XEP-0191 sayeth:
 	-- > When the user blocks communications with the contact, the user's
 	-- > server MUST send unavailable presence information to the contact (but
@@ -158,15 +160,15 @@
 
 	local new_blocklist = {
 		-- We set the [false] key to someting as a signal not to migrate privacy lists
-		[false] = blocklist[false] or { created = os.time(); };
+		[false] = blocklist[false] or { created = now; };
 	};
 	if type(blocklist[false]) == "table" then
-		new_blocklist[false].modified = os.time();
+		new_blocklist[false].modified = now;
 	end
 
 	if is_blocking or next(new) then
-		for jid in pairs(blocklist) do
-			if jid then new_blocklist[jid] = true; end
+		for jid, t in pairs(blocklist) do
+			if jid then new_blocklist[jid] = t; end
 		end
 		for jid in pairs(new) do
 			new_blocklist[jid] = is_blocking;