Comparison

plugins/mod_blocklist.lua @ 7771:2b288dab781a

mod_blocklist: Make the 'false' metadata field a table so we can store timestamps and other useful data
author Kim Alvefur <zash@zash.se>
date Thu, 08 Dec 2016 18:13:56 +0100
parent 7621:b8c03df6e8ca
child 7772:752697d68fda
comparison
equal deleted inserted replaced
7770:f0024972489e 7771:2b288dab781a
52 return true; 52 return true;
53 end 53 end
54 54
55 -- Migrates from the old mod_privacy storage 55 -- Migrates from the old mod_privacy storage
56 local function migrate_privacy_list(username) 56 local function migrate_privacy_list(username)
57 local migrated_data = { [false] = "not empty" }; 57 local migrated_data = { [false] = { created = os.time(); migrated = "privacy" }};
58 local legacy_data = module:open_store("privacy"):get(username); 58 local legacy_data = module:open_store("privacy"):get(username);
59 if legacy_data and legacy_data.lists and legacy_data.default then 59 if legacy_data and legacy_data.lists and legacy_data.default then
60 legacy_data = legacy_data.lists[legacy_data.default]; 60 legacy_data = legacy_data.lists[legacy_data.default];
61 legacy_data = legacy_data and legacy_data.items; 61 legacy_data = legacy_data and legacy_data.items;
62 else 62 else
158 return true; 158 return true;
159 end 159 end
160 160
161 local blocklist = get_blocklist(username); 161 local blocklist = get_blocklist(username);
162 162
163 local new_blocklist = {}; 163 local new_blocklist = {
164 -- We set the [false] key to someting as a signal not to migrate privacy lists
165 [false] = blocklist[false] or { created = os.time(); };
166 };
167 if type(blocklist[false]) == "table" then
168 new_blocklist[false].modified = os.time();
169 end
164 170
165 if is_blocking or next(new) then 171 if is_blocking or next(new) then
166 for jid in pairs(blocklist) do 172 for jid in pairs(blocklist) do
167 new_blocklist[jid] = true; 173 if jid then new_blocklist[jid] = true; end
168 end 174 end
169 for jid in pairs(new) do 175 for jid in pairs(new) do
170 new_blocklist[jid] = is_blocking; 176 new_blocklist[jid] = is_blocking;
171 end 177 end
172 -- else empty the blocklist 178 -- else empty the blocklist
173 end 179 end
174 new_blocklist[false] = "not empty"; -- In order to avoid doing the migration thing twice
175 180
176 local ok, err = set_blocklist(username, new_blocklist); 181 local ok, err = set_blocklist(username, new_blocklist);
177 if ok then 182 if ok then
178 origin.send(st.reply(stanza)); 183 origin.send(st.reply(stanza));
179 else 184 else