Przeglądaj źródła

feat(visitors): Uses metadata to save participants that were promoted. (#15215)

* feat(visitors): Uses metadata to save participants that were promoted.

* squash: fix comments.

* squash: fix comments.
factor2
Дамян Минков 1 rok temu
rodzic
commit
1f37e0ba8d
No account linked to committer's email address

+ 2
- 0
react/features/base/conference/functions.ts Wyświetl plik

@@ -85,6 +85,7 @@ export function commonUserJoinedHandling(
85 85
 
86 86
     if (!user.isHidden()) {
87 87
         const isReplacing = user?.isReplacing();
88
+        const isPromoted = conference?.getMetadataHandler().getMetadata()?.visitors?.promoted?.[id];
88 89
 
89 90
         // the identity and avatar come from jwt and never change in the presence
90 91
         dispatch(participantJoined({
@@ -95,6 +96,7 @@ export function commonUserJoinedHandling(
95 96
             name: displayName,
96 97
             presence: user.getStatus(),
97 98
             role: user.getRole(),
99
+            isPromoted,
98 100
             isReplacing,
99 101
             sources: user.getSources()
100 102
         }));

+ 31
- 0
react/features/base/participants/reducer.ts Wyświetl plik

@@ -1,5 +1,6 @@
1 1
 import { AnyAction } from 'redux';
2 2
 
3
+import { UPDATE_CONFERENCE_METADATA } from '../conference/actionTypes';
3 4
 import { MEDIA_TYPE } from '../media/constants';
4 5
 import ReducerRegistry from '../redux/ReducerRegistry';
5 6
 import { set } from '../redux/functions';
@@ -499,6 +500,34 @@ ReducerRegistry.register<IParticipantsState>('features/base/participants',
499 500
             raisedHandsQueue: action.queue
500 501
         };
501 502
     }
503
+    case UPDATE_CONFERENCE_METADATA: {
504
+        const { metadata } = action;
505
+
506
+
507
+        if (metadata?.visitors?.promoted) {
508
+            let participantProcessed = false;
509
+
510
+            Object.entries(metadata?.visitors?.promoted).forEach(([ key, _ ]) => {
511
+
512
+                const p = state.remote.get(key);
513
+
514
+                if (p && !p.isPromoted) {
515
+
516
+                    state.remote.set(key, {
517
+                        ...p,
518
+                        isPromoted: true
519
+                    });
520
+                    participantProcessed = true;
521
+                }
522
+            });
523
+
524
+            if (participantProcessed) {
525
+                return { ...state };
526
+            }
527
+        }
528
+
529
+        break;
530
+    }
502 531
     case OVERWRITE_PARTICIPANT_NAME: {
503 532
         const { id, name } = action;
504 533
 
@@ -585,6 +614,7 @@ function _participantJoined({ participant }: { participant: IParticipant; }) {
585 614
         dominantSpeaker,
586 615
         email,
587 616
         fakeParticipant,
617
+        isPromoted,
588 618
         isReplacing,
589 619
         loadableAvatarUrl,
590 620
         local,
@@ -616,6 +646,7 @@ function _participantJoined({ participant }: { participant: IParticipant; }) {
616 646
         email,
617 647
         fakeParticipant,
618 648
         id,
649
+        isPromoted,
619 650
         isReplacing,
620 651
         loadableAvatarUrl,
621 652
         local: local || false,

+ 1
- 0
react/features/base/participants/types.ts Wyświetl plik

@@ -23,6 +23,7 @@ export interface IParticipant {
23 23
     getId?: Function;
24 24
     id: string;
25 25
     isJigasi?: boolean;
26
+    isPromoted?: boolean;
26 27
     isReplaced?: boolean;
27 28
     isReplacing?: number;
28 29
     isSilent?: boolean;

+ 35
- 11
resources/prosody-plugins/mod_visitors_component.lua Wyświetl plik

@@ -214,6 +214,16 @@ function get_visitors_languages(room)
214 214
     return count, languages:sort():concat(',');
215 215
 end
216 216
 
217
+local function get_visitors_room_metadata(room)
218
+    if not room.jitsiMetadata then
219
+        room.jitsiMetadata = {};
220
+    end
221
+    if not room.jitsiMetadata.visitors then
222
+        room.jitsiMetadata.visitors = {};
223
+    end
224
+    return room.jitsiMetadata.visitors;
225
+end
226
+
217 227
 -- listens for iq request for promotion and forward it to moderators in the meeting for approval
218 228
 -- or auto-allow it if such the config is set enabling it
219 229
 local function stanza_handler(event)
@@ -300,12 +310,8 @@ local function stanza_handler(event)
300 310
             module:log('warn', 'Received forged transcription_languages message: %s %s',stanza, inspect(room._connected_vnodes));
301 311
             return true; -- stop processing
302 312
         end
303
-        if not room.jitsiMetadata then
304
-            room.jitsiMetadata = {};
305
-        end
306
-        if not room.jitsiMetadata.visitors then
307
-            room.jitsiMetadata.visitors = {};
308
-        end
313
+
314
+        local metadata = get_visitors_room_metadata(room);
309 315
 
310 316
         -- we keep the split by languages array to optimize accumulating languages
311 317
         from_vnode.langs = split_string(transcription_languages.attr.langs, ',');
@@ -313,13 +319,13 @@ local function stanza_handler(event)
313 319
 
314 320
         local count, languages = get_visitors_languages(room);
315 321
 
316
-        if room.jitsiMetadata.visitors.transcribingLanguages ~= languages then
317
-            room.jitsiMetadata.visitors.transcribingLanguages = languages;
322
+        if metadata.transcribingLanguages ~= languages then
323
+            metadata.transcribingLanguages = languages;
318 324
             processed = true;
319 325
         end
320 326
 
321
-        if room.jitsiMetadata.visitors.transcribingCount ~= count then
322
-            room.jitsiMetadata.visitors.transcribingCount = count;
327
+        if metadata.transcribingCount ~= count then
328
+            metadata.transcribingCount = count;
323 329
             processed = true;
324 330
         end
325 331
 
@@ -338,6 +344,11 @@ local function stanza_handler(event)
338 344
 end
339 345
 
340 346
 local function process_promotion_response(room, id, approved)
347
+    if not approved then
348
+        module:log('debug', 'promotion not approved %s, %s', room.jid, id);
349
+        return;
350
+    end
351
+
341 352
     -- lets reply to participant that requested promotion
342 353
     local username = new_id():lower();
343 354
     visitors_promotion_map[room.jid][username] = {
@@ -452,10 +463,23 @@ process_host_module(muc_domain_prefix..'.'..muc_domain_base, function(host_modul
452 463
         end
453 464
 
454 465
         if visitors_promotion_map[room.jid] then
466
+            local in_ignore_list = ignore_list:contains(jid.host(stanza.attr.from));
467
+
455 468
             -- now let's check for jid
456 469
             if visitors_promotion_map[room.jid][jid.node(stanza.attr.from)] -- promotion was approved
457
-                or ignore_list:contains(jid.host(stanza.attr.from)) then -- jibri or other domains to ignore
470
+                or in_ignore_list then -- jibri or other domains to ignore
458 471
                 -- allow join
472
+                if not in_ignore_list then
473
+                    -- let's update metadata
474
+                    local metadata = get_visitors_room_metadata(room);
475
+                    if not metadata.promoted then
476
+                        metadata.promoted = {};
477
+                    end
478
+                    metadata.promoted[jid.resource(occupant.nick)] = true;
479
+                    module:context(muc_domain_prefix..'.'..muc_domain_base)
480
+                        :fire_event('room-metadata-changed', { room = room; });
481
+                end
482
+
459 483
                 return;
460 484
             end
461 485
             module:log('error', 'Visitor needs to be allowed by a moderator %s', stanza.attr.from);

Ładowanie…
Anuluj
Zapisz