@@ -19,7 +19,7 @@ import {PluginRegistry, ContextArgs} from './types/mattermost-webapp';
19
19
import { selectPubkeys , selectPrivkey , selectKS } from './selectors' ;
20
20
import { msgCache } from './msg_cache' ;
21
21
import { AppPrivKey } from './privkey' ;
22
- import { encryptPost , decryptPost } from './e2ee_post' ;
22
+ import { encryptPost , decryptPost , isEncryptedPost } from './e2ee_post' ;
23
23
import { PublicKeyMaterial } from './e2ee' ;
24
24
import { observeStore , isValidUsername } from './utils' ;
25
25
import { MyActionResult , PubKeysState } from './types' ;
@@ -261,11 +261,6 @@ export default class E2EEHooks {
261
261
262
262
private async encryptPost ( post : Post , isUpdate = false ) : Promise < { post : Post } | { error : { message : string } } > {
263
263
const chanID = post . channel_id ;
264
- const { data : users , error : errUsers } = await this . getUserIdsInChannel ( chanID ) ;
265
- if ( errUsers ) {
266
- return { error : { message : 'Unable to get the list of users in this channel: ' + errUsers } } ;
267
- }
268
-
269
264
const lastMethod = this . getLastEncryptionMethodForChannel ( chanID ) ;
270
265
271
266
// @ts -ignore
@@ -286,6 +281,11 @@ export default class E2EEHooks {
286
281
287
282
this . setLastEncryptionMethodForChannel ( chanID , method ) ;
288
283
if ( method === 'p2p' ) {
284
+ const { data : users , error : errUsers } = await this . getUserIdsInChannel ( chanID ) ;
285
+ if ( errUsers ) {
286
+ return { error : { message : 'Unable to get the list of users in this channel: ' + errUsers } } ;
287
+ }
288
+
289
289
// @ts -ignore
290
290
const { data : pubkeys , error : errPK } = await this . dispatch ( getPubKeys ( users ) ) ;
291
291
if ( errPK ) {
@@ -336,7 +336,7 @@ export default class E2EEHooks {
336
336
}
337
337
338
338
private async messageWillBeUpdated ( post : Post ) : Promise < { post : Post } | { error : { message : string } } > {
339
- if ( ( typeof post . props !== 'undefined' ) && ( typeof post . props . e2ee !== 'undefined' ) ) {
339
+ if ( isEncryptedPost ( post ) ) {
340
340
delete post . props . e2ee ;
341
341
}
342
342
if ( post . message === '' ) {
@@ -350,7 +350,7 @@ export default class E2EEHooks {
350
350
// 2**-32.
351
351
//
352
352
// @ts -ignore
353
- if ( typeof ret . post !== 'undefined' ) {
353
+ if ( ( typeof ret . post !== 'undefined' ) && isEncryptedPost ( ret . post ) ) {
354
354
// @ts -ignore
355
355
ret . post . message += ' ' + Math . floor ( ( 2 ** 32 ) * Math . random ( ) ) . toString ( ) ;
356
356
}
0 commit comments