Comparison

plugins/mod_presence.lua @ 3518:d3399d1b484a

Don't send offline messages to resource with negative priorities
author Robert Hoelz <rob@hoelz.ro>
date Fri, 15 Oct 2010 00:53:05 -0500
parent 3235:651139e831b1
child 3540:bc139431830b
comparison
equal deleted inserted replaced
3513:4cf5962747fc 3518:d3399d1b484a
57 for i=#priority.tags,1,-1 do priority.tags[i] = nil; end 57 for i=#priority.tags,1,-1 do priority.tags[i] = nil; end
58 for i=#priority,1,-1 do priority[i] = nil; end 58 for i=#priority,1,-1 do priority[i] = nil; end
59 priority[1] = "0"; 59 priority[1] = "0";
60 end 60 end
61 end 61 end
62 local priority = stanza:child_with_name("priority");
63 if priority and #priority > 0 then
64 priority = t_concat(priority);
65 if s_find(priority, "^[+-]?[0-9]+$") then
66 priority = tonumber(priority);
67 if priority < -128 then priority = -128 end
68 if priority > 127 then priority = 127 end
69 else priority = 0; end
70 else priority = 0; end
62 if full_sessions[origin.full_jid] then -- if user is still connected 71 if full_sessions[origin.full_jid] then -- if user is still connected
63 origin.send(stanza); -- reflect their presence back to them 72 origin.send(stanza); -- reflect their presence back to them
64 end 73 end
65 local roster = origin.roster; 74 local roster = origin.roster;
66 local node, host = origin.username, origin.host; 75 local node, host = origin.username, origin.host;
103 if item.ask then 112 if item.ask then
104 request.attr.to = jid; 113 request.attr.to = jid;
105 core_post_stanza(origin, request, true); 114 core_post_stanza(origin, request, true);
106 end 115 end
107 end 116 end
108 local offline = offlinemanager.load(node, host); 117
109 if offline then 118 if priority >= 0 then
110 for _, msg in ipairs(offline) do 119 local offline = offlinemanager.load(node, host);
111 origin.send(msg); -- FIXME do we need to modify to/from in any way? 120 if offline then
112 end 121 for _, msg in ipairs(offline) do
113 offlinemanager.deleteAll(node, host); 122 origin.send(msg); -- FIXME do we need to modify to/from in any way?
114 end 123 end
124 offlinemanager.deleteAll(node, host);
125 end
126 end
115 end 127 end
116 if stanza.attr.type == "unavailable" then 128 if stanza.attr.type == "unavailable" then
117 origin.presence = nil; 129 origin.presence = nil;
118 if origin.priority then 130 if origin.priority then
119 origin.priority = nil; 131 origin.priority = nil;
126 end 138 end
127 origin.directed = nil; 139 origin.directed = nil;
128 end 140 end
129 else 141 else
130 origin.presence = stanza; 142 origin.presence = stanza;
131 local priority = stanza:child_with_name("priority");
132 if priority and #priority > 0 then
133 priority = t_concat(priority);
134 if s_find(priority, "^[+-]?[0-9]+$") then
135 priority = tonumber(priority);
136 if priority < -128 then priority = -128 end
137 if priority > 127 then priority = 127 end
138 else priority = 0; end
139 else priority = 0; end
140 if origin.priority ~= priority then 143 if origin.priority ~= priority then
141 origin.priority = priority; 144 origin.priority = priority;
142 recalc_resource_map(user); 145 recalc_resource_map(user);
143 end 146 end
144 end 147 end