Software /
code /
prosody-modules
Changeset
58:b07193056935
mod_privacy: save the part already coded for presence-out/-in getting active stuff but disabled it.
author | Thilo Cestonaro <thilo@cestona.ro> |
---|---|
date | Tue, 20 Oct 2009 20:27:10 +0200 |
parents | 57:cddcea7c091a |
children | 59:50e3d5b87119 |
files | mod_privacy/mod_privacy.lua |
diffstat | 1 files changed, 70 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/mod_privacy/mod_privacy.lua Mon Oct 19 22:43:30 2009 +0200 +++ b/mod_privacy/mod_privacy.lua Tue Oct 20 20:27:10 2009 +0200 @@ -60,6 +60,63 @@ return ret; end +function sendUnavailable(to, from) +--[[ example unavailable presence stanza +<presence from="node@host/resource" type="unavailable" to="node@host" > + <status>Logged out</status> +</presence> +]]-- + local presence = st.presence({from=from, type="unavailable"}) + presence:tag("status"):text("Logged out"); + + local node, host = jid_bare(to); + local bare = node .. "@" .. host; + + if bare_sessions[bare].sessions ~= nil then + for resource, session in pairs(bare_sessions[bare].sessions) do + presence.attr.to = session.full_jid; + module:log("debug", "send unavailable to: %s; from: %s", tostring(presence.attr.to), tostring(presence.attr.from)); + origin.send(presence); + end + end +end + +function sendNeededUnavailablePersences(origin, listnameOrItem) -- TODO implement it correctly! + if type(listnameOrItem) == "string" then + local listname = listnameOrItem; + for _,list in ipairs(privacy_lists.lists) do + if list.name == listname then + for _,item in ipairs(list.items) do + sendNeededUnavailablePersences(origin, item); + end + end + end + elseif type(listnameOrItem) == "table" then + module:log("debug", "got an item, check wether to send unavailable presence stanza or not"); + local item = listnameOrItem; + local serialize = require "util.serialization".serialize; + + + if item["presence-out"] == true then + if item.type == "jid" then + sendUnavailable(item.value, origin.full_jid); + elseif item.type == "group" then + elseif item.type == "subscription" then + elseif item.type == nil then + end + elseif item["presence-in"] == true then + if item.type == "jid" then + sendUnavailable(origin.full_jid, item.value); + elseif item.type == "group" then + elseif item.type == "subscription" then + elseif item.type == nil then + end + end + else + module:log("debug", "got unknown type: %s", type(listnameOrItem)); + end +end + function declineList (privacy_lists, origin, stanza, which) if which == "default" then if isAnotherSessionUsingDefaultList(origin) then @@ -92,9 +149,15 @@ end privacy_lists.default = name; origin.send(st.reply(stanza)); +--[[ + if origin.activePrivacyList == nil then + sendNeededUnavailablePersences(origin, name); + end +]]-- elseif which == "active" and idx ~= nil then origin.activePrivacyList = name; origin.send(st.reply(stanza)); + -- sendNeededUnavailablePersences(origin, name); else return {"modify", "bad-request", "Either not active or default given or unknown list name specified."}; end @@ -204,6 +267,13 @@ return {"cancel", "bad-request", "Action must be either deny or allow."}; end +--[[ + if (privacy_lists.default == name and origin.activePrivacyList == nil) or origin.activePrivacyList == name then + module:log("debug", "calling sendNeededUnavailablePresences!"); + -- item is valid and list is active, so send needed unavailable stanzas + sendNeededUnavailablePersences(origin, tmp); + end +]]-- list.items[#list.items + 1] = tmp; end