plugins/mod_message.lua
changeset 1272 28f9041d8c55
parent 1271 e78c161944ab
child 1274 50babb72edac
equal deleted inserted replaced
1271:e78c161944ab 1272:28f9041d8c55
     5 local jid_bare = require "util.jid".bare;
     5 local jid_bare = require "util.jid".bare;
     6 local user_exists = require "core.usermanager".user_exists;
     6 local user_exists = require "core.usermanager".user_exists;
     7 
     7 
     8 local function process_to_bare(bare, origin, stanza)
     8 local function process_to_bare(bare, origin, stanza)
     9 	local sessions = bare_sessions[bare];
     9 	local sessions = bare_sessions[bare];
    10 	if sessions then sessions = sessions.sessions; end
       
    11 	
    10 	
       
    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"));
       
    15 		return true;
       
    16 	end
       
    17 
    12 	if sessions then
    18 	if sessions then
    13 		-- some resources are online
    19 		-- some resources are connected
       
    20 		sessions = sessions.sessions;
       
    21 		
       
    22 		if t == "headline" then
       
    23 			for _, session in pairs(sessions) do
       
    24 				if session.presence and session.priority >= 0 then
       
    25 					session.send(stanza);
       
    26 				end
       
    27 			end
       
    28 			return true;
       
    29 		end
    14 		-- TODO find top resources willing to accept this message
    30 		-- TODO find top resources willing to accept this message
    15 		-- TODO then send them each the stanza
    31 		-- TODO then send them each the stanza
    16 	else
    32 		return;
    17 		-- no resources are online
       
    18 		-- TODO check if the user exists
       
    19 		-- TODO if it doesn't, return an error reply
       
    20 		-- TODO otherwise, apply the default privacy list
       
    21 		-- TODO and store into offline storage
       
    22 		-- TODO or maybe the offline store can apply privacy lists
       
    23 	end
    33 	end
       
    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
    24 end
    42 end
    25 
    43 
    26 module:hook("message/full", function(data)
    44 module:hook("message/full", function(data)
    27 	-- message to full JID recieved
    45 	-- message to full JID recieved
    28 	local origin, stanza = data.origin, data.stanza;
    46 	local origin, stanza = data.origin, data.stanza;