Prepare required data folder for integration tests
[prosody.git] / util / presence.lua
blob8d1ae2d989ad9a3d3b4c127e90b3fe13a368ec63
1 -- Prosody IM
2 -- Copyright (C) 2008-2010 Matthew Wild
3 -- Copyright (C) 2008-2010 Waqas Hussain
4 --
5 -- This project is MIT/X11 licensed. Please see the
6 -- COPYING file in the source package for more information.
7 --
9 local t_insert = table.insert;
11 local function select_top_resources(user)
12 local priority = 0;
13 local recipients = {};
14 for _, session in pairs(user.sessions) do -- find resource with greatest priority
15 if session.presence then
16 local p = session.priority;
17 if p > priority then
18 priority = p;
19 recipients = {session};
20 elseif p == priority then
21 t_insert(recipients, session);
22 end
23 end
24 end
25 return recipients;
26 end
27 local function recalc_resource_map(user)
28 if user then
29 user.top_resources = select_top_resources(user);
30 if #user.top_resources == 0 then user.top_resources = nil; end
31 end
32 end
34 return {
35 select_top_resources = select_top_resources;
36 recalc_resource_map = recalc_resource_map;