Software /
code /
prosody
Comparison
plugins/mod_presence.lua @ 3083:cb15fa9242f9
Merge with backout
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Fri, 21 May 2010 19:45:33 +0100 |
parent | 2925:692b3c6c5bd2 |
parent | 3082:920cd9667c7b |
child | 3084:9b17449fb5f4 |
comparison
equal
deleted
inserted
replaced
3071:39a870ae75d9 | 3083:cb15fa9242f9 |
---|---|
36 end | 36 end |
37 end | 37 end |
38 _core_route_stanza(origin, stanza); | 38 _core_route_stanza(origin, stanza); |
39 end | 39 end |
40 | 40 |
41 local select_top_resources; | 41 local function select_top_resources(user) |
42 local bare_message_delivery_policy = module:get_option("bare_message_delivery_policy") or "priority"; | 42 local priority = 0; |
43 if bare_message_delivery_policy == "broadcast" then | 43 local recipients = {}; |
44 function select_top_resources(user) | 44 for _, session in pairs(user.sessions) do -- find resource with greatest priority |
45 local recipients = {}; | 45 if session.presence then |
46 for _, session in pairs(user.sessions) do -- find resources with non-negative priority | 46 -- TODO check active privacy list for session |
47 local p = session.priority; | 47 local p = session.priority; |
48 if p and p >= 0 then | 48 if p > priority then |
49 priority = p; | |
50 recipients = {session}; | |
51 elseif p == priority then | |
49 t_insert(recipients, session); | 52 t_insert(recipients, session); |
50 end | 53 end |
51 end | 54 end |
52 return recipients; | 55 end |
53 end | 56 return recipients; |
54 else | 57 end |
55 if bare_message_delivery_policy ~= "priority" then | |
56 module:log("warn", "Invalid value for config option bare_message_delivery_policy"); | |
57 end | |
58 function select_top_resources(user) | |
59 local priority = 0; | |
60 local recipients = {}; | |
61 for _, session in pairs(user.sessions) do -- find resource with greatest priority | |
62 if session.presence then | |
63 -- TODO check active privacy list for session | |
64 local p = session.priority; | |
65 if p > priority then | |
66 priority = p; | |
67 recipients = {session}; | |
68 elseif p == priority then | |
69 t_insert(recipients, session); | |
70 end | |
71 end | |
72 end | |
73 return recipients; | |
74 end | |
75 end | |
76 | |
77 local function recalc_resource_map(user) | 58 local function recalc_resource_map(user) |
78 if user then | 59 if user then |
79 user.top_resources = select_top_resources(user); | 60 user.top_resources = select_top_resources(user); |
80 if #user.top_resources == 0 then user.top_resources = nil; end | 61 if #user.top_resources == 0 then user.top_resources = nil; end |
81 end | 62 end |