Last active
August 29, 2015 14:06
-
-
Save legastero/863a78b357b77653ff74 to your computer and use it in GitHub Desktop.
mod_psa.lua
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- NOTE: requires adding resource-hibernate and resource-resumed events to mod_smacks | |
-- TODO: make it reuse the contents of the user's last presence instead of creating a completely new one | |
local st = require "util.stanza"; | |
local core_post_stanza = prosody.core_post_stanza; | |
local xmlns_psa = "urn:xmpp:psa"; | |
module:hook("resource-hibernate", function(event) | |
local session = event.session; | |
module:log("info", "PSA for hibernating session: "..session.full_jid); | |
if session.presence then | |
local pres = st.presence() | |
:tag('state-annotation', { xmlns = xmlns_psa, from = module.host }) | |
:tag('connection-paused'):up() | |
:tag('description'):text('Connection has gone into hibernation'):up() | |
:up(); | |
session:dispatch_stanza(pres); | |
elseif session.directed then | |
local pres = st.presence({from = session.full_jid}) | |
:tag('state-annotation', { xmlns = xmlns_psa, from = module.host }) | |
:tag('connection-paused'):up() | |
:tag('description'):text('Connection has gone into hibernation'):up() | |
:up(); | |
for jid in pairs(session.directed) do | |
pres.attr.to = jid; | |
session:dispatch_stanza(pres); | |
end | |
end | |
end); | |
module:hook("resource-resumed", function(event) | |
local session = event.session; | |
module:log("info", "PSA for resuming session"); | |
if session.presence then | |
local pres = st.presence() | |
:tag('state-annotation', { xmlns = xmlns_psa, from = module.host }):up(); | |
session:dispatch_stanza(pres); | |
elseif session.directed then | |
local pres = st.presence({from = session.full_jid}) | |
:tag('state-annotation', { xmlns = xmlns_psa, from = module.host }):up(); | |
for jid in pairs(session.directed) do | |
pres.attr.to = jid; | |
core_post_stanza(session, pres, true); | |
end | |
end | |
end); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment