2 local full_sessions = full_sessions;
3 local bare_sessions = bare_sessions;
5 local jid_bare = require "util.jid".bare;
6 local user_exists = require "core.usermanager".user_exists;
8 local function process_to_bare(bare, origin, stanza)
9 local sessions = bare_sessions[bare];
11 local t = stanza.attr.type;
12 if t == "error" then return true; end
13 if t == "groupchat" then
14 origin.send(st.error_reply(stanza, "cancel", "service-unavailable"));
19 -- some resources are connected
20 sessions = sessions.sessions;
22 if t == "headline" then
23 for _, session in pairs(sessions) do
24 if session.presence and session.priority >= 0 then
30 -- TODO find top resources willing to accept this message
31 -- TODO then send them each the stanza
34 -- no resources are online
35 if t == "headline" then return true; end -- current policy is to discard headlines
36 -- chat or normal message
37 -- TODO check if the user exists
38 -- TODO if it doesn't, return an error reply
39 -- TODO otherwise, apply the default privacy list
40 -- TODO and store into offline storage
41 -- TODO or maybe the offline store can apply privacy lists
44 module:hook("message/full", function(data)
45 -- message to full JID recieved
46 local origin, stanza = data.origin, data.stanza;
48 local session = full_sessions[stanza.attr.to];
50 -- TODO fire post processing event
53 else -- resource not online
54 return process_to_bare(jid_bare(stanza.attr.to), origin, stanza);
58 module:hook("message/bare", function(data)
59 -- message to bare JID recieved
60 local origin, stanza = data.origin, data.stanza;
62 return process_to_bare(stanza.attr.to or (origin.username..'@'..origin.host), origin, stanza);