Skip to content

Commit 83ff29f

Browse files
committed
Do not modify message on update if not encrypted
1 parent 49542f5 commit 83ff29f

File tree

2 files changed

+11
-8
lines changed

2 files changed

+11
-8
lines changed

webapp/src/e2ee_post.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,3 +41,6 @@ export async function decryptPost(e2ee: EncryptedP2PMessageJSON, senderkey: Publ
4141
return new UtilTextDecoder('utf-8').decode(msg);
4242
}
4343

44+
export function isEncryptedPost(post: Post): boolean {
45+
return (typeof post.props !== 'undefined') && (typeof post.props.e2ee !== 'undefined');
46+
}

webapp/src/hooks.tsx

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import {PluginRegistry, ContextArgs} from './types/mattermost-webapp';
1919
import {selectPubkeys, selectPrivkey, selectKS} from './selectors';
2020
import {msgCache} from './msg_cache';
2121
import {AppPrivKey} from './privkey';
22-
import {encryptPost, decryptPost} from './e2ee_post';
22+
import {encryptPost, decryptPost, isEncryptedPost} from './e2ee_post';
2323
import {PublicKeyMaterial} from './e2ee';
2424
import {observeStore, isValidUsername} from './utils';
2525
import {MyActionResult, PubKeysState} from './types';
@@ -261,11 +261,6 @@ export default class E2EEHooks {
261261

262262
private async encryptPost(post: Post, isUpdate = false): Promise<{post: Post} | {error: {message: string}}> {
263263
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-
269264
const lastMethod = this.getLastEncryptionMethodForChannel(chanID);
270265

271266
// @ts-ignore
@@ -286,6 +281,11 @@ export default class E2EEHooks {
286281

287282
this.setLastEncryptionMethodForChannel(chanID, method);
288283
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+
289289
// @ts-ignore
290290
const {data: pubkeys, error: errPK} = await this.dispatch(getPubKeys(users));
291291
if (errPK) {
@@ -336,7 +336,7 @@ export default class E2EEHooks {
336336
}
337337

338338
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)) {
340340
delete post.props.e2ee;
341341
}
342342
if (post.message === '') {
@@ -350,7 +350,7 @@ export default class E2EEHooks {
350350
// 2**-32.
351351
//
352352
// @ts-ignore
353-
if (typeof ret.post !== 'undefined') {
353+
if ((typeof ret.post !== 'undefined') && isEncryptedPost(ret.post)) {
354354
// @ts-ignore
355355
ret.post.message += ' ' + Math.floor((2 ** 32) * Math.random()).toString();
356356
}

0 commit comments

Comments
 (0)