From 6d43c9623cf12bc42d8e39636db474dfa59a98d0 Mon Sep 17 00:00:00 2001 From: Ben Gotow Date: Mon, 7 Mar 2016 18:18:57 -0800 Subject: [PATCH] fix(autoload-images): Bar disappears when you choose to load images --- .../lib/autoload-images-header.jsx | 23 ++++++++++++- .../lib/autoload-images-store.es6 | 32 ++++++++++++------- .../message-autoload-images/package.json | 3 -- 3 files changed, 42 insertions(+), 16 deletions(-) diff --git a/internal_packages/message-autoload-images/lib/autoload-images-header.jsx b/internal_packages/message-autoload-images/lib/autoload-images-header.jsx index 2fa4a6206..32cb6c8f2 100644 --- a/internal_packages/message-autoload-images/lib/autoload-images-header.jsx +++ b/internal_packages/message-autoload-images/lib/autoload-images-header.jsx @@ -10,10 +10,31 @@ export default class AutoloadImagesHeader extends React.Component { message: React.PropTypes.instanceOf(Message).isRequired, } + constructor(props) { + super(props); + this.state = { + blocking: AutoloadImagesStore.shouldBlockImagesIn(this.props.message), + }; + } + + componentDidMount() { + this._unlisten = AutoloadImagesStore.listen(() => { + const blocking = AutoloadImagesStore.shouldBlockImagesIn(this.props.message); + if (blocking !== this.state.blocking) { + this.setState({blocking}); + } + }); + } + + componentWillUnmount() { + this._unlisten(); + } + render() { const {message} = this.props; + const {blocking} = this.state; - if (AutoloadImagesStore.shouldBlockImagesIn(message) === false) { + if (blocking === false) { return (
); diff --git a/internal_packages/message-autoload-images/lib/autoload-images-store.es6 b/internal_packages/message-autoload-images/lib/autoload-images-store.es6 index 2ddc185b3..8ba6dd41b 100644 --- a/internal_packages/message-autoload-images/lib/autoload-images-store.es6 +++ b/internal_packages/message-autoload-images/lib/autoload-images-store.es6 @@ -15,19 +15,21 @@ class AutoloadImagesStore extends NylasStore { this._whitelistEmails = {} this._whitelistMessageIds = {} - this._whitelistEmailsPath = path.join(NylasEnv.getConfigDirPath(), 'autoload-images-whitelist.txt'); + + const filename = 'autoload-images-whitelist.txt'; + this._whitelistEmailsPath = path.join(NylasEnv.getConfigDirPath(), filename); this._loadWhitelist(); this.listenTo(AutoloadImagesActions.temporarilyEnableImages, this._onTemporarilyEnableImages); this.listenTo(AutoloadImagesActions.permanentlyEnableImages, this._onPermanentlyEnableImages); - NylasEnv.config.onDidChange('core.reading.autoloadImages', ()=> { - MessageBodyProcessor.resetCache() + NylasEnv.config.onDidChange('core.reading.autoloadImages', () => { + MessageBodyProcessor.resetCache(); }); } - shouldBlockImagesIn = (message)=> { + shouldBlockImagesIn = (message) => { if (NylasEnv.config.get('core.reading.autoloadImages') === true) { return false; } @@ -41,22 +43,26 @@ class AutoloadImagesStore extends NylasStore { return ImagesRegexp.test(message.body); } - _loadWhitelist = ()=> { - fs.exists(this._whitelistEmailsPath, (exists)=> { + _loadWhitelist = () => { + fs.exists(this._whitelistEmailsPath, (exists) => { if (!exists) { return; } - fs.readFile(this._whitelistEmailsPath, (err, body)=> { - if (err || !body) { return console.log(err); } + fs.readFile(this._whitelistEmailsPath, (err, body) => { + if (err || !body) { + console.log(err); + return; + } this._whitelistEmails = {} - body.toString().split(/[\n\r]+/).forEach((email)=> { + body.toString().split(/[\n\r]+/).forEach((email) => { this._whitelistEmails[Utils.toEquivalentEmailForm(email)] = true; }); + this.trigger(); }); }); } - _saveWhitelist = ()=> { + _saveWhitelist = () => { const data = Object.keys(this._whitelistEmails).join('\n'); fs.writeFile(this._whitelistEmailsPath, data, (err) => { if (err) { @@ -65,16 +71,18 @@ class AutoloadImagesStore extends NylasStore { }); } - _onTemporarilyEnableImages = (message)=> { + _onTemporarilyEnableImages = (message) => { this._whitelistMessageIds[message.id] = true; MessageBodyProcessor.resetCache(); + this.trigger(); } - _onPermanentlyEnableImages = (message)=> { + _onPermanentlyEnableImages = (message) => { const email = Utils.toEquivalentEmailForm(message.fromContact().email); this._whitelistEmails[email] = true; MessageBodyProcessor.resetCache(); setTimeout(this._saveWhitelist, 1); + this.trigger(); } } diff --git a/internal_packages/message-autoload-images/package.json b/internal_packages/message-autoload-images/package.json index d9a49f624..d21811054 100755 --- a/internal_packages/message-autoload-images/package.json +++ b/internal_packages/message-autoload-images/package.json @@ -7,8 +7,5 @@ "private": true, "engines": { "nylas": "*" - }, - "dependencies": { - "autolinker": "0.18.1" } }