Skip to content

Jitsi Meet - Secure, Simple and Scalable Video Conferences that you use as a standalone app or embed in your web application.

feat: Filter transcription results. (#16606)

bgrozev93022b328192
diff --git a/resources/prosody-plugins/mod_muc_meeting_id.lua b/resources/prosody-plugins/mod_muc_meeting_id.lua
index 7287db8732..6e8b7f8746 100644
--- a/resources/prosody-plugins/mod_muc_meeting_id.lua
+++ b/resources/prosody-plugins/mod_muc_meeting_id.lua
@@ -10,6 +10,8 @@ local is_healthcheck_room = main_util.is_healthcheck_room;
local internal_room_jid_match_rewrite = main_util.internal_room_jid_match_rewrite;
local presence_check_status = main_util.presence_check_status;
local extract_subdomain = main_util.extract_subdomain;
+local util = module:require 'util';
+local is_transcriber = util.is_transcriber;
local QUEUE_MAX_SIZE = 500;
@@ -158,7 +160,7 @@ module:hook("muc-occupant-groupchat", function(event)
event.stanza:remove_children('nick', 'http://jabber.org/protocol/nick');
end, 45); -- prosody check is prio 50, we want to run after it
-module:hook('message/bare', function(event)
+local function filterTranscriptionResult(event)
local stanza = event.stanza;
if stanza.attr.type ~= 'groupchat' then
@@ -190,12 +192,6 @@ module:hook('message/bare', function(event)
return;
end
- -- TODO: add optimization by moving type and certain fields like is_interim as attribute on 'json-message'
- -- using string find is roughly 70x faster than json decode for checking the value
- if string.find(json_message, '"is_interim":true', 1, true) then
- return;
- end
-
local msg_obj, error = json.decode(json_message);
if error then
@@ -203,6 +199,18 @@ module:hook('message/bare', function(event)
return true;
end
+ if msg_obj.type == 'transcription-result' then
+ if not is_transcriber(stanza.attr.from) then
+ module:log('warn', 'Filtering transcription-result message from non-transcriber: %s', stanza.attr.from);
+ -- Do not fire the event, and do not forward the message
+ return true
+ end
+ if msg_obj.is_interim then
+ -- Do not fire the event, but forward the message
+ return
+ end
+ end
+
if msg_obj.transcript ~= nil then
local transcription = msg_obj;
@@ -240,4 +248,7 @@ module:hook('message/bare', function(event)
room = room, occupant = occupant, message = msg_obj,
origin = event.origin,
stanza = stanza, raw_message = json_message });
-end);
+end
+
+module:hook('message/bare', filterTranscriptionResult);
+module:hook('jitsi-visitor-groupchat-pre-route', filterTranscriptionResult);