Software /
code /
prosody
Comparison
plugins/mod_blocklist.lua @ 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 |
parent | 8741:0fd63ed1f647 |
child | 9993:02a41315d275 |
child | 10052:0c35f353db68 |
comparison
equal
deleted
inserted
replaced
9247:26854d7a4947 | 9248:1d6a2cc389eb |
---|---|
112 end, -1); | 112 end, -1); |
113 | 113 |
114 -- Add or remove some jid(s) from the blocklist | 114 -- Add or remove some jid(s) from the blocklist |
115 -- We want this to be atomic and not do a partial update | 115 -- We want this to be atomic and not do a partial update |
116 local function edit_blocklist(event) | 116 local function edit_blocklist(event) |
117 local now = os.time(); | |
117 local origin, stanza = event.origin, event.stanza; | 118 local origin, stanza = event.origin, event.stanza; |
118 local username = origin.username; | 119 local username = origin.username; |
119 local action = stanza.tags[1]; -- "block" or "unblock" | 120 local action = stanza.tags[1]; -- "block" or "unblock" |
120 local is_blocking = action.name == "block" or nil; -- nil if unblocking | 121 local is_blocking = action.name == "block" and now or nil; -- nil if unblocking |
121 local new = {}; -- JIDs to block depending or unblock on action | 122 local new = {}; -- JIDs to block depending or unblock on action |
123 | |
122 | 124 |
123 -- XEP-0191 sayeth: | 125 -- XEP-0191 sayeth: |
124 -- > When the user blocks communications with the contact, the user's | 126 -- > When the user blocks communications with the contact, the user's |
125 -- > server MUST send unavailable presence information to the contact (but | 127 -- > server MUST send unavailable presence information to the contact (but |
126 -- > only if the contact is allowed to receive presence notifications [...] | 128 -- > only if the contact is allowed to receive presence notifications [...] |
156 | 158 |
157 local blocklist = cache[username] or get_blocklist(username); | 159 local blocklist = cache[username] or get_blocklist(username); |
158 | 160 |
159 local new_blocklist = { | 161 local new_blocklist = { |
160 -- We set the [false] key to someting as a signal not to migrate privacy lists | 162 -- We set the [false] key to someting as a signal not to migrate privacy lists |
161 [false] = blocklist[false] or { created = os.time(); }; | 163 [false] = blocklist[false] or { created = now; }; |
162 }; | 164 }; |
163 if type(blocklist[false]) == "table" then | 165 if type(blocklist[false]) == "table" then |
164 new_blocklist[false].modified = os.time(); | 166 new_blocklist[false].modified = now; |
165 end | 167 end |
166 | 168 |
167 if is_blocking or next(new) then | 169 if is_blocking or next(new) then |
168 for jid in pairs(blocklist) do | 170 for jid, t in pairs(blocklist) do |
169 if jid then new_blocklist[jid] = true; end | 171 if jid then new_blocklist[jid] = t; end |
170 end | 172 end |
171 for jid in pairs(new) do | 173 for jid in pairs(new) do |
172 new_blocklist[jid] = is_blocking; | 174 new_blocklist[jid] = is_blocking; |
173 end | 175 end |
174 -- else empty the blocklist | 176 -- else empty the blocklist |