Changeset

9248:1d6a2cc389eb

mod_blocklist: Store timestamp of blocking to allow age to be determined
author Kim Alvefur <zash@zash.se>
date Thu, 15 Feb 2018 03:00:32 +0100
parents 9247:26854d7a4947
children 9249:506aabdb13bc
files plugins/mod_blocklist.lua
diffstat 1 files changed, 7 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- 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;