Software /
code /
prosody
Comparison
plugins/mod_blocklist.lua @ 7772:752697d68fda
mod_blocklist: Return early from migration if no valid privacy list data is found
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Mon, 05 Dec 2016 17:22:12 +0100 |
parent | 7771:2b288dab781a |
child | 7773:7fd26815fcf6 |
comparison
equal
deleted
inserted
replaced
7771:2b288dab781a | 7772:752697d68fda |
---|---|
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 legacy_data = module:open_store("privacy"):get(username); | |
58 if not legacy_data or not legacy_data.lists or not legacy_data.default then return; end | |
59 local default_list = legacy_data.lists[legacy_data.default]; | |
60 if not default_list or not default_list.items then return; end | |
61 | |
57 local migrated_data = { [false] = { created = os.time(); migrated = "privacy" }}; | 62 local migrated_data = { [false] = { created = os.time(); migrated = "privacy" }}; |
58 local legacy_data = module:open_store("privacy"):get(username); | 63 |
59 if legacy_data and legacy_data.lists and legacy_data.default then | |
60 legacy_data = legacy_data.lists[legacy_data.default]; | |
61 legacy_data = legacy_data and legacy_data.items; | |
62 else | |
63 return migrated_data; | |
64 end | |
65 if legacy_data then | 64 if legacy_data then |
66 module:log("info", "Migrating blocklist from mod_privacy storage for user '%s'", username); | 65 module:log("info", "Migrating blocklist from mod_privacy storage for user '%s'", username); |
67 local item, jid; | 66 local item, jid; |
68 for i = 1, #legacy_data do | 67 for i = 1, #legacy_data do |
69 item = legacy_data[i]; | 68 item = legacy_data[i]; |
92 end | 91 end |
93 blocklist = storage:get(username); | 92 blocklist = storage:get(username); |
94 if not blocklist then | 93 if not blocklist then |
95 blocklist = migrate_privacy_list(username); | 94 blocklist = migrate_privacy_list(username); |
96 end | 95 end |
96 if not blocklist then | |
97 blocklist = { [false] = { created = os.time(); }; }; | |
98 end | |
97 cache2:set(username, blocklist); | 99 cache2:set(username, blocklist); |
98 end | 100 end |
99 cache[username] = blocklist; | 101 cache[username] = blocklist; |
100 return blocklist; | 102 return blocklist; |
101 end | 103 end |