@@ -10,6 +10,8 @@ local is_healthcheck_room = main_util.is_healthcheck_room;
1010local internal_room_jid_match_rewrite = main_util .internal_room_jid_match_rewrite ;
1111local presence_check_status = main_util .presence_check_status ;
1212local extract_subdomain = main_util .extract_subdomain ;
13+ local util = module :require ' util' ;
14+ local is_transcriber = util .is_transcriber ;
1315
1416local QUEUE_MAX_SIZE = 500 ;
1517
@@ -158,7 +160,7 @@ module:hook("muc-occupant-groupchat", function(event)
158160 event .stanza :remove_children (' nick' , ' http://jabber.org/protocol/nick' );
159161end , 45 ); -- prosody check is prio 50, we want to run after it
160162
161- module : hook ( ' message/bare ' , function (event )
163+ local function filterTranscriptionResult (event )
162164 local stanza = event .stanza ;
163165
164166 if stanza .attr .type ~= ' groupchat' then
@@ -190,19 +192,25 @@ module:hook('message/bare', function(event)
190192 return ;
191193 end
192194
193- -- TODO: add optimization by moving type and certain fields like is_interim as attribute on 'json-message'
194- -- using string find is roughly 70x faster than json decode for checking the value
195- if string.find (json_message , ' "is_interim":true' , 1 , true ) then
196- return ;
197- end
198-
199195 local msg_obj , error = json .decode (json_message );
200196
201197 if error then
202198 module :log (' error' , ' Error decoding data error:%s Sender: %s to:%s' , error , stanza .attr .from , stanza .attr .to );
203199 return true ;
204200 end
205201
202+ if msg_obj .type == ' transcription-result' then
203+ if not is_transcriber (stanza .attr .from ) then
204+ module :log (' warn' , ' Filtering transcription-result message from non-transcriber: %s' , stanza .attr .from );
205+ -- Do not fire the event, and do not forward the message
206+ return true
207+ end
208+ if msg_obj .is_interim then
209+ -- Do not fire the event, but forward the message
210+ return
211+ end
212+ end
213+
206214 if msg_obj .transcript ~= nil then
207215 local transcription = msg_obj ;
208216
@@ -240,4 +248,7 @@ module:hook('message/bare', function(event)
240248 room = room , occupant = occupant , message = msg_obj ,
241249 origin = event .origin ,
242250 stanza = stanza , raw_message = json_message });
243- end );
251+ end
252+
253+ module :hook (' message/bare' , filterTranscriptionResult );
254+ module :hook (' jitsi-visitor-groupchat-pre-route' , filterTranscriptionResult );
0 commit comments