@@ -263,19 +263,38 @@ try {
263263 soc . emit ( 'newMessage' , message , smKey , messageId ) ;
264264 }
265265 } ) ;
266- } catch ( _ ) {
267- console . error ( 'Error broadcasting message' ) ;
266+ } catch ( error ) {
267+ console . error ( 'Error broadcasting message' , error ) ;
268268 }
269269 } ) ;
270270
271271 callback ( messageId ) ;
272272 } ) ;
273-
273+
274+ //socket.emit('editMessage', encryptedMessage, chatRoomStore.value.Key, smKeys
275+ socket . on ( 'editMessage' , ( message : string , key : string , smKeys : { [ key : string ] : ArrayBuffer } , callback : ( ) => void ) => {
276+ //everyone in room including sender
277+ io . in ( `chat:${ key } ` ) . fetchSockets ( ) . then ( ( sockets ) => {
278+ try {
279+ sockets . forEach ( ( soc ) => {
280+ if ( soc . id !== socket . id ) {
281+ const smKey = smKeys [ soc . id ] ;
282+ soc . emit ( 'editMessage' , message , smKey ) ;
283+ }
284+ } ) ;
285+ } catch ( error ) {
286+ console . error ( 'Error broadcasting edited message' , error ) ;
287+ }
288+ } ) ;
289+ callback ( ) ;
290+ } ) ;
291+
292+
274293 socket . on ( 'deleteMessage' , ( messageId : string , key : string , userId : string ) => {
275294 //send back to all users in the room including the sender
276295 io . in ( `chat:${ key } ` ) . emit ( 'deleteMessage' , messageId , userId ) ;
277296 } ) ;
278-
297+
279298 socket . on ( 'react' , ( messageId : string , key : string , userId : string , react : string ) => {
280299 //everyone in room including sender
281300 io . in ( `chat:${ key } ` ) . emit ( 'react' , messageId , userId , react ) ;
0 commit comments