Comparison

plugins/mod_message.lua @ 1418:d14de6cb8b5b

mod_message, mod_presence: Maintain list of top resources. Less work in routing messages to bare JIDs. - #optimization
author Waqas Hussain <waqas20@gmail.com>
date Fri, 26 Jun 2009 08:54:22 +0500
parent 1329:599a058d3961
child 1423:5e72c3e1743a
comparison
equal deleted inserted replaced
1417:b02b22f77326 1418:d14de6cb8b5b
6 local jid_bare = require "util.jid".bare; 6 local jid_bare = require "util.jid".bare;
7 local jid_split = require "util.jid".split; 7 local jid_split = require "util.jid".split;
8 local user_exists = require "core.usermanager".user_exists; 8 local user_exists = require "core.usermanager".user_exists;
9 local offlinemanager = require "core.offlinemanager"; 9 local offlinemanager = require "core.offlinemanager";
10 local t_insert = table.insert; 10 local t_insert = table.insert;
11
12 local function select_top_resources(user)
13 local priority = 0;
14 local recipients = {};
15 for _, session in pairs(user.sessions) do -- find resource with greatest priority
16 if session.presence then
17 -- TODO check active privacy list for session
18 local p = session.priority;
19 if p > priority then
20 priority = p;
21 recipients = {session};
22 elseif p == priority then
23 t_insert(recipients, session);
24 end
25 end
26 end
27 return recipients;
28 end
29 11
30 local function process_to_bare(bare, origin, stanza) 12 local function process_to_bare(bare, origin, stanza)
31 local user = bare_sessions[bare]; 13 local user = bare_sessions[bare];
32 14
33 local t = stanza.attr.type; 15 local t = stanza.attr.type;
43 end 25 end
44 end 26 end
45 end -- current policy is to discard headlines if no recipient is available 27 end -- current policy is to discard headlines if no recipient is available
46 else -- chat or normal message 28 else -- chat or normal message
47 if user then -- some resources are connected 29 if user then -- some resources are connected
48 local recipients = select_top_resources(user); 30 local recipients = user.top_resources;
49 if #recipients > 0 then 31 if recipients then
50 for i=1,#recipients do 32 for i=1,#recipients do
51 recipients[i].send(stanza); 33 recipients[i].send(stanza);
52 end 34 end
53 return true; 35 return true;
54 end 36 end