From b791245e37271c59834cd0dbd5dc6d2d9a1351cd Mon Sep 17 00:00:00 2001 From: Kimmo Saari Date: Fri, 26 Apr 2019 02:57:26 +0300 Subject: [PATCH] Version 0.5.2-beta3 --- CHANGELOG.md | 5 +++++ package.json | 2 +- public/electron.js | 5 ++++- public/handlers/auth.js | 6 +++--- public/handlers/slackInstances.js | 8 ++++++-- src/component/Menu/MenuConfig.js | 2 +- src/container/App/AppProvider.js | 3 ++- 7 files changed, 22 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 77d0bd3..87edb77 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Crash reporter. - Ability to downgrade. +## [0.5.2-beta3] - 2019-04-26 +### Fixed +- Adding new Slack instance (authorisation) was broken (again). +- When removing a Slack instance, removes also the configurations for it. + ## [0.5.2-beta2] - 2019-04-26 ### Fixed - Auto updater bug. diff --git a/package.json b/package.json index 199a06c..cb8bc31 100644 --- a/package.json +++ b/package.json @@ -1,5 +1,5 @@ { - "version": "0.5.2-beta2", + "version": "0.5.2-beta3", "name": "slothy", "description": "Changes your Slack status based on the SSID you're currently connected to.", "productName": "Slothy", diff --git a/public/electron.js b/public/electron.js index 692314b..1d001cd 100644 --- a/public/electron.js +++ b/public/electron.js @@ -400,7 +400,10 @@ ipc } }) .on('getConnections', async () => sendIfMainWindow('connections', getConnections)) - .on('removeSlackInstance', async (event, data) => sendIfMainWindow('slackInstances', removeSlackInstance, data)) + .on('removeSlackInstance', async (event, data) => { + await sendIfMainWindow('slackInstances', removeSlackInstance, data); + sendIfMainWindow('configurations', getConfigurations); + }) .on('getConfigurations', async () => sendIfMainWindow('configurations', getConfigurations)) .on('saveConfiguration', async (event, data, updateNow = true) => { await sendIfMainWindow('configurations', saveConfiguration, data); diff --git a/public/handlers/auth.js b/public/handlers/auth.js index e9773d7..78cc61e 100644 --- a/public/handlers/auth.js +++ b/public/handlers/auth.js @@ -25,13 +25,13 @@ const handleAuth = (sendIfMainWindow, uri) => { }; request(options, async (error, response, body) => { - const { ok, accessToken } = JSON.parse(body); + const { ok, access_token } = JSON.parse(body); // eslint-disable-line camelcase if (!ok) { sendIfMainWindow('error', () => 'Error in authentication!'); throw error; } else { const token = { - token: accessToken, + token: access_token, }; const profile = await getStatus(token); const workspace = await getWorkspace(token); @@ -43,7 +43,7 @@ const handleAuth = (sendIfMainWindow, uri) => { if (profile) { instance = await saveSlackInstance({ - token: accessToken, + token: access_token, profile, }); } diff --git a/public/handlers/slackInstances.js b/public/handlers/slackInstances.js index 7f6ad3b..a2d9929 100644 --- a/public/handlers/slackInstances.js +++ b/public/handlers/slackInstances.js @@ -85,10 +85,13 @@ const saveSlackInstance = instance => ( * @param {object} slackInstance - Slack instance to remove. * @returns {array} slackInstances */ -const removeSlackInstance = ({ token }) => ( +const removeSlackInstance = ({ id, token }) => ( new Promise(async (resolve, reject) => { try { - resolve(await storage.set('slackInstances', (await getSlackInstances()).filter(instance => instance.token !== token))); + const slackInstances = await getSlackInstances(); + await storage.set('configurations', (await getConfigurations()).filter(({ instanceId }) => instanceId !== id)); + const filteredSlackInstances = slackInstances.filter(instance => instance.token !== token); + resolve(await storage.set('slackInstances', filteredSlackInstances)); } catch (error) { log.error('removeSlackInstance', error); reject(error); @@ -103,4 +106,5 @@ module.exports = { removeSlackInstance, }; +const { getConfigurations } = require('./configurations'); const { getWorkspace, getWorkspaceEmojis } = require('./workspaces'); diff --git a/src/component/Menu/MenuConfig.js b/src/component/Menu/MenuConfig.js index ec067f4..a563c2b 100644 --- a/src/component/Menu/MenuConfig.js +++ b/src/component/Menu/MenuConfig.js @@ -35,7 +35,7 @@ export const contextMenu = (instance, removeSlackInstance) => ( showDeleteConfirm(instance.name, () => removeSlackInstance(instance.token))} + onClick={() => showDeleteConfirm(instance.name, () => removeSlackInstance(instance))} > Remove {instance.name} diff --git a/src/container/App/AppProvider.js b/src/container/App/AppProvider.js index 739927f..bd4b355 100644 --- a/src/container/App/AppProvider.js +++ b/src/container/App/AppProvider.js @@ -33,8 +33,9 @@ const closeOtherNotifications = (skip = '') => { class AppProvider extends Component { state = { ...INITIAL_STATE, - removeSlackInstance: token => { + removeSlackInstance: ({ token, id }) => { ipcRenderer.send('removeSlackInstance', { + id, token, }); },