{MessageStore, React, ReactDOM, FileDownloadStore, MessageBodyProcessor, Actions} = require 'nylas-exports'
PGPKeyStore = require './pgp-key-store'
PassphrasePopover = require './passphrase-popover'
pgp = require 'kbpgp'
class DecryptMessageButton extends React.Component
@displayName: 'DecryptMessageButton'
@propTypes:
message: React.PropTypes.object.isRequired
constructor: (props) ->
super(props)
@state = @_getStateFromStores()
_getStateFromStores: ->
return {
isDecrypted: PGPKeyStore.isDecrypted(@props.message)
wasEncrypted: PGPKeyStore.hasEncryptedComponent(@props.message)
encryptedAttachments: PGPKeyStore.fetchEncryptedAttachments(@props.message)
status: PGPKeyStore.msgStatus(@props.message)
}
componentDidMount: ->
@unlistenKeystore = PGPKeyStore.listen(@_onKeystoreChange, @)
componentWillUnmount: ->
@unlistenKeystore()
_onKeystoreChange: ->
@setState(@_getStateFromStores())
# every time a new key gets unlocked/fetched, try to decrypt this message
if not @state.isDecrypted
PGPKeyStore.decrypt(@props.message)
_onClickDecrypt: (event) =>
popoverTarget = event.target.getBoundingClientRect()
Actions.openPopover(