plugins/mod_presence.lua

changeset 2852
56630a6c9a31
parent 2851
dcd1c0a90b2f
child 2643
21eb99b06f4d
equal deleted inserted replaced
2851:dcd1c0a90b2f 2852:56630a6c9a31
53 end 53 end
54 end 54 end
55 end 55 end
56 return recipients; 56 return recipients;
57 end 57 end
58 local function recalc_resource_map(origin) 58 local function recalc_resource_map(user)
59 local user = hosts[origin.host].sessions[origin.username]; 59 if user then
60 user.top_resources = select_top_resources(user); 60 user.top_resources = select_top_resources(user);
61 if #user.top_resources == 0 then user.top_resources = nil; end 61 if #user.top_resources == 0 then user.top_resources = nil; end
62 end
62 end 63 end
63 64
64 function handle_normal_presence(origin, stanza, core_route_stanza) 65 function handle_normal_presence(origin, stanza, core_route_stanza)
65 local roster = origin.roster; 66 local roster = origin.roster;
66 local node, host = origin.username, origin.host; 67 local node, host = origin.username, origin.host;
115 end 116 end
116 if stanza.attr.type == "unavailable" then 117 if stanza.attr.type == "unavailable" then
117 origin.presence = nil; 118 origin.presence = nil;
118 if origin.priority then 119 if origin.priority then
119 origin.priority = nil; 120 origin.priority = nil;
120 recalc_resource_map(origin); 121 recalc_resource_map(user);
121 end 122 end
122 if origin.directed then 123 if origin.directed then
123 for jid in pairs(origin.directed) do 124 for jid in pairs(origin.directed) do
124 stanza.attr.to = jid; 125 stanza.attr.to = jid;
125 core_route_stanza(origin, stanza); 126 core_route_stanza(origin, stanza);
137 if priority > 127 then priority = 127 end 138 if priority > 127 then priority = 127 end
138 else priority = 0; end 139 else priority = 0; end
139 else priority = 0; end 140 else priority = 0; end
140 if origin.priority ~= priority then 141 if origin.priority ~= priority then
141 origin.priority = priority; 142 origin.priority = priority;
142 recalc_resource_map(origin); 143 recalc_resource_map(user);
143 end 144 end
144 end 145 end
145 stanza.attr.to = nil; -- reset it 146 stanza.attr.to = nil; -- reset it
146 end 147 end
147 148

mercurial