Browse Source

feat: Fixes filtering not needed presences.

We were filtering only self presences, no it filters and the presences to the other participants.
master
damencho 4 years ago
parent
commit
2e308d67d8
1 changed files with 14 additions and 4 deletions
  1. 14
    4
      resources/prosody-plugins/mod_muc_allowners.lua

+ 14
- 4
resources/prosody-plugins/mod_muc_allowners.lua View File

111
 -- Filters self-presences to a jid that exist in joining_participants array
111
 -- Filters self-presences to a jid that exist in joining_participants array
112
 -- We want to filter those presences where we send first `participant` and just after it `moderator`
112
 -- We want to filter those presences where we send first `participant` and just after it `moderator`
113
 function filter_stanza(stanza)
113
 function filter_stanza(stanza)
114
-    if not stanza.attr or not stanza.attr.to or stanza.name ~= "presence" then
114
+    -- when joining_moderator_participants is empty there is nothing to filter
115
+    if next(joining_moderator_participants) == nil or not stanza.attr or not stanza.attr.to or stanza.name ~= "presence" then
116
+        return stanza;
117
+    end
118
+
119
+    local muc_x = stanza:get_child('x', MUC_NS..'#user');
120
+    if not muc_x then
115
         return stanza;
121
         return stanza;
116
     end
122
     end
117
 
123
 
118
-    -- Allow self-presence (code=110)
119
     local bare_to = jid_bare(stanza.attr.to);
124
     local bare_to = jid_bare(stanza.attr.to);
125
+    if joining_moderator_participants[bare_to] and presence_check_status(muc_x, '110') then
126
+        -- skip the local presence for participant
127
+        return nil;
128
+    end
120
 
129
 
121
-    if joining_moderator_participants[bare_to] then
122
-        if presence_check_status(stanza:get_child('x', MUC_NS..'#user'), '110') then
130
+    -- skip sending the 'participant' presences to all other people in the room
131
+    for item in muc_x:childtags('item') do
132
+        if joining_moderator_participants[jid_bare(item.attr.jid)] then
123
             return nil;
133
             return nil;
124
         end
134
         end
125
     end
135
     end

Loading…
Cancel
Save