ソースを参照

feat: Dynamically limit the number of participants in a room (#9880)

* Dynamically limit the number of participants in a room

* Remove log
master
abora8x8 3年前
コミット
a5fc75ed35
コミッターのメールアドレスに関連付けられたアカウントが存在しません
1個のファイルの変更10行の追加4行の削除
  1. 10
    4
      resources/prosody-plugins/mod_muc_max_occupants.lua

+ 10
- 4
resources/prosody-plugins/mod_muc_max_occupants.lua ファイルの表示

@@ -7,6 +7,7 @@
7 7
 local split_jid = require "util.jid".split;
8 8
 local st = require "util.stanza";
9 9
 local it = require "util.iterators";
10
+local is_healthcheck_room = module:require "util".is_healthcheck_room;
10 11
 
11 12
 local whitelist = module:get_option_set("muc_access_whitelist");
12 13
 local MAX_OCCUPANTS = module:get_option_number("muc_max_occupants", -1);
@@ -17,10 +18,12 @@ end
17 18
 
18 19
 local function check_for_max_occupants(event)
19 20
   local room, origin, stanza = event.room, event.origin, event.stanza;
20
-
21
-	local actor = stanza.attr.from;
22 21
   local user, domain, res = split_jid(stanza.attr.from);
23 22
 
23
+  if is_healthcheck_room(room.jid) then
24
+    return;
25
+  end
26
+
24 27
   --no user object means no way to check for max occupants
25 28
   if user == nil then
26 29
     return
@@ -32,11 +35,14 @@ local function check_for_max_occupants(event)
32 35
   end
33 36
 
34 37
 	if room and not room._jid_nick[stanza.attr.from] then
38
+        local max_occupants_by_room = event.room._data.max_occupants;
35 39
 		local count = count_keys(room._occupants);
36
-		local slots = MAX_OCCUPANTS;
40
+        -- if no of occupants limit is set per room basis use
41
+        -- that settings otherwise use the global one
42
+        local slots = max_occupants_by_room or MAX_OCCUPANTS;
37 43
 
38 44
 		-- If there is no whitelist, just check the count.
39
-		if not whitelist and count >= MAX_OCCUPANTS then
45
+		if not whitelist and count >= slots then
40 46
 			module:log("info", "Attempt to enter a maxed out MUC");
41 47
 			origin.send(st.error_reply(stanza, "cancel", "service-unavailable"));
42 48
 			return true;

読み込み中…
キャンセル
保存