2 -- Copyright (C) 2014 Florian Zeitz
4 -- This project is MIT/X11 licensed. Please see the
5 -- COPYING file in the source package for more information.
8 local presence
= module
:depends("presence");
9 local send_presence_of_available_resources
= presence
.send_presence_of_available_resources
;
11 local hosts
= prosody
.hosts
;
12 local core_post_stanza
= prosody
.core_post_stanza
;
14 local st
= require
"util.stanza";
15 local is_admin
= require
"core.usermanager".is_admin
;
16 local jid_split
= require
"util.jid".split
;
18 module
:hook("presence/bare", function(data
)
19 local origin
, stanza
= data
.origin
, data
.stanza
;
20 local to
, from
, type = stanza
.attr
.to
, stanza
.attr
.from
, stanza
.attr
.type;
21 local node
, host
= jid_split(to
);
23 if type ~= "probe" then return; end
24 if not is_admin(from
, module
.host
) then return; end
26 if 0 == send_presence_of_available_resources(node
, host
, from
, origin
) then
27 core_post_stanza(hosts
[host
], st
.presence({from
=to
, to
=from
, type="unavailable"}), true);