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.js72
1 files changed, 47 insertions, 25 deletions
diff --git a/src/stores/ServicesStore.js b/src/stores/ServicesStore.js
index d1fd2be3d..f88b14983 100644
--- a/src/stores/ServicesStore.js
+++ b/src/stores/ServicesStore.js
@@ -4,19 +4,19 @@ import {
4 computed, 4 computed,
5 observable, 5 observable,
6} from 'mobx'; 6} from 'mobx';
7import { debounce, remove } from 'lodash'; 7import { remove } from 'lodash';
8import ms from 'ms'; 8import ms from 'ms';
9 9
10import Store from './lib/Store'; 10import Store from './lib/Store';
11import Request from './lib/Request'; 11import Request from './lib/Request';
12import CachedRequest from './lib/CachedRequest'; 12import CachedRequest from './lib/CachedRequest';
13import { matchRoute } from '../helpers/routing-helpers'; 13import { matchRoute } from '../helpers/routing-helpers';
14import { gaEvent, statsEvent } from '../lib/analytics';
15import { workspaceStore } from '../features/workspaces'; 14import { workspaceStore } from '../features/workspaces';
16import { serviceLimitStore } from '../features/serviceLimit'; 15import { serviceLimitStore } from '../features/serviceLimit';
17import { RESTRICTION_TYPES } from '../models/Service'; 16import { RESTRICTION_TYPES } from '../models/Service';
17import { KEEP_WS_LOADED_USID } from '../config';
18 18
19const debug = require('debug')('Franz:ServiceStore'); 19const debug = require('debug')('Ferdi:ServiceStore');
20 20
21export default class ServicesStore extends Store { 21export default class ServicesStore extends Store {
22 @observable allServicesRequest = new CachedRequest(this.api.services, 'all'); 22 @observable allServicesRequest = new CachedRequest(this.api.services, 'all');
@@ -125,7 +125,35 @@ export default class ServicesStore extends Store {
125 const { keepAllWorkspacesLoaded } = this.stores.workspaces.settings; 125 const { keepAllWorkspacesLoaded } = this.stores.workspaces.settings;
126 const services = this.allServicesRequest.execute().result || []; 126 const services = this.allServicesRequest.execute().result || [];
127 const filteredServices = showDisabledServices ? services : services.filter(service => service.isEnabled); 127 const filteredServices = showDisabledServices ? services : services.filter(service => service.isEnabled);
128 return keepAllWorkspacesLoaded ? filteredServices : workspaceStore.filterServicesByActiveWorkspace(filteredServices); 128
129 let displayedServices;
130 if (keepAllWorkspacesLoaded) {
131 // Keep all enabled services loaded
132 displayedServices = filteredServices;
133 } else {
134 // Keep all services in current workspace loaded
135 displayedServices = workspaceStore.filterServicesByActiveWorkspace(filteredServices);
136
137 // Keep all services active in workspaces that should be kept loaded
138 for (const workspace of this.stores.workspaces.workspaces) {
139 // Check if workspace needs to be kept loaded
140 if (workspace.services.includes(KEEP_WS_LOADED_USID)) {
141 // Get services for workspace
142 const serviceIDs = workspace.services.filter(i => i !== KEEP_WS_LOADED_USID);
143 const wsServices = filteredServices.filter(service => serviceIDs.includes(service.id));
144
145 displayedServices = [
146 ...displayedServices,
147 ...wsServices,
148 ];
149 }
150 }
151
152 // Make sure every service is in the list only once
153 displayedServices = displayedServices.filter((v, i, a) => a.indexOf(v) === i);
154 }
155
156 return displayedServices;
129 } 157 }
130 158
131 @computed get filtered() { 159 @computed get filtered() {
@@ -182,7 +210,6 @@ export default class ServicesStore extends Store {
182 210
183 if (redirect) { 211 if (redirect) {
184 this.stores.router.push('/settings/recipes'); 212 this.stores.router.push('/settings/recipes');
185 gaEvent('Service', 'create', recipeId);
186 } 213 }
187 } 214 }
188 215
@@ -259,7 +286,6 @@ export default class ServicesStore extends Store {
259 286
260 if (redirect) { 287 if (redirect) {
261 this.stores.router.push('/settings/services'); 288 this.stores.router.push('/settings/services');
262 gaEvent('Service', 'update', service.recipe.id);
263 } 289 }
264 } 290 }
265 291
@@ -274,19 +300,14 @@ export default class ServicesStore extends Store {
274 remove(result, c => c.id === serviceId); 300 remove(result, c => c.id === serviceId);
275 }); 301 });
276 302
277 const service = this.one(serviceId);
278
279 await request._promise; 303 await request._promise;
280 this.actionStatus = request.result.status; 304 this.actionStatus = request.result.status;
281
282 gaEvent('Service', 'delete', service.recipe.id);
283 } 305 }
284 306
285 @action async _clearCache({ serviceId }) { 307 @action async _clearCache({ serviceId }) {
286 this.clearCacheRequest.reset(); 308 this.clearCacheRequest.reset();
287 const request = this.clearCacheRequest.execute(serviceId); 309 const request = this.clearCacheRequest.execute(serviceId);
288 await request._promise; 310 await request._promise;
289 gaEvent('Service', 'clear cache');
290 } 311 }
291 312
292 @action _setActive({ serviceId, keepActiveRoute }) { 313 @action _setActive({ serviceId, keepActiveRoute }) {
@@ -298,8 +319,6 @@ export default class ServicesStore extends Store {
298 }); 319 });
299 service.isActive = true; 320 service.isActive = true;
300 321
301 statsEvent('activate-service', service.recipe.id);
302
303 this._focusActiveService(); 322 this._focusActiveService();
304 } 323 }
305 324
@@ -402,7 +421,7 @@ export default class ServicesStore extends Store {
402 }, 421 },
403 }); 422 });
404 } else if (channel === 'notification') { 423 } else if (channel === 'notification') {
405 const options = args[0].options; 424 const { options } = args[0];
406 if (service.recipe.hasNotificationSound || service.isMuted || this.stores.settings.all.app.isAppMuted) { 425 if (service.recipe.hasNotificationSound || service.isMuted || this.stores.settings.all.app.isAppMuted) {
407 Object.assign(options, { 426 Object.assign(options, {
408 silent: true, 427 silent: true,
@@ -410,8 +429,17 @@ export default class ServicesStore extends Store {
410 } 429 }
411 430
412 if (service.isNotificationEnabled) { 431 if (service.isNotificationEnabled) {
413 const title = typeof args[0].title === 'string' ? args[0].title : service.name; 432 let title = `Notification from ${service.name}`;
414 options.body = typeof options.body === 'string' ? options.body : ''; 433 if (!this.stores.settings.all.app.privateNotifications) {
434 options.body = typeof options.body === 'string' ? options.body : '';
435 title = typeof args[0].title === 'string' ? args[0].title : service.name;
436 } else {
437 // Remove message data from notification in private mode
438 options.body = '';
439 options.icon = '/assets/img/notification-badge.gif';
440 }
441
442 console.log(title, options);
415 443
416 this.actions.app.notify({ 444 this.actions.app.notify({
417 notificationId: args[0].notificationId, 445 notificationId: args[0].notificationId,
@@ -529,7 +557,7 @@ export default class ServicesStore extends Store {
529 } 557 }
530 558
531 @action _reorderService({ oldIndex, newIndex }) { 559 @action _reorderService({ oldIndex, newIndex }) {
532 const showDisabledServices = this.stores.settings.all.app.showDisabledServices; 560 const { showDisabledServices } = this.stores.settings.all.app;
533 const oldEnabledSortIndex = showDisabledServices ? oldIndex : this.all.indexOf(this.enabled[oldIndex]); 561 const oldEnabledSortIndex = showDisabledServices ? oldIndex : this.all.indexOf(this.enabled[oldIndex]);
534 const newEnabledSortIndex = showDisabledServices ? newIndex : this.all.indexOf(this.enabled[newIndex]); 562 const newEnabledSortIndex = showDisabledServices ? newIndex : this.all.indexOf(this.enabled[newIndex]);
535 563
@@ -548,8 +576,6 @@ export default class ServicesStore extends Store {
548 service.order = services[s.id]; 576 service.order = services[s.id];
549 }); 577 });
550 }); 578 });
551
552 this._reorderAnalytics();
553 } 579 }
554 580
555 @action _toggleNotifications({ serviceId }) { 581 @action _toggleNotifications({ serviceId }) {
@@ -625,8 +651,8 @@ export default class ServicesStore extends Store {
625 } 651 }
626 652
627 _getUnreadMessageCountReaction() { 653 _getUnreadMessageCountReaction() {
628 const showMessageBadgeWhenMuted = this.stores.settings.all.app.showMessageBadgeWhenMuted; 654 const { showMessageBadgeWhenMuted } = this.stores.settings.all.app;
629 const showMessageBadgesEvenWhenMuted = this.stores.ui.showMessageBadgesEvenWhenMuted; 655 const { showMessageBadgesEvenWhenMuted } = this.stores.ui;
630 656
631 const unreadDirectMessageCount = this.allDisplayed 657 const unreadDirectMessageCount = this.allDisplayed
632 .filter(s => (showMessageBadgeWhenMuted || s.isNotificationEnabled) && showMessageBadgesEvenWhenMuted && s.isBadgeEnabled) 658 .filter(s => (showMessageBadgeWhenMuted || s.isNotificationEnabled) && showMessageBadgesEvenWhenMuted && s.isBadgeEnabled)
@@ -751,10 +777,6 @@ export default class ServicesStore extends Store {
751 } 777 }
752 } 778 }
753 779
754 _reorderAnalytics = debounce(() => {
755 gaEvent('Service', 'order');
756 }, ms('5s'));
757
758 _wrapIndex(index, delta, size) { 780 _wrapIndex(index, delta, size) {
759 return (((index + delta) % size) + size) % size; 781 return (((index + delta) % size) + size) % size;
760 } 782 }