Merge 0.10->trunk
[prosody.git] / plugins / mod_blocklist.lua
index dca729f060fe329d29ee8f356c1d4daa9ba21f0f..81bdd2c696f8f6e12c3e8e4f864905c4b4a62436 100644 (file)
@@ -13,7 +13,7 @@ local user_exists = require"core.usermanager".user_exists;
 local is_contact_subscribed = require"core.rostermanager".is_contact_subscribed;
 local st = require"util.stanza";
 local st_error_reply = st.error_reply;
-local jid_prep, jid_split = import("jid", "prep", "split");
+local jid_prep, jid_split = import("util.jid", "prep", "split");
 
 local host = module.host;
 local storage = module:open_store();
@@ -43,7 +43,6 @@ end
 -- Migrates from the old mod_privacy storage
 local function migrate_privacy_list(username)
        local migrated_data = { [false] = "not empty" };
-       module:log("info", "Migrating blocklist from mod_privacy storage for user '%s'", username);
        local legacy_data = module:open_store("privacy"):get(username);
        if legacy_data and legacy_data.lists and legacy_data.default then
                legacy_data = legacy_data.lists[legacy_data.default];
@@ -52,6 +51,7 @@ local function migrate_privacy_list(username)
                return migrated_data;
        end
        if legacy_data then
+               module:log("info", "Migrating blocklist from mod_privacy storage for user '%s'", username);
                local item, jid;
                for i = 1, #legacy_data do
                        item = legacy_data[i];
@@ -149,7 +149,9 @@ local function edit_blocklist(event)
                for jid, in_roster in pairs(new) do
                        if not blocklist[jid] and in_roster and sessions[username] then
                                for _, session in pairs(sessions[username].sessions) do
-                                       module:send(st.presence({ type = "unavailable", to = jid, from = session.full_jid }));
+                                       if session.presence then
+                                               module:send(st.presence({ type = "unavailable", to = jid, from = session.full_jid }));
+                                       end
                                end
                        end
                end
@@ -182,7 +184,7 @@ end);
 -- Buggy clients
 module:hook("iq-error/self/blocklist-push", function (event)
        local type, condition, text = event.stanza:get_error();
-       (event.origin.log or module._log)("warn", "client returned an error in response to notification from mod_%s: %s%s%s", module.name, condition, text and ": " or "", text or "");
+       (event.origin.log or module._log)("warn", "Client returned an error in response to notification from mod_%s: %s%s%s", module.name, condition, text and ": " or "", text or "");
        return true;
 end);