Merge 0.10->trunk
[prosody.git] / plugins / mod_presence.lua
index 2899bd7e97e8b7bbbe18d98bcb786b9f944d9709..ab57a15811ca1e28a208eb026b2a1fdf46fd24a2 100644 (file)
@@ -55,14 +55,14 @@ local ignore_presence_priority = module:get_option("ignore_presence_priority");
 
 function handle_normal_presence(origin, stanza)
        if ignore_presence_priority then
-               local priority = stanza:child_with_name("priority");
+               local priority = stanza:get_child("priority");
                if priority and priority[1] ~= "0" then
                        for i=#priority.tags,1,-1 do priority.tags[i] = nil; end
                        for i=#priority,1,-1 do priority[i] = nil; end
                        priority[1] = "0";
                end
        end
-       local priority = stanza:child_with_name("priority");
+       local priority = stanza:get_child("priority");
        if priority and #priority > 0 then
                priority = t_concat(priority);
                if s_find(priority, "^[+-]?[0-9]+$") then
@@ -90,6 +90,7 @@ function handle_normal_presence(origin, stanza)
                end
        end
        if stanza.attr.type == nil and not origin.presence then -- initial presence
+               module:fire_event("presence/initial", { origin = origin, stanza = stanza } );
                origin.presence = stanza; -- FIXME repeated later
                local probe = st.presence({from = origin.full_jid, type = "probe"});
                for jid, item in pairs(roster) do -- probe all contacts we are subscribed to
@@ -105,10 +106,8 @@ function handle_normal_presence(origin, stanza)
                                res.presence.attr.to = nil;
                        end
                end
-               if roster.pending then -- resend incoming subscription requests
-                       for jid in pairs(roster.pending) do
-                               origin.send(st.presence({type="subscribe", from=jid})); -- TODO add to attribute? Use original?
-                       end
+               for jid in pairs(roster[false].pending) do -- resend incoming subscription requests
+                       origin.send(st.presence({type="subscribe", from=jid})); -- TODO add to attribute? Use original?
                end
                local request = st.presence({type="subscribe", from=origin.username.."@"..origin.host});
                for jid, item in pairs(roster) do -- resend outgoing subscription requests