@@ -40,22 +40,23 @@ const useSendMessage = () => {
4040 // TODO: Investigation for group/community chat RSA encryption
4141 const room = rooms . find ( ( room ) => room . roomId === roomId ) ;
4242
43- // Find the opposing user ID among one-to-one room participants
44- const oppositeUserId = room ?. groupName
45- ? null
46- : room ?. participants . find (
47- ( id ) => id !== selfUser ?. _id && ! id . startsWith ( "system" ) ,
48- ) ;
43+ if ( room && ! room . groupName ) {
44+ // Find the opposing user ID among one-to-one room participants
45+ const oppositeUserId = room . participants . find (
46+ ( id ) => id !== selfUser ?. _id && ! id . startsWith ( "system" ) ,
47+ ) ;
4948
50- const oppositeUserPck = users . find ( ( user ) => user . _id === oppositeUserId )
51- ?. publicKey ;
49+ const oppositeUserPck = users . find (
50+ ( user ) => user . _id === oppositeUserId ,
51+ ) ?. publicKey ;
5252
53- // If the opposite user has a public key, the message text is encrypted using RSA.
54- if ( oppositeUserPck ) {
55- encryptedMessage = rsaEncrypt ( {
56- message : encryptedMessage ,
57- publicKey : oppositeUserPck ,
58- } ) ;
53+ // If the opposite user has a public key, the message text is encrypted using RSA.
54+ if ( oppositeUserPck ) {
55+ encryptedMessage = rsaEncrypt ( {
56+ message : encryptedMessage ,
57+ publicKey : oppositeUserPck ,
58+ } ) ;
59+ }
5960 }
6061 }
6162
0 commit comments