From 6280a047f6766dbf0423b5e76107d5c624f96e54 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Thu, 8 Dec 2016 18:13:56 +0100 Subject: mod_blocklist: Make the 'false' metadata field a table so we can store timestamps and other useful data --- plugins/mod_blocklist.lua | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'plugins') diff --git a/plugins/mod_blocklist.lua b/plugins/mod_blocklist.lua index 9083dda4..f0b305d6 100644 --- a/plugins/mod_blocklist.lua +++ b/plugins/mod_blocklist.lua @@ -54,7 +54,7 @@ end -- Migrates from the old mod_privacy storage local function migrate_privacy_list(username) - local migrated_data = { [false] = "not empty" }; + local migrated_data = { [false] = { created = os.time(); migrated = "privacy" }}; 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]; @@ -160,18 +160,23 @@ local function edit_blocklist(event) local blocklist = get_blocklist(username); - local new_blocklist = {}; + 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(); }; + }; + if type(blocklist[false]) == "table" then + new_blocklist[false].modified = os.time(); + end if is_blocking or next(new) then for jid in pairs(blocklist) do - new_blocklist[jid] = true; + if jid then new_blocklist[jid] = true; end end for jid in pairs(new) do new_blocklist[jid] = is_blocking; end -- else empty the blocklist end - new_blocklist[false] = "not empty"; -- In order to avoid doing the migration thing twice local ok, err = set_blocklist(username, new_blocklist); if ok then -- cgit v1.2.3 From 12325f7354c8899596b32d8aa41e87d62eefbf0b Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Mon, 5 Dec 2016 17:22:12 +0100 Subject: mod_blocklist: Return early from migration if no valid privacy list data is found --- plugins/mod_blocklist.lua | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) (limited to 'plugins') diff --git a/plugins/mod_blocklist.lua b/plugins/mod_blocklist.lua index f0b305d6..e2dd8117 100644 --- a/plugins/mod_blocklist.lua +++ b/plugins/mod_blocklist.lua @@ -54,14 +54,13 @@ end -- Migrates from the old mod_privacy storage local function migrate_privacy_list(username) - local migrated_data = { [false] = { created = os.time(); migrated = "privacy" }}; 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]; - legacy_data = legacy_data and legacy_data.items; - else - return migrated_data; - end + if not legacy_data or not legacy_data.lists or not legacy_data.default then return; end + local default_list = legacy_data.lists[legacy_data.default]; + if not default_list or not default_list.items then return; end + + local migrated_data = { [false] = { created = os.time(); migrated = "privacy" }}; + if legacy_data then module:log("info", "Migrating blocklist from mod_privacy storage for user '%s'", username); local item, jid; @@ -94,6 +93,9 @@ local function get_blocklist(username) if not blocklist then blocklist = migrate_privacy_list(username); end + if not blocklist then + blocklist = { [false] = { created = os.time(); }; }; + end cache2:set(username, blocklist); end cache[username] = blocklist; -- cgit v1.2.3 From b7d32f055302f1cd90d2ab9125ac0ba71bc80b9a Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Mon, 5 Dec 2016 17:25:02 +0100 Subject: mod_blocklist: Remove one indentation level --- plugins/mod_blocklist.lua | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) (limited to 'plugins') diff --git a/plugins/mod_blocklist.lua b/plugins/mod_blocklist.lua index e2dd8117..f5198108 100644 --- a/plugins/mod_blocklist.lua +++ b/plugins/mod_blocklist.lua @@ -61,18 +61,16 @@ local function migrate_privacy_list(username) local migrated_data = { [false] = { created = os.time(); migrated = "privacy" }}; - 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]; - if item.type == "jid" and item.action == "deny" then - jid = jid_prep(item.value); - if not jid then - module:log("warn", "Invalid JID in privacy store for user '%s' not migrated: %s", username, tostring(item.value)); - else - migrated_data[jid] = true; - end + 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]; + if item.type == "jid" and item.action == "deny" then + jid = jid_prep(item.value); + if not jid then + module:log("warn", "Invalid JID in privacy store for user '%s' not migrated: %s", username, tostring(item.value)); + else + migrated_data[jid] = true; end end end -- cgit v1.2.3 From 088d53b68f48faa00d798adccdbf4fbf8831e5be Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Thu, 8 Dec 2016 18:06:18 +0100 Subject: mod_blocklist: Simplify loop with ipairs --- plugins/mod_blocklist.lua | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'plugins') diff --git a/plugins/mod_blocklist.lua b/plugins/mod_blocklist.lua index f5198108..2233045e 100644 --- a/plugins/mod_blocklist.lua +++ b/plugins/mod_blocklist.lua @@ -62,11 +62,9 @@ local function migrate_privacy_list(username) local migrated_data = { [false] = { created = os.time(); migrated = "privacy" }}; 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]; + for _, item in ipairs(default_list.items) do if item.type == "jid" and item.action == "deny" then - jid = jid_prep(item.value); + local jid = jid_prep(item.value); if not jid then module:log("warn", "Invalid JID in privacy store for user '%s' not migrated: %s", username, tostring(item.value)); else -- cgit v1.2.3 From 9ac77204baa77df1d42db6f713219601a7bd4e78 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Mon, 5 Dec 2016 17:35:38 +0100 Subject: mod_blocklist: Check first level cache before calling blocklist getter --- plugins/mod_blocklist.lua | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) (limited to 'plugins') diff --git a/plugins/mod_blocklist.lua b/plugins/mod_blocklist.lua index 2233045e..283d52fa 100644 --- a/plugins/mod_blocklist.lua +++ b/plugins/mod_blocklist.lua @@ -77,10 +77,7 @@ local function migrate_privacy_list(username) end local function get_blocklist(username) - local blocklist = cache[username]; - if not blocklist then - blocklist = cache2:get(username); - end + local blocklist = cache2:get(username); if not blocklist then if not user_exists(username, module.host) then return null_blocklist; @@ -102,7 +99,7 @@ module:hook("iq-get/self/urn:xmpp:blocking:blocklist", function (event) local origin, stanza = event.origin, event.stanza; local username = origin.username; local reply = st.reply(stanza):tag("blocklist", { xmlns = "urn:xmpp:blocking" }); - local blocklist = get_blocklist(username); + local blocklist = cache[username] or get_blocklist(username); for jid in pairs(blocklist) do if jid then reply:tag("item", { jid = jid }):up(); @@ -156,7 +153,7 @@ local function edit_blocklist(event) return true; end - local blocklist = get_blocklist(username); + local blocklist = cache[username] or get_blocklist(username); local new_blocklist = { -- We set the [false] key to someting as a signal not to migrate privacy lists -- cgit v1.2.3 From f9869506eda3fd6248487a7033a40ca2a949e783 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Thu, 8 Dec 2016 17:51:23 +0100 Subject: mod_carbons: Rename some variables for clarity --- plugins/mod_carbons.lua | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'plugins') diff --git a/plugins/mod_carbons.lua b/plugins/mod_carbons.lua index 4984b908..cb7d9233 100644 --- a/plugins/mod_carbons.lua +++ b/plugins/mod_carbons.lua @@ -24,21 +24,23 @@ local function message_handler(event, c2s) local origin, stanza = event.origin, event.stanza; local orig_type = stanza.attr.type or "normal"; local orig_from = stanza.attr.from; + local bare_from = jid_bare(orig_from); local orig_to = stanza.attr.to; - + local bare_to = jid_bare(orig_to); + if not(orig_type == "chat" or (orig_type == "normal" and stanza:get_child("body"))) then return -- Only chat type messages end -- Stanza sent by a local client - local bare_jid = jid_bare(orig_from); + local bare_jid = bare_from; -- JID of the local user local target_session = origin; local top_priority = false; - local user_sessions = bare_sessions[bare_jid]; + local user_sessions = bare_sessions[bare_from]; -- Stanza about to be delivered to a local client if not c2s then - bare_jid = jid_bare(orig_to); + bare_jid = bare_to; target_session = full_sessions[orig_to]; user_sessions = bare_sessions[bare_jid]; if not target_session and user_sessions then -- cgit v1.2.3 From 1dbe1533ec336146aead43fca58952d06174e67c Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Thu, 8 Dec 2016 20:49:35 +0100 Subject: mod_presence: Send probe once subscribed (fixes #794) --- plugins/mod_presence.lua | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'plugins') diff --git a/plugins/mod_presence.lua b/plugins/mod_presence.lua index a5b4f282..6df56fe0 100644 --- a/plugins/mod_presence.lua +++ b/plugins/mod_presence.lua @@ -201,7 +201,9 @@ function handle_outbound_presence_subscriptions_and_probes(origin, stanza, from_ end core_post_stanza(origin, stanza); send_presence_of_available_resources(node, host, to_bare, origin); - core_post_stanza(origin, st.presence({ type = "probe", from = from_bare, to = to_bare })); + if rostermanager.is_user_subscribed(node, host, to_bare) then + core_post_stanza(origin, st.presence({ type = "probe", from = from_bare, to = to_bare })); + end elseif stanza.attr.type == "unsubscribed" then -- 1. send unavailable -- 2. route stanza -- cgit v1.2.3