# HG changeset patch # User João Duarte # Date 1561076178 -3600 # Node ID cb5e4e07ab1145620d8422b44f74d0a41c5f8ff6 # Parent 08c6540f5a65e60564c3d38482e9e561767cc443# Parent ad640c2e072e27472bde5244d076326f1043875a Merge my line of development->trunk diff -r ad640c2e072e -r cb5e4e07ab11 plugins/mod_blocklist.lua --- a/plugins/mod_blocklist.lua Thu Jun 20 19:17:47 2019 +0100 +++ b/plugins/mod_blocklist.lua Fri Jun 21 01:16:18 2019 +0100 @@ -128,6 +128,7 @@ -- > only if the contact is allowed to receive presence notifications [...] -- So contacts we need to do that for are added to the set below. local send_unavailable = is_blocking and {}; + local send_available = not is_blocking and {}; -- Because blocking someone currently also blocks the ability to reject -- subscription requests, we'll preemptively reject such @@ -147,6 +148,8 @@ elseif is_contact_pending_in(username, module.host, jid) then remove_pending[jid] = true; end + elseif is_contact_subscribed(username, module.host, jid) then + send_available[jid] = true; end end @@ -186,6 +189,7 @@ if is_blocking then for jid in pairs(send_unavailable) do + -- Check that this JID isn't already blocked, i.e. this is not a change if not blocklist[jid] then for _, session in pairs(sessions[username].sessions) do if session.presence then @@ -203,6 +207,11 @@ save_roster(username, module.host, roster); -- Not much we can do about save failing here end + else + local user_bare = username .. "@" .. module.host; + for jid in pairs(send_available) do + module:send(st.presence({ type = "probe", to = user_bare, from = jid })); + end end local blocklist_push = st.iq({ type = "set", id = "blocklist-push" }) diff -r ad640c2e072e -r cb5e4e07ab11 plugins/mod_pep.lua --- a/plugins/mod_pep.lua Thu Jun 20 19:17:47 2019 +0100 +++ b/plugins/mod_pep.lua Fri Jun 21 01:16:18 2019 +0100 @@ -91,6 +91,21 @@ return data, err; end function store:set(node, data) + if data then + -- Save the data without subscriptions + local subscribers = {}; + for jid, sub in pairs(data.subscribers) do + if type(sub) ~= "table" or not sub.presence then + subscribers[jid] = sub; + end + end + data = { + name = data.name; + config = data.config; + affiliations = data.affiliations; + subscribers = subscribers; + }; + end return node_config:set(username, node, data); end function store:users() @@ -124,7 +139,6 @@ if kind == "retract" then kind = "items"; -- XEP-0060 signals retraction in an container end - if item then item = st.clone(item); item.attr.xmlns = nil; -- Clear the pubsub namespace @@ -144,23 +158,8 @@ message:add_child(item); end - local broadcast_to = {}; for jid in pairs(jids) do - broadcast_to[jid] = true; - end - - local service_recipients = recipients[username]; - if service_recipients then - local service = services[username]; - for recipient, nodes in pairs(service_recipients) do - if nodes:contains(node) and service:may(node, recipient, "subscribe") then - broadcast_to[recipient] = true; - end - end - end - - for jid in pairs(broadcast_to) do - module:log("debug", "Sending notification to %s from %s: %s", jid, user_bare, tostring(item)); + module:log("debug", "Sending notification to %s from %s for node %s", jid, user_bare, node); message.attr.to = jid; module:send(message); end @@ -168,6 +167,21 @@ return simple_broadcast; end +local function on_node_creation(event) + local service = event.service; + local node = event.node; + local username = service.config.pep_username; + + local service_recipients = recipients[username]; + if not service_recipients then return; end + + for recipient, nodes in pairs(service_recipients) do + if nodes:contains(node) then + service:add_subscription(node, recipient, recipient, { presence = true }); + end + end +end + function get_pep_service(username) module:log("debug", "get_pep_service(%q)", username); local user_bare = jid_join(username, host); @@ -226,6 +240,11 @@ return service; end +module:hook("item-added/pep-service", function (event) + local service = event.item.service; + module:hook_object_event(service.events, "node-created", on_node_creation); +end); + function handle_pubsub_iq(event) local origin, stanza = event.origin, event.stanza; local service_name = origin.username; @@ -240,6 +259,7 @@ module:hook("iq/bare/"..xmlns_pubsub..":pubsub", handle_pubsub_iq); module:hook("iq/bare/"..xmlns_pubsub_owner..":pubsub", handle_pubsub_iq); + local function get_caps_hash_from_presence(stanza, current) local t = stanza.attr.type; if not t then @@ -288,9 +308,12 @@ end local service = get_pep_service(service_name); + for node in current - nodes do + service:remove_subscription(node, recipient, recipient); + end for node in nodes - current do - if service:may(node, recipient, "subscribe") then + if service:add_subscription(node, recipient, recipient, { presence = true }) then resend_last_item(recipient, node, service); end end diff -r ad640c2e072e -r cb5e4e07ab11 plugins/muc/muc.lib.lua --- a/plugins/muc/muc.lib.lua Thu Jun 20 19:17:47 2019 +0100 +++ b/plugins/muc/muc.lib.lua Fri Jun 21 01:16:18 2019 +0100 @@ -391,7 +391,11 @@ end self:publicise_occupant_status(new_occupant or occupant, x); if is_last_session then - module:fire_event("muc-occupant-left", {room = self; nick = occupant.nick; occupant = occupant;}); + module:fire_event("muc-occupant-left", { + room = self; + nick = occupant.nick; + occupant = occupant; + }); end return true; end @@ -868,7 +872,11 @@ end for occupant in pairs(occupants_updated) do self:publicise_occupant_status(occupant, x); - module:fire_event("muc-occupant-left", { room = self; nick = occupant.nick; occupant = occupant;}); + module:fire_event("muc-occupant-left", { + room = self; + nick = occupant.nick; + occupant = occupant; + }); end end @@ -1316,7 +1324,11 @@ for occupant, old_role in pairs(occupants_updated) do self:publicise_occupant_status(occupant, x, nil, actor, reason); if occupant.role == nil then - module:fire_event("muc-occupant-left", {room = self; nick = occupant.nick; occupant = occupant;}); + module:fire_event("muc-occupant-left", { + room = self; + nick = occupant.nick; + occupant = occupant; + }); elseif is_semi_anonymous and (old_role == "moderator" and occupant.role ~= "moderator") or (old_role ~= "moderator" and occupant.role == "moderator") then -- Has gained or lost moderator status @@ -1432,7 +1444,11 @@ self:save_occupant(occupant); self:publicise_occupant_status(occupant, x, nil, actor, reason); if role == nil then - module:fire_event("muc-occupant-left", {room = self; nick = occupant.nick; occupant = occupant;}); + module:fire_event("muc-occupant-left", { + room = self; + nick = occupant.nick; + occupant = occupant; + }); end return true; end diff -r ad640c2e072e -r cb5e4e07ab11 spec/scansion/blocking.scs --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/spec/scansion/blocking.scs Fri Jun 21 01:16:18 2019 +0100 @@ -0,0 +1,160 @@ +# XEP-0191: Blocking Command + +[Client] Romeo + jid: blocker@localhost + password: password + +[Client] Juliet + jid: blockee@localhost + password: password + +----- + +# The parties connect +Romeo connects + +Romeo sends: + + +Romeo receives: + + +Juliet connects + +Juliet sends: + + +Juliet receives: + + +# They add each other +Romeo sends: + + +Romeo receives: + + +Juliet receives: + + +Juliet sends: + + +Romeo receives: + + + + +Juliet sends: + + +Juliet receives: + + +Romeo receives: + + +Romeo sends: + + +Juliet receives: + + + + +Romeo receives: + + + + +# They can now talk +Juliet sends: + + ohai + + +Romeo receives: + + ohai + + +# And now to the blockining + +Romeo sends: + + + + + + +Romeo receives: + + +Juliet receives: + + +# Can"t talk anymore +Romeo sends: + + hello? + + +Romeo receives: + + + + You have blocked this JID + + + + +Juliet sends: + + +Juliet receives: + + + + + + +Romeo sends: + + + + + + +Juliet receives: + + + + +Romeo receives: + + +# Can talk again +Romeo sends: + + hello! + + +Juliet receives: + + hello! + + +# Bye +Juliet disconnects + +Juliet sends: + + +Romeo receives: + + +Romeo disconnects + +Romeo sends: + + diff -r ad640c2e072e -r cb5e4e07ab11 util/dependencies.lua --- a/util/dependencies.lua Thu Jun 20 19:17:47 2019 +0100 +++ b/util/dependencies.lua Fri Jun 21 01:16:18 2019 +0100 @@ -140,7 +140,7 @@ end local function log_warnings() - if _VERSION > "Lua 5.2" then + if _VERSION > "Lua 5.3" then prosody.log("warn", "Support for %s is experimental, please report any issues", _VERSION); end local ssl = softreq"ssl";