diff options
Diffstat (limited to 'src/stores/ServicesStore.js')
-rw-r--r-- | src/stores/ServicesStore.js | 63 |
1 files changed, 52 insertions, 11 deletions
diff --git a/src/stores/ServicesStore.js b/src/stores/ServicesStore.js index 22c376c06..20e07e540 100644 --- a/src/stores/ServicesStore.js +++ b/src/stores/ServicesStore.js | |||
@@ -16,6 +16,7 @@ export default class ServicesStore extends Store { | |||
16 | @observable updateServiceRequest = new Request(this.api.services, 'update'); | 16 | @observable updateServiceRequest = new Request(this.api.services, 'update'); |
17 | @observable reorderServicesRequest = new Request(this.api.services, 'reorder'); | 17 | @observable reorderServicesRequest = new Request(this.api.services, 'reorder'); |
18 | @observable deleteServiceRequest = new Request(this.api.services, 'delete'); | 18 | @observable deleteServiceRequest = new Request(this.api.services, 'delete'); |
19 | @observable clearCacheRequest = new Request(this.api.services, 'clearCache'); | ||
19 | 20 | ||
20 | @observable filterNeedle = null; | 21 | @observable filterNeedle = null; |
21 | 22 | ||
@@ -31,6 +32,7 @@ export default class ServicesStore extends Store { | |||
31 | this.actions.service.createFromLegacyService.listen(this._createFromLegacyService.bind(this)); | 32 | this.actions.service.createFromLegacyService.listen(this._createFromLegacyService.bind(this)); |
32 | this.actions.service.updateService.listen(this._updateService.bind(this)); | 33 | this.actions.service.updateService.listen(this._updateService.bind(this)); |
33 | this.actions.service.deleteService.listen(this._deleteService.bind(this)); | 34 | this.actions.service.deleteService.listen(this._deleteService.bind(this)); |
35 | this.actions.service.clearCache.listen(this._clearCache.bind(this)); | ||
34 | this.actions.service.setWebviewReference.listen(this._setWebviewReference.bind(this)); | 36 | this.actions.service.setWebviewReference.listen(this._setWebviewReference.bind(this)); |
35 | this.actions.service.focusService.listen(this._focusService.bind(this)); | 37 | this.actions.service.focusService.listen(this._focusService.bind(this)); |
36 | this.actions.service.focusActiveService.listen(this._focusActiveService.bind(this)); | 38 | this.actions.service.focusActiveService.listen(this._focusActiveService.bind(this)); |
@@ -172,9 +174,29 @@ export default class ServicesStore extends Store { | |||
172 | const data = this._cleanUpTeamIdAndCustomUrl(service.recipe.id, serviceData); | 174 | const data = this._cleanUpTeamIdAndCustomUrl(service.recipe.id, serviceData); |
173 | const request = this.updateServiceRequest.execute(serviceId, data); | 175 | const request = this.updateServiceRequest.execute(serviceId, data); |
174 | 176 | ||
177 | const newData = serviceData; | ||
178 | if (serviceData.iconFile) { | ||
179 | await request._promise; | ||
180 | |||
181 | newData.iconUrl = request.result.data.iconUrl; | ||
182 | newData.hasCustomUploadedIcon = true; | ||
183 | } | ||
184 | |||
175 | this.allServicesRequest.patch((result) => { | 185 | this.allServicesRequest.patch((result) => { |
176 | if (!result) return; | 186 | if (!result) return; |
177 | Object.assign(result.find(c => c.id === serviceId), serviceData); | 187 | |
188 | // patch custom icon deletion | ||
189 | if (data.customIcon === 'delete') { | ||
190 | newData.iconUrl = ''; | ||
191 | newData.hasCustomUploadedIcon = false; | ||
192 | } | ||
193 | |||
194 | // patch custom icon url | ||
195 | if (data.customIconUrl) { | ||
196 | newData.iconUrl = data.customIconUrl; | ||
197 | } | ||
198 | |||
199 | Object.assign(result.find(c => c.id === serviceId), newData); | ||
178 | }); | 200 | }); |
179 | 201 | ||
180 | await request._promise; | 202 | await request._promise; |
@@ -205,6 +227,13 @@ export default class ServicesStore extends Store { | |||
205 | gaEvent('Service', 'delete', service.recipe.id); | 227 | gaEvent('Service', 'delete', service.recipe.id); |
206 | } | 228 | } |
207 | 229 | ||
230 | @action async _clearCache({ serviceId }) { | ||
231 | this.clearCacheRequest.reset(); | ||
232 | const request = this.clearCacheRequest.execute(serviceId); | ||
233 | await request._promise; | ||
234 | gaEvent('Service', 'clear cache'); | ||
235 | } | ||
236 | |||
208 | @action _setActive({ serviceId }) { | 237 | @action _setActive({ serviceId }) { |
209 | const service = this.one(serviceId); | 238 | const service = this.one(serviceId); |
210 | 239 | ||
@@ -297,7 +326,7 @@ export default class ServicesStore extends Store { | |||
297 | }); | 326 | }); |
298 | } else if (channel === 'notification') { | 327 | } else if (channel === 'notification') { |
299 | const options = args[0].options; | 328 | const options = args[0].options; |
300 | if (service.recipe.hasNotificationSound || service.isMuted) { | 329 | if (service.recipe.hasNotificationSound || service.isMuted || this.stores.settings.all.isAppMuted) { |
301 | Object.assign(options, { | 330 | Object.assign(options, { |
302 | silent: true, | 331 | silent: true, |
303 | }); | 332 | }); |
@@ -316,7 +345,7 @@ export default class ServicesStore extends Store { | |||
316 | } | 345 | } |
317 | } else if (channel === 'avatar') { | 346 | } else if (channel === 'avatar') { |
318 | const url = args[0]; | 347 | const url = args[0]; |
319 | if (service.customIconUrl !== url) { | 348 | if (service.iconUrl !== url && !service.hasCustomUploadedIcon) { |
320 | service.customIconUrl = url; | 349 | service.customIconUrl = url; |
321 | 350 | ||
322 | this.actions.service.updateService({ | 351 | this.actions.service.updateService({ |
@@ -327,6 +356,10 @@ export default class ServicesStore extends Store { | |||
327 | redirect: false, | 356 | redirect: false, |
328 | }); | 357 | }); |
329 | } | 358 | } |
359 | } else if (channel === 'new-window') { | ||
360 | const url = args[0]; | ||
361 | |||
362 | this.actions.app.openExternalUrl({ url }); | ||
330 | } | 363 | } |
331 | } | 364 | } |
332 | 365 | ||
@@ -368,7 +401,7 @@ export default class ServicesStore extends Store { | |||
368 | const service = this.one(serviceId); | 401 | const service = this.one(serviceId); |
369 | service.resetMessageCount(); | 402 | service.resetMessageCount(); |
370 | 403 | ||
371 | service.webview.reload(); | 404 | service.webview.loadURL(service.url); |
372 | } | 405 | } |
373 | 406 | ||
374 | @action _reloadActive() { | 407 | @action _reloadActive() { |
@@ -488,19 +521,27 @@ export default class ServicesStore extends Store { | |||
488 | } | 521 | } |
489 | 522 | ||
490 | _getUnreadMessageCountReaction() { | 523 | _getUnreadMessageCountReaction() { |
491 | const unreadDirectMessageCount = this.enabled | 524 | const showMessageBadgeWhenMuted = this.stores.settings.all.showMessageBadgeWhenMuted; |
525 | const showMessageBadgesEvenWhenMuted = this.stores.ui.showMessageBadgesEvenWhenMuted; | ||
526 | |||
527 | const unreadDirectMessageCount = this.allDisplayed | ||
528 | .filter(s => (showMessageBadgeWhenMuted || s.isNotificationEnabled) && showMessageBadgesEvenWhenMuted && s.isBadgeEnabled) | ||
492 | .map(s => s.unreadDirectMessageCount) | 529 | .map(s => s.unreadDirectMessageCount) |
493 | .reduce((a, b) => a + b, 0); | 530 | .reduce((a, b) => a + b, 0); |
494 | 531 | ||
495 | const unreadIndirectMessageCount = this.enabled | 532 | const unreadIndirectMessageCount = this.allDisplayed |
496 | .filter(s => s.isIndirectMessageBadgeEnabled) | 533 | .filter(s => (showMessageBadgeWhenMuted && showMessageBadgesEvenWhenMuted) && (s.isBadgeEnabled && s.isIndirectMessageBadgeEnabled)) |
497 | .map(s => s.unreadIndirectMessageCount) | 534 | .map(s => s.unreadIndirectMessageCount) |
498 | .reduce((a, b) => a + b, 0); | 535 | .reduce((a, b) => a + b, 0); |
499 | 536 | ||
500 | this.actions.app.setBadge({ | 537 | // We can't just block this earlier, otherwise the mobx reaction won't be aware of the vars to watch in some cases |
501 | unreadDirectMessageCount, | 538 | if (showMessageBadgesEvenWhenMuted) { |
502 | unreadIndirectMessageCount, | 539 | console.log('set badge', unreadDirectMessageCount, unreadIndirectMessageCount); |
503 | }); | 540 | this.actions.app.setBadge({ |
541 | unreadDirectMessageCount, | ||
542 | unreadIndirectMessageCount, | ||
543 | }); | ||
544 | } | ||
504 | } | 545 | } |
505 | 546 | ||
506 | _logoutReaction() { | 547 | _logoutReaction() { |