浏览代码

feat: Filters moderators presence in lobby room. (#10316)

* feat: Filters moderators presence in lobby room.

* squash: Print actor creating lobby.
master
Дамян Минков 3 年前
父节点
当前提交
17c0298e59
没有帐户链接到提交者的电子邮件
共有 1 个文件被更改,包括 28 次插入9 次删除
  1. 28
    9
      resources/prosody-plugins/mod_muc_lobby_rooms.lua

+ 28
- 9
resources/prosody-plugins/mod_muc_lobby_rooms.lua 查看文件

105
 end
105
 end
106
 
106
 
107
 function filter_stanza(stanza)
107
 function filter_stanza(stanza)
108
-    if not stanza.attr or not stanza.attr.from or not main_muc_service then
108
+    if not stanza.attr or not stanza.attr.from or not main_muc_service or not lobby_muc_service then
109
         return stanza;
109
         return stanza;
110
     end
110
     end
111
     -- Allow self-presence (code=110)
111
     -- Allow self-presence (code=110)
117
                 return stanza;
117
                 return stanza;
118
             end
118
             end
119
 
119
 
120
-            -- check is an owner, only owners can receive the presence
121
-            local room = main_muc_service.get_room_from_jid(jid_bare(node .. '@' .. main_muc_component_config));
122
-            if not room or room.get_affiliation(room, stanza.attr.to) == 'owner' then
120
+            local lobby_room_jid = jid_bare(stanza.attr.from);
121
+            local lobby_room = lobby_muc_service.get_room_from_jid(lobby_room_jid);
122
+            if not lobby_room then
123
+                module:log('warn', 'No lobby room found %s', lobby_room_jid);
123
                 return stanza;
124
                 return stanza;
124
             end
125
             end
125
 
126
 
126
-            return nil;
127
+            local is_to_moderator = lobby_room:get_affiliation(stanza.attr.to) == 'owner';
128
+            local from_occupant = lobby_room:get_occupant_by_nick(stanza.attr.from);
129
+            if not from_occupant then
130
+                if is_to_moderator then
131
+                    return stanza;
132
+                end
133
+
134
+                module:log('warn', 'No lobby occupant found %s', stanza.attr.from);
135
+                return nil;
136
+            end
137
+
138
+            local from_real_jid;
139
+            for real_jid in from_occupant:each_session() do
140
+                from_real_jid = real_jid;
141
+            end
142
+
143
+            if is_to_moderator and lobby_room:get_affiliation(from_real_jid) ~= 'owner' then
144
+                return stanza;
145
+            end
127
         elseif stanza.name == 'iq' and stanza:get_child('query', DISCO_INFO_NS) then
146
         elseif stanza.name == 'iq' and stanza:get_child('query', DISCO_INFO_NS) then
128
             -- allow disco info from the lobby component
147
             -- allow disco info from the lobby component
129
             return stanza;
148
             return stanza;
139
     filters.add_filter(session, 'stanzas/out', filter_stanza, -1);
158
     filters.add_filter(session, 'stanzas/out', filter_stanza, -1);
140
 end
159
 end
141
 
160
 
142
-function attach_lobby_room(room)
161
+-- actor can be null if called from backend (another module using hook create-lobby-room)
162
+function attach_lobby_room(room, actor)
143
     local node = jid_split(room.jid);
163
     local node = jid_split(room.jid);
144
     local lobby_room_jid = node .. '@' .. lobby_muc_component_config;
164
     local lobby_room_jid = node .. '@' .. lobby_muc_component_config;
145
     if not lobby_muc_service.get_room_from_jid(lobby_room_jid) then
165
     if not lobby_muc_service.get_room_from_jid(lobby_room_jid) then
149
         -- which can leave the room with no occupants and it will be destroyed and we want to
169
         -- which can leave the room with no occupants and it will be destroyed and we want to
150
         -- avoid lobby destroy while it is enabled
170
         -- avoid lobby destroy while it is enabled
151
         new_room:set_persistent(true);
171
         new_room:set_persistent(true);
152
-        module:log("debug","Lobby room jid = %s created",lobby_room_jid);
172
+        module:log("info","Lobby room jid = %s created from:%s", lobby_room_jid, actor);
153
         new_room.main_room = room;
173
         new_room.main_room = room;
154
         room._data.lobbyroom = new_room.jid;
174
         room._data.lobbyroom = new_room.jid;
155
         room:save(true);
175
         room:save(true);
278
         end
298
         end
279
         local members_only = event.fields['muc#roomconfig_membersonly'] and true or nil;
299
         local members_only = event.fields['muc#roomconfig_membersonly'] and true or nil;
280
         if members_only then
300
         if members_only then
281
-            local lobby_created = attach_lobby_room(room);
301
+            local lobby_created = attach_lobby_room(room, actor);
282
             if lobby_created then
302
             if lobby_created then
283
                 event.status_codes['104'] = true;
303
                 event.status_codes['104'] = true;
284
                 notify_lobby_enabled(room, actor, true);
304
                 notify_lobby_enabled(room, actor, true);
382
 function handle_create_lobby(event)
402
 function handle_create_lobby(event)
383
     local room = event.room;
403
     local room = event.room;
384
     room:set_members_only(true);
404
     room:set_members_only(true);
385
-    module:log("info","Set room jid = %s as members only",room.jid);
386
     attach_lobby_room(room)
405
     attach_lobby_room(room)
387
 end
406
 end
388
 
407
 

正在加载...
取消
保存