浏览代码

feat: Simplify AV moderation participant approve/remove message and fix array usage. (#10062)

* feat: Simplify av moderation participant approve/remove message.

There is no point of having messages like:
{
  "room": "myroom@conference.mydomain.com",
  "type": "av_moderation",
  "mediaType": "audio",
  "removed": true,
  "approved": true
}

* fix: Fixes array in json.

fix: Fixes array in json.
master
Дамян Минков 4 年前
父节点
当前提交
31a7fbfa82
没有帐户链接到提交者的电子邮件
共有 1 个文件被更改,包括 11 次插入6 次删除
  1. 11
    6
      resources/prosody-plugins/mod_av_moderation_component.lua

+ 11
- 6
resources/prosody-plugins/mod_av_moderation_component.lua 查看文件

2
 local is_healthcheck_room = module:require 'util'.is_healthcheck_room;
2
 local is_healthcheck_room = module:require 'util'.is_healthcheck_room;
3
 local internal_room_jid_match_rewrite = module:require "util".internal_room_jid_match_rewrite;
3
 local internal_room_jid_match_rewrite = module:require "util".internal_room_jid_match_rewrite;
4
 local room_jid_match_rewrite = module:require "util".room_jid_match_rewrite;
4
 local room_jid_match_rewrite = module:require "util".room_jid_match_rewrite;
5
+local array = require "util.array";
5
 local json = require 'util.json';
6
 local json = require 'util.json';
6
 local st = require 'util.stanza';
7
 local st = require 'util.stanza';
7
 
8
 
68
     body_json.type = 'av_moderation';
69
     body_json.type = 'av_moderation';
69
     body_json.room = internal_room_jid_match_rewrite(room.jid);
70
     body_json.room = internal_room_jid_match_rewrite(room.jid);
70
     body_json.whitelists = room.av_moderation;
71
     body_json.whitelists = room.av_moderation;
71
-    body_json.removed = removed;
72
+    if removed then
73
+        body_json.removed = true;
74
+    end
72
     body_json.mediaType = mediaType;
75
     body_json.mediaType = mediaType;
73
     local moderators_body_json_str = json.encode(body_json);
76
     local moderators_body_json_str = json.encode(body_json);
74
     body_json.whitelists = nil;
77
     body_json.whitelists = nil;
75
-    body_json.approved = true; -- we want to send to participants only that they were approved to unmute
78
+    if not removed then
79
+        body_json.approved = true; -- we want to send to participants only that they were approved to unmute
80
+    end
76
     local participant_body_json_str = json.encode(body_json);
81
     local participant_body_json_str = json.encode(body_json);
77
 
82
 
78
     for _, occupant in room:each_occupant() do
83
     for _, occupant in room:each_occupant() do
167
                         room.av_moderation = {};
172
                         room.av_moderation = {};
168
                         room.av_moderation_actors = {};
173
                         room.av_moderation_actors = {};
169
                     end
174
                     end
170
-                    room.av_moderation[mediaType] = {};
175
+                    room.av_moderation[mediaType] = array{};
171
                     room.av_moderation_actors[mediaType] = occupant.nick;
176
                     room.av_moderation_actors[mediaType] = occupant.nick;
172
                 end
177
                 end
173
             else
178
             else
208
             if room.av_moderation then
213
             if room.av_moderation then
209
                 local whitelist = room.av_moderation[mediaType];
214
                 local whitelist = room.av_moderation[mediaType];
210
                 if not whitelist then
215
                 if not whitelist then
211
-                    whitelist = {};
216
+                    whitelist = array{};
212
                     room.av_moderation[mediaType] = whitelist;
217
                     room.av_moderation[mediaType] = whitelist;
213
                 end
218
                 end
214
-                table.insert(whitelist, occupant_jid);
219
+                whitelist:push(occupant_jid);
215
 
220
 
216
                 notify_whitelist_change(occupant_to_add.jid, true, room, mediaType, false);
221
                 notify_whitelist_change(occupant_to_add.jid, true, room, mediaType, false);
217
 
222
 
236
                 if whitelist then
241
                 if whitelist then
237
                     local index = get_index_in_table(whitelist, occupant_jid)
242
                     local index = get_index_in_table(whitelist, occupant_jid)
238
                     if(index) then
243
                     if(index) then
239
-                        table.remove(whitelist, index);
244
+                        whitelist:pop(index);
240
                         notify_whitelist_change(occupant_to_remove.jid, true, room, mediaType, true);
245
                         notify_whitelist_change(occupant_to_remove.jid, true, room, mediaType, true);
241
                     end
246
                     end
242
                 end
247
                 end

正在加载...
取消
保存