Software /
code /
prosody
Comparison
plugins/mod_presence.lua @ 2644:c75c22c316d6
mod_presence: Added config option 'bare_message_delivery_policy'. Allowed values are 'priority' (default) and 'broadcast'.
author | Waqas Hussain <waqas20@gmail.com> |
---|---|
date | Mon, 15 Feb 2010 08:04:25 +0500 |
parent | 2643:21eb99b06f4d |
child | 2925:692b3c6c5bd2 |
child | 3082:920cd9667c7b |
comparison
equal
deleted
inserted
replaced
2643:21eb99b06f4d | 2644:c75c22c316d6 |
---|---|
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 function select_top_resources(user) | 41 local select_top_resources; |
42 local priority = 0; | 42 local bare_message_delivery_policy = module:get_option("bare_message_delivery_policy") or "priority"; |
43 local recipients = {}; | 43 if bare_message_delivery_policy == "broadcast" then |
44 for _, session in pairs(user.sessions) do -- find resource with greatest priority | 44 function select_top_resources(user) |
45 if session.presence then | 45 local recipients = {}; |
46 -- TODO check active privacy list for session | 46 for _, session in pairs(user.sessions) do -- find resources with non-negative priority |
47 local p = session.priority; | 47 local p = session.priority; |
48 if p > priority then | 48 if p and p >= 0 then |
49 priority = p; | |
50 recipients = {session}; | |
51 elseif p == priority then | |
52 t_insert(recipients, session); | 49 t_insert(recipients, session); |
53 end | 50 end |
54 end | 51 end |
55 end | 52 return recipients; |
56 return recipients; | 53 end |
57 end | 54 else |
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 | |
58 local function recalc_resource_map(user) | 77 local function recalc_resource_map(user) |
59 if user then | 78 if user then |
60 user.top_resources = select_top_resources(user); | 79 user.top_resources = select_top_resources(user); |
61 if #user.top_resources == 0 then user.top_resources = nil; end | 80 if #user.top_resources == 0 then user.top_resources = nil; end |
62 end | 81 end |