Software /
code /
prosody
Comparison
plugins/mod_message.lua @ 1275:850cf92b8ad4
mod_message: A little cleanup
author | Waqas Hussain <waqas20@gmail.com> |
---|---|
date | Mon, 01 Jun 2009 18:15:28 +0500 |
parent | 1274:50babb72edac |
child | 1289:d0c38cac1687 |
comparison
equal
deleted
inserted
replaced
1274:50babb72edac | 1275:850cf92b8ad4 |
---|---|
9 local function select_top_resources(user) | 9 local function select_top_resources(user) |
10 local priority = 0; | 10 local priority = 0; |
11 local recipients = {}; | 11 local recipients = {}; |
12 for _, session in pairs(user.sessions) do -- find resource with greatest priority | 12 for _, session in pairs(user.sessions) do -- find resource with greatest priority |
13 if session.presence then | 13 if session.presence then |
14 -- TODO check active privacy list for session | |
14 local p = session.priority; | 15 local p = session.priority; |
15 if p > priority then | 16 if p > priority then |
16 priority = p; | 17 priority = p; |
17 recipients = {session}; | 18 recipients = {session}; |
18 elseif p == priority then | 19 elseif p == priority then |
25 | 26 |
26 local function process_to_bare(bare, origin, stanza) | 27 local function process_to_bare(bare, origin, stanza) |
27 local user = bare_sessions[bare]; | 28 local user = bare_sessions[bare]; |
28 | 29 |
29 local t = stanza.attr.type; | 30 local t = stanza.attr.type; |
30 if t == "error" then return true; end | 31 if t == "error" then |
31 if t == "groupchat" then | 32 -- discard |
33 elseif t == "groupchat" then | |
32 origin.send(st.error_reply(stanza, "cancel", "service-unavailable")); | 34 origin.send(st.error_reply(stanza, "cancel", "service-unavailable")); |
33 return true; | 35 elseif t == "headline" then |
34 end | |
35 if t == "headline" then | |
36 if user then | 36 if user then |
37 for _, session in pairs(user.sessions) do | 37 for _, session in pairs(user.sessions) do |
38 if session.presence and session.priority >= 0 then | 38 if session.presence and session.priority >= 0 then |
39 session.send(stanza); | 39 session.send(stanza); |
40 end | 40 end |
41 end | 41 end |
42 end -- current policy is to discard headlines if no recipient is available | 42 end -- current policy is to discard headlines if no recipient is available |
43 return true; | 43 else -- chat or normal message |
44 end | 44 if user then -- some resources are connected |
45 -- chat or normal message | 45 local recipients = select_top_resources(user); |
46 if user then -- some resources are connected | 46 if #recipients > 0 then |
47 local recipients = select_top_resources(user); | 47 for i=1,#recipients do |
48 if #recipients > 0 then | 48 recipients[i].send(stanza); |
49 for i=1,#recipients do | 49 end |
50 recipients[i].send(stanza); | 50 return true; |
51 end | 51 end |
52 return true; | |
53 end | 52 end |
54 end | 53 -- no resources are online |
55 -- no resources are online | 54 local node, host = jid_split(bare); |
56 local node, host = jid_split(bare); | 55 if user_exists(node, host) then |
57 if user_exists(node, host) then | 56 -- TODO apply the default privacy list |
58 -- TODO apply the default privacy list | 57 offlinemanager.store(node, host, stanza); |
59 offlinemanager.store(node, host, stanza); | 58 else |
60 else | 59 origin.send(st.error_reply(stanza, "cancel", "service-unavailable")); |
61 origin.send(st.error_reply(stanza, "cancel", "service-unavailable")); | 60 end |
62 end | 61 end |
63 return true; | 62 return true; |
64 end | 63 end |
65 | 64 |
66 module:hook("message/full", function(data) | 65 module:hook("message/full", function(data) |