X-Git-Url: https://git.enpas.org/?a=blobdiff_plain;f=plugins%2Fmod_presence.lua;h=d4f2f28dff4a4056638514f8612fa8126fe257ac;hb=abea636be5d5a1b40614e77acadadfc16d96feae;hp=ab57a15811ca1e28a208eb026b2a1fdf46fd24a2;hpb=544e05fb68f869526b71194c3bed3edd7311f3fe;p=prosody.git diff --git a/plugins/mod_presence.lua b/plugins/mod_presence.lua index ab57a158..d4f2f28d 100644 --- a/plugins/mod_presence.lua +++ b/plugins/mod_presence.lua @@ -10,7 +10,7 @@ local log = module._log; local require = require; local pairs = pairs; -local t_concat, t_insert = table.concat, table.insert; +local t_concat = table.concat; local s_find = string.find; local tonumber = tonumber; @@ -27,31 +27,9 @@ local NULL = {}; local rostermanager = require "core.rostermanager"; local sessionmanager = require "core.sessionmanager"; -local function select_top_resources(user) - local priority = 0; - local recipients = {}; - for _, session in pairs(user.sessions) do -- find resource with greatest priority - if session.presence then - -- TODO check active privacy list for session - local p = session.priority; - if p > priority then - priority = p; - recipients = {session}; - elseif p == priority then - t_insert(recipients, session); - end - end - end - return recipients; -end -local function recalc_resource_map(user) - if user then - user.top_resources = select_top_resources(user); - if #user.top_resources == 0 then user.top_resources = nil; end - end -end +local recalc_resource_map = require "util.presence".recalc_resource_map; -local ignore_presence_priority = module:get_option("ignore_presence_priority"); +local ignore_presence_priority = module:get_option_boolean("ignore_presence_priority", false); function handle_normal_presence(origin, stanza) if ignore_presence_priority then @@ -379,3 +357,26 @@ module:hook("resource-unbind", function(event) 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); +