mod_proxy65: Give the 'iq/host' stanza handler a negative priority, to allow mod_iq...
[prosody.git] / plugins / mod_presence.lua
index 8e6ef85a35ab97ab928f6a7e7a4dcbd6d9c5c492..65abe665e29725b3dcda5665e867908fd4255239 100644 (file)
@@ -59,6 +59,15 @@ function handle_normal_presence(origin, stanza)
                        priority[1] = "0";
                end
        end
+       local priority = stanza:child_with_name("priority");
+       if priority and #priority > 0 then
+               priority = t_concat(priority);
+               if s_find(priority, "^[+-]?[0-9]+$") then
+                       priority = tonumber(priority);
+                       if priority < -128 then priority = -128 end
+                       if priority > 127 then priority = 127 end
+               else priority = 0; end
+       else priority = 0; end
        if full_sessions[origin.full_jid] then -- if user is still connected
                origin.send(stanza); -- reflect their presence back to them
        end
@@ -105,12 +114,15 @@ function handle_normal_presence(origin, stanza)
                                core_post_stanza(origin, request, true);
                        end
                end
-               local offline = offlinemanager.load(node, host);
-               if offline then
-                       for _, msg in ipairs(offline) do
-                               origin.send(msg); -- FIXME do we need to modify to/from in any way?
+
+               if priority >= 0 then
+                       local offline = offlinemanager.load(node, host);
+                       if offline then
+                               for _, msg in ipairs(offline) do
+                                       origin.send(msg); -- FIXME do we need to modify to/from in any way?
+                               end
+                               offlinemanager.deleteAll(node, host);
                        end
-                       offlinemanager.deleteAll(node, host);
                end
        end
        if stanza.attr.type == "unavailable" then
@@ -128,15 +140,6 @@ function handle_normal_presence(origin, stanza)
                end
        else
                origin.presence = stanza;
-               local priority = stanza:child_with_name("priority");
-               if priority and #priority > 0 then
-                       priority = t_concat(priority);
-                       if s_find(priority, "^[+-]?[0-9]+$") then
-                               priority = tonumber(priority);
-                               if priority < -128 then priority = -128 end
-                               if priority > 127 then priority = 127 end
-                       else priority = 0; end
-               else priority = 0; end
                if origin.priority ~= priority then
                        origin.priority = priority;
                        recalc_resource_map(user);