Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[NEW] E2E Encryption #2394

Merged
merged 180 commits into from
Sep 11, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
180 commits
Select commit Hold shift + click to select a range
8fa6c72
Add E2EKey to Subscription Model
djorkaeffalexandre Aug 6, 2020
0a68713
Install react-native-simple-crypto
djorkaeffalexandre Aug 6, 2020
0e029c6
Install bytebuffer
djorkaeffalexandre Aug 6, 2020
dfab3f9
Add translations
djorkaeffalexandre Aug 10, 2020
88ad198
CreateChannel Encrypted toggle
djorkaeffalexandre Aug 10, 2020
3e1a207
Request E2E_Enabled setting
djorkaeffalexandre Aug 10, 2020
e005771
Add some E2E API methods
djorkaeffalexandre Aug 10, 2020
2dbee00
Merge branch 'develop' of https://github.com/RocketChat/Rocket.Chat.R…
djorkaeffalexandre Aug 10, 2020
81881e0
POC E2E Encryption
djorkaeffalexandre Aug 11, 2020
9d840f3
Merge branch 'develop' of https://github.com/RocketChat/Rocket.Chat.R…
djorkaeffalexandre Aug 11, 2020
f91258d
Garbage remove
djorkaeffalexandre Aug 11, 2020
5e027b1
Remove keys cleaner
djorkaeffalexandre Aug 11, 2020
e63118c
Android cast JWK -> PKCS1
djorkaeffalexandre Aug 12, 2020
8b75842
Initialize E2E when Login Success
djorkaeffalexandre Aug 12, 2020
f7b10d1
Add some translations
djorkaeffalexandre Aug 12, 2020
859c0ed
Add e2e property to Message model
djorkaeffalexandre Aug 12, 2020
e4ed14c
Send Encrypted messages
djorkaeffalexandre Aug 12, 2020
c3889be
(iOS) PKCS1 -> JWK & e2e.setUserPublicAndPrivateKeys
djorkaeffalexandre Aug 12, 2020
0ab8278
(Android) PKCS1 -> JWK & e2e.setUserPublicAndPrivateKeys
djorkaeffalexandre Aug 13, 2020
e9fee01
Create an encrypted channel
djorkaeffalexandre Aug 13, 2020
6229e8f
Fix app crashing on RoomsList
djorkaeffalexandre Aug 13, 2020
fae72b2
Create room key
djorkaeffalexandre Aug 13, 2020
a9ec9fd
Set Room E2E Key (Android)
djorkaeffalexandre Aug 14, 2020
3410be6
Edit room encrypted
djorkaeffalexandre Aug 14, 2020
2671678
Show encrypted icon on messages
djorkaeffalexandre Aug 14, 2020
d5cdcbd
logEvents
djorkaeffalexandre Aug 14, 2020
2f3aad2
Decrypt pending subscriptions & messages
djorkaeffalexandre Aug 14, 2020
21dd5ae
Handle user cancel e2e password entry
djorkaeffalexandre Aug 14, 2020
dbd4e9e
E2ESavePasswordView
djorkaeffalexandre Aug 14, 2020
e412539
Update Snapshot
djorkaeffalexandre Aug 14, 2020
07470cf
Add encrypted props to message on Send
djorkaeffalexandre Aug 14, 2020
f70faf0
Thread messages encryption
djorkaeffalexandre Aug 17, 2020
a05a9ad
E2E -> Encryption
djorkaeffalexandre Aug 17, 2020
44657d1
Share Extension: Share encrypted text
djorkaeffalexandre Aug 17, 2020
3f1ea69
(POC) Search messages on Encrypted room
djorkaeffalexandre Aug 17, 2020
4f210fd
Provide room key to new users
djorkaeffalexandre Aug 17, 2020
a191ded
Request roomKey on stream-notify-room-users
djorkaeffalexandre Aug 17, 2020
d71cdc8
Add e2eKeyId to Room Model
djorkaeffalexandre Aug 18, 2020
840744a
(WIP) E2E Encryption Screens
djorkaeffalexandre Aug 18, 2020
c185c4a
Remove encryption subscription file
djorkaeffalexandre Aug 18, 2020
a38de43
Move E2E_Enable to Server Model
djorkaeffalexandre Aug 18, 2020
766fc78
Encryption List Banner
djorkaeffalexandre Aug 18, 2020
781d1c8
Move Encryption init to Sagas
djorkaeffalexandre Aug 18, 2020
1029131
Show banner only when enabled
djorkaeffalexandre Aug 18, 2020
1c9d16e
Use RocketChat/react-native-simple-crypto
djorkaeffalexandre Aug 18, 2020
ea64bb1
Search on WM only when is an Encrypted channel
djorkaeffalexandre Aug 19, 2020
e66ba21
Merge branch 'develop' of https://github.com/RocketChat/Rocket.Chat.R…
djorkaeffalexandre Aug 19, 2020
1929210
(WIP) Encryption Banner
djorkaeffalexandre Aug 19, 2020
854d19a
Encryption banner
djorkaeffalexandre Aug 19, 2020
9d8d97d
Merge develop
djorkaeffalexandre Aug 19, 2020
5de1c43
Patch -> Fork
djorkaeffalexandre Aug 19, 2020
631ff5b
Merge branch 'develop' of https://github.com/RocketChat/Rocket.Chat.R…
djorkaeffalexandre Aug 19, 2020
65b36ec
Merge branch 'develop' of https://github.com/RocketChat/Rocket.Chat.R…
djorkaeffalexandre Aug 20, 2020
5d25fcf
Improve send encrypted message
djorkaeffalexandre Aug 20, 2020
7c790e1
Update simple-crypto
djorkaeffalexandre Aug 20, 2020
3aba922
Merge develop
djorkaeffalexandre Aug 20, 2020
3462641
Not decrypt already decrypted messages
djorkaeffalexandre Aug 20, 2020
827f8d7
Add comments
djorkaeffalexandre Aug 20, 2020
d9cd44e
Change eslint disable to inline
djorkaeffalexandre Aug 20, 2020
14d9a2e
Improve code
djorkaeffalexandre Aug 20, 2020
2e19371
Remove comment
djorkaeffalexandre Aug 20, 2020
e651aa6
Some fixes
djorkaeffalexandre Aug 20, 2020
3b39031
(WIP) Encryption Screens
djorkaeffalexandre Aug 20, 2020
ddb280d
Improve sub find
djorkaeffalexandre Aug 20, 2020
0e57adf
Resend an encrypted message
djorkaeffalexandre Aug 20, 2020
8afc43e
Fix comment
djorkaeffalexandre Aug 20, 2020
9d8890d
Code improvements
djorkaeffalexandre Aug 20, 2020
41b8bd1
Hide e2e buttons on features if it is not enabled
djorkaeffalexandre Aug 20, 2020
ac92dc6
InApp notifications of a encrypted room
djorkaeffalexandre Aug 20, 2020
41543e1
Encryption stop logic
djorkaeffalexandre Aug 20, 2020
722800b
Edit encrypted message
djorkaeffalexandre Aug 21, 2020
7fc9b33
Merge develop
djorkaeffalexandre Aug 21, 2020
f84640f
DB batch on decryptPending
djorkaeffalexandre Aug 21, 2020
607b4fb
Encryption ready client
djorkaeffalexandre Aug 21, 2020
6425464
Comments
djorkaeffalexandre Aug 21, 2020
fd81bac
Handle getRoomInstance errors
djorkaeffalexandre Aug 21, 2020
2b7ff5f
Multiple messages decrypt
djorkaeffalexandre Aug 21, 2020
d5b2abe
Remove unnecessary try/catch
djorkaeffalexandre Aug 21, 2020
4120c41
Fix decrypt all messages history
djorkaeffalexandre Aug 21, 2020
0a13927
Just add a questionmark
djorkaeffalexandre Aug 21, 2020
dcf5fb2
Fix some subscriptions missing decrypt
djorkaeffalexandre Aug 21, 2020
69ad3c1
Merge develop
djorkaeffalexandre Aug 21, 2020
f3540ee
Disable request key logic
djorkaeffalexandre Aug 22, 2020
8ab94fe
Fix unicode emojis
djorkaeffalexandre Aug 24, 2020
9f88a26
Fix e2ekey request
djorkaeffalexandre Aug 24, 2020
f7feb1d
roomId -> subscription
djorkaeffalexandre Aug 24, 2020
4d573d6
Merge branch 'develop' of https://github.com/RocketChat/Rocket.Chat.R…
djorkaeffalexandre Aug 24, 2020
1e413db
Merge develop
djorkaeffalexandre Aug 24, 2020
6051ecd
Decrypt subscription after merge
djorkaeffalexandre Aug 24, 2020
5a11bd5
E2ERoom -> EncryptionRoom
djorkaeffalexandre Aug 25, 2020
00c78da
Fix infinite loading
djorkaeffalexandre Aug 25, 2020
2cf140d
Handle import key errors
djorkaeffalexandre Aug 25, 2020
34d541b
Handle request key errors
djorkaeffalexandre Aug 25, 2020
b309f36
Move e2eRequestRoomKey to Rocket.Chat
djorkaeffalexandre Aug 25, 2020
abf5e70
Merge branch 'develop' of https://github.com/RocketChat/Rocket.Chat.R…
djorkaeffalexandre Aug 25, 2020
84e9827
WIP handshake when key should be requested
djorkaeffalexandre Aug 25, 2020
6ad5c82
Add search messages explanation
djorkaeffalexandre Aug 25, 2020
74b8dd6
Remove some TODO and update comments
djorkaeffalexandre Aug 25, 2020
4902adf
Merge branch 'develop' of https://github.com/RocketChat/Rocket.Chat.R…
djorkaeffalexandre Aug 25, 2020
67ff890
Improvements
djorkaeffalexandre Aug 25, 2020
84a8a0a
Merge branch 'develop' of https://github.com/RocketChat/Rocket.Chat.R…
djorkaeffalexandre Aug 25, 2020
9488adc
Dont show message hash to user
djorkaeffalexandre Aug 25, 2020
56e770e
Merge develop
djorkaeffalexandre Aug 25, 2020
b1390f4
Merge branch 'develop' of https://github.com/RocketChat/Rocket.Chat.R…
djorkaeffalexandre Aug 25, 2020
04b2acc
Handle key request & prevent multiple calls
djorkaeffalexandre Aug 26, 2020
631b5b7
Request E2EKey on decryptSubscription that doesn't exists on database…
djorkaeffalexandre Aug 26, 2020
00d69b7
Insert decrypted subscription
djorkaeffalexandre Aug 26, 2020
b799a1e
Fix crash after login
djorkaeffalexandre Aug 26, 2020
2b4d445
Decrypt sub when receive the key
djorkaeffalexandre Aug 26, 2020
84dd57c
Decrypt pending messages of a room
djorkaeffalexandre Aug 26, 2020
b918fc0
Merge branch 'develop' of https://github.com/RocketChat/Rocket.Chat.R…
djorkaeffalexandre Aug 26, 2020
49446a1
Encrypted as a switch
djorkaeffalexandre Aug 26, 2020
100115a
Merge branch 'develop' into new.e2e-encryption
djorkaeffalexandre Aug 26, 2020
fbe8107
Buffer to Base64 URI Safe
djorkaeffalexandre Aug 26, 2020
b9d142f
Add a relevant comment
djorkaeffalexandre Aug 26, 2020
c419af0
Prevent import key without a privateKey
djorkaeffalexandre Aug 27, 2020
b228473
Prevent create a new instance when client is not ready
djorkaeffalexandre Aug 27, 2020
a725236
Update simple-crypto & remove replace trick
djorkaeffalexandre Aug 27, 2020
2e4fdc8
More comments
djorkaeffalexandre Aug 27, 2020
4b230dd
Remove useless comment
djorkaeffalexandre Aug 27, 2020
c5faed1
Remove useless try/catch
djorkaeffalexandre Aug 27, 2020
1089ea0
I18n all E2E screens
djorkaeffalexandre Aug 27, 2020
f763621
E2ESavePassword -> E2ESaveYourPassword
djorkaeffalexandre Aug 27, 2020
c3b190b
Merge branch 'develop' into new.e2e-encryption
diegolmello Aug 28, 2020
78ff6fb
merge develop
djorkaeffalexandre Aug 28, 2020
97dc7ab
Prevent multiple views on message when is not encrypted
djorkaeffalexandre Aug 28, 2020
c597f80
Fix encryption toggle not working sometimes
djorkaeffalexandre Aug 31, 2020
8287d22
follow some suggestions
djorkaeffalexandre Aug 31, 2020
7e45bd2
dont rotate icons
djorkaeffalexandre Aug 31, 2020
d4e6c81
remove unnecessary condition
djorkaeffalexandre Aug 31, 2020
6d0de1a
remove unreachable event
djorkaeffalexandre Aug 31, 2020
80ecd9a
create channel comment
djorkaeffalexandre Aug 31, 2020
5296706
disable no-bitwise rule for entire file
djorkaeffalexandre Aug 31, 2020
7c77c58
loadKeys -> persistKeys
djorkaeffalexandre Aug 31, 2020
ad97e7b
getMasterKey -> generateMasterKey
djorkaeffalexandre Aug 31, 2020
84d78ca
explicit difference between E2EKey & e2eKeyId
djorkaeffalexandre Aug 31, 2020
9ac380a
roomId -> rid
djorkaeffalexandre Aug 31, 2020
fac357a
group columns
djorkaeffalexandre Aug 31, 2020
e4c516f
Merge develop
djorkaeffalexandre Aug 31, 2020
bffed8c
Remove server selector
djorkaeffalexandre Sep 1, 2020
cc95074
missing log events
djorkaeffalexandre Sep 1, 2020
c6bb976
remove comment
djorkaeffalexandre Sep 1, 2020
4e9572f
use stored public key
djorkaeffalexandre Sep 1, 2020
72fc48b
update simple-crypto & remove base64-js patch
djorkaeffalexandre Sep 1, 2020
aa63066
add some logs
djorkaeffalexandre Sep 1, 2020
28b09a0
remove unreachable condition
djorkaeffalexandre Sep 1, 2020
75e82c0
log errors
djorkaeffalexandre Sep 1, 2020
d756dd2
handle errors on provide key directly on subscription
djorkaeffalexandre Sep 1, 2020
d6a41e3
Downgrade RocketChat/react-native-simple-crypto
djorkaeffalexandre Sep 1, 2020
0a305ba
improve get room instance
djorkaeffalexandre Sep 1, 2020
2a56527
migration of older apps
djorkaeffalexandre Sep 2, 2020
2b74e58
check encrypted status before send a message
djorkaeffalexandre Sep 2, 2020
d3e3072
Merge branch 'develop' of https://github.com/RocketChat/Rocket.Chat.R…
djorkaeffalexandre Sep 2, 2020
4f1ae4a
wait client ready
djorkaeffalexandre Sep 8, 2020
a070758
use our own base64-js
djorkaeffalexandre Sep 8, 2020
f3cf043
add more jest tests
djorkaeffalexandre Sep 8, 2020
bd162e7
explain return
djorkaeffalexandre Sep 8, 2020
60d70d1
remove unncessary stop
djorkaeffalexandre Sep 8, 2020
b4868ee
thrown error to caller
djorkaeffalexandre Sep 8, 2020
b822e65
remove superfluous checks
djorkaeffalexandre Sep 8, 2020
98136df
use Encryption property
djorkaeffalexandre Sep 8, 2020
d0fd6a1
change ready state logic
djorkaeffalexandre Sep 8, 2020
58f6a26
ready -> establishing
djorkaeffalexandre Sep 8, 2020
29e6cb7
encryption.room -> encryptionRoom
djorkaeffalexandre Sep 8, 2020
e26ed3d
EncryptionRoom -> Room
djorkaeffalexandre Sep 9, 2020
11354d9
add documentation
djorkaeffalexandre Sep 9, 2020
718c33b
wait establishing before provide a room key
djorkaeffalexandre Sep 9, 2020
69020fb
remove superfluous condition
djorkaeffalexandre Sep 9, 2020
2bdb814
improve error handling logic
djorkaeffalexandre Sep 9, 2020
3a2ce5e
fallback e2ekey set
djorkaeffalexandre Sep 9, 2020
58fd4b5
remove no longer necessary check
djorkaeffalexandre Sep 9, 2020
d2ec09c
remove e.g.
djorkaeffalexandre Sep 9, 2020
5bd32c9
improve getRoomInstance
djorkaeffalexandre Sep 10, 2020
3cd8bef
import from index
djorkaeffalexandre Sep 10, 2020
3e4f004
use batch
djorkaeffalexandre Sep 10, 2020
e396087
fix a comment
djorkaeffalexandre Sep 10, 2020
f4e4f1c
decrypt tmsg
djorkaeffalexandre Sep 10, 2020
5f057f7
dont show hash when message is encrypted
djorkaeffalexandre Sep 10, 2020
91faf9a
Fix detox
diegolmello Sep 11, 2020
653ac5f
Apply suggestions from code review
diegolmello Sep 11, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
159 changes: 159 additions & 0 deletions __tests__/__snapshots__/Storyshots.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -3333,6 +3333,165 @@ exports[`Storyshots Message list message 1`] = `
>
Edited
</Text>
<Text
style={
Array [
Object {
"fontSize": 20,
"fontWeight": "300",
"marginLeft": 10,
"marginVertical": 30,
},
Object {
"color": "#0d0e12",
},
Object {
"marginBottom": 0,
"marginTop": 30,
},
]
}
>
Encrypted
</Text>
<View>
<View
style={
Array [
Object {
"flexDirection": "column",
"paddingHorizontal": 14,
"paddingVertical": 4,
"width": "100%",
},
undefined,
]
}
>
<View
style={
Object {
"flexDirection": "row",
}
}
>
<View
style={
Array [
Object {
"borderRadius": 4,
"height": 36,
"width": 36,
},
Object {
"marginTop": 4,
},
]
}
/>
<View
style={
Array [
Object {
"flex": 1,
"marginLeft": 46,
},
Object {
"marginLeft": 10,
},
]
}
>
<View
style={
Object {
"alignItems": "center",
"flex": 1,
"flexDirection": "row",
}
}
>
<Text
style={
Array [
Object {
"backgroundColor": "transparent",
"fontFamily": "System",
"fontSize": 12,
"fontWeight": "300",
"lineHeight": 22,
"paddingLeft": 10,
},
Object {
"color": "#9ca2a8",
},
]
}
>
10:00 AM
</Text>
</View>
<View>
<View
style={
Object {
"flexDirection": "row",
}
}
>
<View
style={
Object {
"flex": 1,
}
}
>
<Text
numberOfLines={0}
style={
Array [
undefined,
Object {
"color": "#2f343d",
},
]
}
>
<Text
accessibilityLabel="This message has error and is encrypted"
numberOfLines={0}
style={
Array [
Object {
"backgroundColor": "transparent",
"fontFamily": "System",
"fontSize": 16,
"fontWeight": "400",
},
Array [
Object {},
Object {
"alignItems": "flex-start",
"flexDirection": "row",
"flexWrap": "wrap",
"justifyContent": "flex-start",
"marginBottom": 0,
"marginTop": 0,
},
],
]
}
>
This message has error and is encrypted
</Text>
</Text>
</View>
</View>
</View>
</View>
</View>
</View>
</View>
<Text
style={
Array [
Expand Down
1 change: 1 addition & 0 deletions app/actions/actionsTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,4 @@ export const INVITE_LINKS = createRequestTypes('INVITE_LINKS', [
export const SETTINGS = createRequestTypes('SETTINGS', ['CLEAR', 'ADD']);
export const APP_STATE = createRequestTypes('APP_STATE', ['FOREGROUND', 'BACKGROUND']);
export const ENTERPRISE_MODULES = createRequestTypes('ENTERPRISE_MODULES', ['CLEAR', 'SET']);
export const ENCRYPTION = createRequestTypes('ENCRYPTION', ['INIT', 'STOP', 'DECODE_KEY', 'SET_BANNER']);
27 changes: 27 additions & 0 deletions app/actions/encryption.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import * as types from './actionsTypes';

export function encryptionInit() {
return {
type: types.ENCRYPTION.INIT
};
}

export function encryptionStop() {
return {
type: types.ENCRYPTION.STOP
};
}

export function encryptionSetBanner(banner) {
return {
type: types.ENCRYPTION.SET_BANNER,
banner
};
}

export function encryptionDecodeKey(password) {
return {
type: types.ENCRYPTION.DECODE_KEY,
password
};
}
3 changes: 3 additions & 0 deletions app/constants/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ export default {
DirectMesssage_maxUsers: {
type: 'valueAsNumber'
},
E2E_Enable: {
type: 'valueAsBoolean'
},
Accounts_Directory_DefaultView: {
type: 'valueAsString'
},
Expand Down
34 changes: 31 additions & 3 deletions app/containers/message/Content.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import Markdown from '../markdown';
import { getInfoMessage } from './utils';
import { themes } from '../../constants/colors';
import MessageContext from './Context';
import Encrypted from './Encrypted';
import { E2E_MESSAGE_TYPE } from '../../lib/encryption/constants';

const Content = React.memo((props) => {
if (props.isInfo) {
Expand All @@ -22,10 +24,13 @@ const Content = React.memo((props) => {
);
}

const isPreview = props.tmid && !props.isThreadRoom;
let content = null;

if (props.tmid && !props.msg) {
content = <Text style={[styles.text, { color: themes[props.theme].bodyText }]}>{I18n.t('Sent_an_attachment')}</Text>;
} else if (props.isEncrypted) {
content = <Text style={[styles.textInfo, { color: themes[props.theme].auxiliaryText }]}>{I18n.t('Encrypted_message')}</Text>;
} else {
const { baseUrl, user } = useContext(MessageContext);
content = (
Expand All @@ -35,8 +40,8 @@ const Content = React.memo((props) => {
getCustomEmoji={props.getCustomEmoji}
username={user.username}
isEdited={props.isEdited}
numberOfLines={(props.tmid && !props.isThreadRoom) ? 1 : 0}
preview={props.tmid && !props.isThreadRoom}
numberOfLines={isPreview ? 1 : 0}
preview={isPreview}
channels={props.channels}
mentions={props.mentions}
navToRoomInfo={props.navToRoomInfo}
Expand All @@ -47,6 +52,21 @@ const Content = React.memo((props) => {
);
}

// If this is a encrypted message and is not a preview
if (props.type === E2E_MESSAGE_TYPE && !isPreview) {
content = (
<View style={styles.flex}>
<View style={styles.contentContainer}>
{content}
</View>
<Encrypted
type={props.type}
theme={props.theme}
/>
</View>
);
}

return (
<View style={props.isTemp && styles.temp}>
{content}
Expand All @@ -59,9 +79,15 @@ const Content = React.memo((props) => {
if (prevProps.msg !== nextProps.msg) {
return false;
}
if (prevProps.type !== nextProps.type) {
return false;
}
if (prevProps.theme !== nextProps.theme) {
return false;
}
if (prevProps.isEncrypted !== nextProps.isEncrypted) {
return false;
}
if (!equal(prevProps.mentions, nextProps.mentions)) {
return false;
}
Expand All @@ -79,11 +105,13 @@ Content.propTypes = {
msg: PropTypes.string,
theme: PropTypes.string,
isEdited: PropTypes.bool,
isEncrypted: PropTypes.bool,
getCustomEmoji: PropTypes.func,
channels: PropTypes.oneOfType([PropTypes.array, PropTypes.object]),
mentions: PropTypes.oneOfType([PropTypes.array, PropTypes.object]),
navToRoomInfo: PropTypes.func,
useRealName: PropTypes.bool
useRealName: PropTypes.bool,
type: PropTypes.string
};
Content.displayName = 'MessageContent';

Expand Down
29 changes: 29 additions & 0 deletions app/containers/message/Encrypted.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import React, { useContext } from 'react';
import PropTypes from 'prop-types';

import Touchable from './Touchable';
import { E2E_MESSAGE_TYPE } from '../../lib/encryption/constants';
import { CustomIcon } from '../../lib/Icons';
import { themes } from '../../constants/colors';
import { BUTTON_HIT_SLOP } from './utils';
import MessageContext from './Context';
import styles from './styles';

const Encrypted = React.memo(({ type, theme }) => {
if (type !== E2E_MESSAGE_TYPE) {
return null;
}

const { onEncryptedPress } = useContext(MessageContext);
return (
<Touchable onPress={onEncryptedPress} style={styles.encrypted} hitSlop={BUTTON_HIT_SLOP}>
<CustomIcon name='encrypted' size={16} color={themes[theme].auxiliaryText} />
</Touchable>
);
});
Encrypted.propTypes = {
type: PropTypes.string,
theme: PropTypes.string
};

export default Encrypted;
13 changes: 11 additions & 2 deletions app/containers/message/RepliedThread.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@ import { CustomIcon } from '../../lib/Icons';
import DisclosureIndicator from '../DisclosureIndicator';
import styles from './styles';
import { themes } from '../../constants/colors';
import I18n from '../../i18n';

const RepliedThread = React.memo(({
tmid, tmsg, isHeader, fetchThreadName, id, theme
tmid, tmsg, isHeader, fetchThreadName, id, isEncrypted, theme
}) => {
if (!tmid || !isHeader) {
return null;
Expand All @@ -24,6 +25,10 @@ const RepliedThread = React.memo(({
let msg = shortnameToUnicode(tmsg);
msg = removeMarkdown(msg);

if (isEncrypted) {
msg = I18n.t('Encrypted_message');
}

return (
<View style={styles.repliedThread} testID={`message-thread-replied-on-${ msg }`}>
<CustomIcon name='threads' size={20} style={styles.repliedThreadIcon} color={themes[theme].tintColor} />
Expand All @@ -38,6 +43,9 @@ const RepliedThread = React.memo(({
if (prevProps.tmsg !== nextProps.tmsg) {
return false;
}
if (prevProps.isEncrypted !== nextProps.isEncrypted) {
return false;
}
if (prevProps.isHeader !== nextProps.isHeader) {
return false;
}
Expand All @@ -53,7 +61,8 @@ RepliedThread.propTypes = {
id: PropTypes.string,
isHeader: PropTypes.bool,
theme: PropTypes.string,
fetchThreadName: PropTypes.func
fetchThreadName: PropTypes.func,
isEncrypted: PropTypes.bool
};
RepliedThread.displayName = 'MessageRepliedThread';

Expand Down
Loading