diff options
Diffstat (limited to 'src/stores/ServicesStore.js')
-rw-r--r-- | src/stores/ServicesStore.js | 41 |
1 files changed, 17 insertions, 24 deletions
diff --git a/src/stores/ServicesStore.js b/src/stores/ServicesStore.js index d1fd2be3d..374daf333 100644 --- a/src/stores/ServicesStore.js +++ b/src/stores/ServicesStore.js | |||
@@ -4,19 +4,18 @@ import { | |||
4 | computed, | 4 | computed, |
5 | observable, | 5 | observable, |
6 | } from 'mobx'; | 6 | } from 'mobx'; |
7 | import { debounce, remove } from 'lodash'; | 7 | import { remove } from 'lodash'; |
8 | import ms from 'ms'; | 8 | import ms from 'ms'; |
9 | 9 | ||
10 | import Store from './lib/Store'; | 10 | import Store from './lib/Store'; |
11 | import Request from './lib/Request'; | 11 | import Request from './lib/Request'; |
12 | import CachedRequest from './lib/CachedRequest'; | 12 | import CachedRequest from './lib/CachedRequest'; |
13 | import { matchRoute } from '../helpers/routing-helpers'; | 13 | import { matchRoute } from '../helpers/routing-helpers'; |
14 | import { gaEvent, statsEvent } from '../lib/analytics'; | ||
15 | import { workspaceStore } from '../features/workspaces'; | 14 | import { workspaceStore } from '../features/workspaces'; |
16 | import { serviceLimitStore } from '../features/serviceLimit'; | 15 | import { serviceLimitStore } from '../features/serviceLimit'; |
17 | import { RESTRICTION_TYPES } from '../models/Service'; | 16 | import { RESTRICTION_TYPES } from '../models/Service'; |
18 | 17 | ||
19 | const debug = require('debug')('Franz:ServiceStore'); | 18 | const debug = require('debug')('Ferdi:ServiceStore'); |
20 | 19 | ||
21 | export default class ServicesStore extends Store { | 20 | export default class ServicesStore extends Store { |
22 | @observable allServicesRequest = new CachedRequest(this.api.services, 'all'); | 21 | @observable allServicesRequest = new CachedRequest(this.api.services, 'all'); |
@@ -182,7 +181,6 @@ export default class ServicesStore extends Store { | |||
182 | 181 | ||
183 | if (redirect) { | 182 | if (redirect) { |
184 | this.stores.router.push('/settings/recipes'); | 183 | this.stores.router.push('/settings/recipes'); |
185 | gaEvent('Service', 'create', recipeId); | ||
186 | } | 184 | } |
187 | } | 185 | } |
188 | 186 | ||
@@ -259,7 +257,6 @@ export default class ServicesStore extends Store { | |||
259 | 257 | ||
260 | if (redirect) { | 258 | if (redirect) { |
261 | this.stores.router.push('/settings/services'); | 259 | this.stores.router.push('/settings/services'); |
262 | gaEvent('Service', 'update', service.recipe.id); | ||
263 | } | 260 | } |
264 | } | 261 | } |
265 | 262 | ||
@@ -274,19 +271,14 @@ export default class ServicesStore extends Store { | |||
274 | remove(result, c => c.id === serviceId); | 271 | remove(result, c => c.id === serviceId); |
275 | }); | 272 | }); |
276 | 273 | ||
277 | const service = this.one(serviceId); | ||
278 | |||
279 | await request._promise; | 274 | await request._promise; |
280 | this.actionStatus = request.result.status; | 275 | this.actionStatus = request.result.status; |
281 | |||
282 | gaEvent('Service', 'delete', service.recipe.id); | ||
283 | } | 276 | } |
284 | 277 | ||
285 | @action async _clearCache({ serviceId }) { | 278 | @action async _clearCache({ serviceId }) { |
286 | this.clearCacheRequest.reset(); | 279 | this.clearCacheRequest.reset(); |
287 | const request = this.clearCacheRequest.execute(serviceId); | 280 | const request = this.clearCacheRequest.execute(serviceId); |
288 | await request._promise; | 281 | await request._promise; |
289 | gaEvent('Service', 'clear cache'); | ||
290 | } | 282 | } |
291 | 283 | ||
292 | @action _setActive({ serviceId, keepActiveRoute }) { | 284 | @action _setActive({ serviceId, keepActiveRoute }) { |
@@ -298,8 +290,6 @@ export default class ServicesStore extends Store { | |||
298 | }); | 290 | }); |
299 | service.isActive = true; | 291 | service.isActive = true; |
300 | 292 | ||
301 | statsEvent('activate-service', service.recipe.id); | ||
302 | |||
303 | this._focusActiveService(); | 293 | this._focusActiveService(); |
304 | } | 294 | } |
305 | 295 | ||
@@ -402,7 +392,7 @@ export default class ServicesStore extends Store { | |||
402 | }, | 392 | }, |
403 | }); | 393 | }); |
404 | } else if (channel === 'notification') { | 394 | } else if (channel === 'notification') { |
405 | const options = args[0].options; | 395 | const { options } = args[0]; |
406 | if (service.recipe.hasNotificationSound || service.isMuted || this.stores.settings.all.app.isAppMuted) { | 396 | if (service.recipe.hasNotificationSound || service.isMuted || this.stores.settings.all.app.isAppMuted) { |
407 | Object.assign(options, { | 397 | Object.assign(options, { |
408 | silent: true, | 398 | silent: true, |
@@ -410,8 +400,17 @@ export default class ServicesStore extends Store { | |||
410 | } | 400 | } |
411 | 401 | ||
412 | if (service.isNotificationEnabled) { | 402 | if (service.isNotificationEnabled) { |
413 | const title = typeof args[0].title === 'string' ? args[0].title : service.name; | 403 | let title = `Notification from ${service.name}`; |
414 | options.body = typeof options.body === 'string' ? options.body : ''; | 404 | if (!this.stores.settings.all.app.privateNotifications) { |
405 | options.body = typeof options.body === 'string' ? options.body : ''; | ||
406 | title = typeof args[0].title === 'string' ? args[0].title : service.name; | ||
407 | } else { | ||
408 | // Remove message data from notification in private mode | ||
409 | options.body = ''; | ||
410 | options.icon = '/assets/img/notification-badge.gif'; | ||
411 | } | ||
412 | |||
413 | console.log(title, options); | ||
415 | 414 | ||
416 | this.actions.app.notify({ | 415 | this.actions.app.notify({ |
417 | notificationId: args[0].notificationId, | 416 | notificationId: args[0].notificationId, |
@@ -529,7 +528,7 @@ export default class ServicesStore extends Store { | |||
529 | } | 528 | } |
530 | 529 | ||
531 | @action _reorderService({ oldIndex, newIndex }) { | 530 | @action _reorderService({ oldIndex, newIndex }) { |
532 | const showDisabledServices = this.stores.settings.all.app.showDisabledServices; | 531 | const { showDisabledServices } = this.stores.settings.all.app; |
533 | const oldEnabledSortIndex = showDisabledServices ? oldIndex : this.all.indexOf(this.enabled[oldIndex]); | 532 | const oldEnabledSortIndex = showDisabledServices ? oldIndex : this.all.indexOf(this.enabled[oldIndex]); |
534 | const newEnabledSortIndex = showDisabledServices ? newIndex : this.all.indexOf(this.enabled[newIndex]); | 533 | const newEnabledSortIndex = showDisabledServices ? newIndex : this.all.indexOf(this.enabled[newIndex]); |
535 | 534 | ||
@@ -548,8 +547,6 @@ export default class ServicesStore extends Store { | |||
548 | service.order = services[s.id]; | 547 | service.order = services[s.id]; |
549 | }); | 548 | }); |
550 | }); | 549 | }); |
551 | |||
552 | this._reorderAnalytics(); | ||
553 | } | 550 | } |
554 | 551 | ||
555 | @action _toggleNotifications({ serviceId }) { | 552 | @action _toggleNotifications({ serviceId }) { |
@@ -625,8 +622,8 @@ export default class ServicesStore extends Store { | |||
625 | } | 622 | } |
626 | 623 | ||
627 | _getUnreadMessageCountReaction() { | 624 | _getUnreadMessageCountReaction() { |
628 | const showMessageBadgeWhenMuted = this.stores.settings.all.app.showMessageBadgeWhenMuted; | 625 | const { showMessageBadgeWhenMuted } = this.stores.settings.all.app; |
629 | const showMessageBadgesEvenWhenMuted = this.stores.ui.showMessageBadgesEvenWhenMuted; | 626 | const { showMessageBadgesEvenWhenMuted } = this.stores.ui; |
630 | 627 | ||
631 | const unreadDirectMessageCount = this.allDisplayed | 628 | const unreadDirectMessageCount = this.allDisplayed |
632 | .filter(s => (showMessageBadgeWhenMuted || s.isNotificationEnabled) && showMessageBadgesEvenWhenMuted && s.isBadgeEnabled) | 629 | .filter(s => (showMessageBadgeWhenMuted || s.isNotificationEnabled) && showMessageBadgesEvenWhenMuted && s.isBadgeEnabled) |
@@ -751,10 +748,6 @@ export default class ServicesStore extends Store { | |||
751 | } | 748 | } |
752 | } | 749 | } |
753 | 750 | ||
754 | _reorderAnalytics = debounce(() => { | ||
755 | gaEvent('Service', 'order'); | ||
756 | }, ms('5s')); | ||
757 | |||
758 | _wrapIndex(index, delta, size) { | 751 | _wrapIndex(index, delta, size) { |
759 | return (((index + delta) % size) + size) % size; | 752 | return (((index + delta) % size) + size) % size; |
760 | } | 753 | } |