Software /
code /
prosody
Changeset
7335:ab7e7d4fe9c1
Merge 0.10->trunk
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Tue, 05 Apr 2016 12:48:36 +0200 |
parents | 7330:89dd1f86a48a (current diff) 7334:566d0a56b37f (diff) |
children | 7338:f8d37227acd7 |
files | |
diffstat | 2 files changed, 35 insertions(+), 12 deletions(-) [+] |
line wrap: on
line diff
--- a/plugins/mod_presence.lua Sun Apr 03 15:53:00 2016 +0200 +++ b/plugins/mod_presence.lua Tue Apr 05 12:48:36 2016 +0200 @@ -357,3 +357,26 @@ session.directed = nil; end end); + +module:hook("roster-item-removed", function (event) + local username = event.username; + local session = event.origin; + local roster = event.roster or session and session.roster; + local jid = event.jid; + local item = event.item; + + local subscription = item and item.subscription or "none"; + local ask = item and item.ask; + local pending = roster and roster[false].pending[jid]; + + if subscription == "both" or subscription == "from" or pending then + core_post_stanza(session, st.presence({type="unsubscribed", from=session.full_jid, to=jid})); + end + + if subscription == "both" or subscription == "to" or ask then + send_presence_of_available_resources(username, module.host, jid, session, st.presence({type="unavailable"})); + core_post_stanza(session, st.presence({type="unsubscribe", from=session.full_jid, to=jid})); + end + +end, -1); +
--- a/plugins/mod_roster.lua Sun Apr 03 15:53:00 2016 +0200 +++ b/plugins/mod_roster.lua Tue Apr 05 12:48:36 2016 +0200 @@ -75,13 +75,9 @@ local roster = session.roster; local r_item = roster[jid]; if r_item then - local to_bare = node and (node.."@"..host) or host; -- bare JID - if r_item.subscription == "both" or r_item.subscription == "from" or roster[false].pending[jid] then - core_post_stanza(session, st.presence({type="unsubscribed", from=session.full_jid, to=to_bare})); - end - if r_item.subscription == "both" or r_item.subscription == "to" or r_item.ask then - core_post_stanza(session, st.presence({type="unsubscribe", from=session.full_jid, to=to_bare})); - end + module:fire_event("roster-item-removed", { + username = node, jid = jid, item = r_item, origin = session, roster = roster, + }); local success, err_type, err_cond, err_msg = rm_remove_from_roster(session, jid); if success then session.send(st.reply(stanza)); @@ -138,16 +134,20 @@ module:hook_global("user-deleted", function(event) local username, host = event.username, event.host; + local origin = event.origin or prosody.hosts[host]; if host ~= module.host then return end local bare = username .. "@" .. host; local roster = rm_load_roster(username, host); for jid, item in pairs(roster) do if jid then - if item.subscription == "both" or item.subscription == "from" or roster[false].pending[jid] then - module:send(st.presence({type="unsubscribed", from=bare, to=jid})); - end - if item.subscription == "both" or item.subscription == "to" or item.ask then - module:send(st.presence({type="unsubscribe", from=bare, to=jid})); + module:fire_event("roster-item-removed", { + username = username, jid = jid, item = item, roster = roster, origin = origin, + }); + else + for jid in pairs(item.pending) do + module:fire_event("roster-item-removed", { + username = username, jid = jid, roster = roster, origin = origin, + }); end end end