add a flag to disable encryption by default

This commit is contained in:
Dave Umrysh 2021-08-25 15:29:44 -06:00
parent 569a8e76c2
commit a91ca1a092
3 changed files with 18 additions and 5 deletions

View File

@ -23,6 +23,7 @@
exitMessage: 'The chat is closed. You may close this window.',
chatUnavailableMessage: 'The chat service is not available right now. Please try again later.',
anonymousDisplayName: 'Anonymous',
enableEncryption: 'no',
}
EmbeddableChatbox.mount(config);

View File

@ -38,6 +38,7 @@ const DEFAULT_EXIT_MESSAGE = "The chat is closed. You may close this window."
const DEFAULT_ANONYMOUS_DISPLAY_NAME="Anonymous"
const DEFAULT_CHAT_UNAVAILABLE_MESSAGE = "The chat service is not available right now. Please try again later."
const DEFAULT_WAIT_MESSAGE = "Please be patient, our online facilitators are currently responding to other support requests."
const DEFAULT_ENCRYPTION = "yes"
class ChatBox extends React.Component {
@ -229,9 +230,13 @@ class ChatBox extends React.Component {
client.setDisplayName(this.props.anonymousDisplayName)
this.setMatrixListeners(client)
try {
await client.initCrypto()
} catch(err) {
if(this.props.enableEncryption == "yes"){
try {
await client.initCrypto()
} catch(err) {
return this.initializeUnencryptedChat()
}
}else{
return this.initializeUnencryptedChat()
}
@ -257,7 +262,9 @@ class ChatBox extends React.Component {
isCryptoEnabled: false,
})
this.displayBotMessage({ body: RESTARTING_UNENCRYPTED_CHAT_MESSAGE })
if(this.props.enableEncryption == "yes"){
this.displayBotMessage({ body: RESTARTING_UNENCRYPTED_CHAT_MESSAGE })
}
let opts = {
baseUrl: this.props.matrixServerUrl,
@ -277,7 +284,9 @@ class ChatBox extends React.Component {
client.setDisplayName(this.props.anonymousDisplayName)
await this.createRoom(client)
await client.startClient()
this.displayBotMessage({ body: UNENCRYPTION_NOTICE })
if(this.props.enableEncryption == "yes"){
this.displayBotMessage({ body: UNENCRYPTION_NOTICE })
}
} catch(err) {
console.log("error", err)
this.handleInitError(err)
@ -715,6 +724,7 @@ ChatBox.propTypes = {
chatUnavailableMessage: PropTypes.string,
anonymousDisplayName: PropTypes.string,
waitMessage: PropTypes.string,
enableEncryption: PropTypes.string,
}
ChatBox.defaultProps = {
@ -729,6 +739,7 @@ ChatBox.defaultProps = {
anonymousDisplayName: DEFAULT_ANONYMOUS_DISPLAY_NAME,
chatUnavailableMessage: DEFAULT_CHAT_UNAVAILABLE_MESSAGE,
waitMessage: DEFAULT_WAIT_MESSAGE,
enableEncryption: DEFAULT_ENCRYPTION,
}
export default ChatBox;

View File

@ -11,6 +11,7 @@ const config = {
exitMessage: 'The chat is closed. You may close this window.',
chatUnavailableMessage: 'The chat service is not available right now. Please try again later.',
anonymousDisplayName: 'Anonymous',
enableEncryption: 'no',
}
export default function bookmarklet() {