aboutsummaryrefslogtreecommitdiffstats
path: root/src/stores/ServicesStore.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/stores/ServicesStore.js')
-rw-r--r--src/stores/ServicesStore.js53
1 files changed, 42 insertions, 11 deletions
diff --git a/src/stores/ServicesStore.js b/src/stores/ServicesStore.js
index 269cd1526..66f37af26 100644
--- a/src/stores/ServicesStore.js
+++ b/src/stores/ServicesStore.js
@@ -37,6 +37,7 @@ export default class ServicesStore extends Store {
37 this.actions.service.toggleService.listen(this._toggleService.bind(this)); 37 this.actions.service.toggleService.listen(this._toggleService.bind(this));
38 this.actions.service.handleIPCMessage.listen(this._handleIPCMessage.bind(this)); 38 this.actions.service.handleIPCMessage.listen(this._handleIPCMessage.bind(this));
39 this.actions.service.sendIPCMessage.listen(this._sendIPCMessage.bind(this)); 39 this.actions.service.sendIPCMessage.listen(this._sendIPCMessage.bind(this));
40 this.actions.service.sendIPCMessageToAllServices.listen(this._sendIPCMessageToAllServices.bind(this));
40 this.actions.service.setUnreadMessageCount.listen(this._setUnreadMessageCount.bind(this)); 41 this.actions.service.setUnreadMessageCount.listen(this._setUnreadMessageCount.bind(this));
41 this.actions.service.openWindow.listen(this._openWindow.bind(this)); 42 this.actions.service.openWindow.listen(this._openWindow.bind(this));
42 this.actions.service.filter.listen(this._filter.bind(this)); 43 this.actions.service.filter.listen(this._filter.bind(this));
@@ -58,6 +59,7 @@ export default class ServicesStore extends Store {
58 this._mapActiveServiceToServiceModelReaction.bind(this), 59 this._mapActiveServiceToServiceModelReaction.bind(this),
59 this._saveActiveService.bind(this), 60 this._saveActiveService.bind(this),
60 this._logoutReaction.bind(this), 61 this._logoutReaction.bind(this),
62 this._shareSettingsWithServiceProcess.bind(this),
61 ]); 63 ]);
62 64
63 // Just bind this 65 // Just bind this
@@ -284,6 +286,7 @@ export default class ServicesStore extends Store {
284 if (channel === 'hello') { 286 if (channel === 'hello') {
285 this._initRecipePolling(service.id); 287 this._initRecipePolling(service.id);
286 this._initializeServiceRecipeInWebview(serviceId); 288 this._initializeServiceRecipeInWebview(serviceId);
289 this._shareSettingsWithServiceProcess();
287 } else if (channel === 'messages') { 290 } else if (channel === 'messages') {
288 this.actions.service.setUnreadMessageCount({ 291 this.actions.service.setUnreadMessageCount({
289 serviceId, 292 serviceId,
@@ -294,7 +297,7 @@ export default class ServicesStore extends Store {
294 }); 297 });
295 } else if (channel === 'notification') { 298 } else if (channel === 'notification') {
296 const options = args[0].options; 299 const options = args[0].options;
297 if (service.recipe.hasNotificationSound || service.isMuted) { 300 if (service.recipe.hasNotificationSound || service.isMuted || this.stores.settings.all.isAppMuted) {
298 Object.assign(options, { 301 Object.assign(options, {
299 silent: true, 302 silent: true,
300 }); 303 });
@@ -330,7 +333,17 @@ export default class ServicesStore extends Store {
330 @action _sendIPCMessage({ serviceId, channel, args }) { 333 @action _sendIPCMessage({ serviceId, channel, args }) {
331 const service = this.one(serviceId); 334 const service = this.one(serviceId);
332 335
333 service.webview.send(channel, args); 336 if (service.webview) {
337 service.webview.send(channel, args);
338 }
339 }
340
341 @action _sendIPCMessageToAllServices({ channel, args }) {
342 this.all.forEach(s => this.actions.service.sendIPCMessage({
343 serviceId: s.id,
344 channel,
345 args,
346 }));
334 } 347 }
335 348
336 @action _openWindow({ event }) { 349 @action _openWindow({ event }) {
@@ -457,8 +470,10 @@ export default class ServicesStore extends Store {
457 const service = this.active; 470 const service = this.active;
458 471
459 if (service) { 472 if (service) {
460 this.stores.settings.updateSettingsRequest.execute({ 473 this.actions.settings.update({
461 activeService: service.id, 474 settings: {
475 activeService: service.id,
476 },
462 }); 477 });
463 } 478 }
464 } 479 }
@@ -473,19 +488,26 @@ export default class ServicesStore extends Store {
473 } 488 }
474 489
475 _getUnreadMessageCountReaction() { 490 _getUnreadMessageCountReaction() {
476 const unreadDirectMessageCount = this.enabled 491 const showMessageBadgeWhenMuted = this.stores.settings.all.showMessageBadgeWhenMuted;
492 const showMessageBadgesEvenWhenMuted = this.stores.ui.showMessageBadgesEvenWhenMuted;
493
494 const unreadDirectMessageCount = this.allDisplayed
495 .filter(s => (showMessageBadgeWhenMuted || s.isNotificationEnabled) && showMessageBadgesEvenWhenMuted && s.isBadgeEnabled)
477 .map(s => s.unreadDirectMessageCount) 496 .map(s => s.unreadDirectMessageCount)
478 .reduce((a, b) => a + b, 0); 497 .reduce((a, b) => a + b, 0);
479 498
480 const unreadIndirectMessageCount = this.enabled 499 const unreadIndirectMessageCount = this.allDisplayed
481 .filter(s => s.isIndirectMessageBadgeEnabled) 500 .filter(s => (showMessageBadgeWhenMuted || s.isIndirectMessageBadgeEnabled) && showMessageBadgesEvenWhenMuted && s.isBadgeEnabled)
482 .map(s => s.unreadIndirectMessageCount) 501 .map(s => s.unreadIndirectMessageCount)
483 .reduce((a, b) => a + b, 0); 502 .reduce((a, b) => a + b, 0);
484 503
485 this.actions.app.setBadge({ 504 // We can't just block this earlier, otherwise the mobx reaction won't be aware of the vars to watch in some cases
486 unreadDirectMessageCount, 505 if (showMessageBadgesEvenWhenMuted) {
487 unreadIndirectMessageCount, 506 this.actions.app.setBadge({
488 }); 507 unreadDirectMessageCount,
508 unreadIndirectMessageCount,
509 });
510 }
489 } 511 }
490 512
491 _logoutReaction() { 513 _logoutReaction() {
@@ -495,6 +517,13 @@ export default class ServicesStore extends Store {
495 } 517 }
496 } 518 }
497 519
520 _shareSettingsWithServiceProcess() {
521 this.actions.service.sendIPCMessageToAllServices({
522 channel: 'settings-update',
523 args: this.stores.settings.all,
524 });
525 }
526
498 _cleanUpTeamIdAndCustomUrl(recipeId, data) { 527 _cleanUpTeamIdAndCustomUrl(recipeId, data) {
499 const serviceData = data; 528 const serviceData = data;
500 const recipe = this.stores.recipes.one(recipeId); 529 const recipe = this.stores.recipes.one(recipeId);
@@ -527,6 +556,8 @@ export default class ServicesStore extends Store {
527 556
528 if (service) { 557 if (service) {
529 const loop = () => { 558 const loop = () => {
559 if (!service.webview) return;
560
530 service.webview.send('poll'); 561 service.webview.send('poll');
531 562
532 setTimeout(loop, delay); 563 setTimeout(loop, delay);