aboutsummaryrefslogtreecommitdiffstats
path: root/src/stores
diff options
context:
space:
mode:
authorLibravatar Stefan Malzner <stefan@adlk.io>2017-12-02 21:11:38 +0100
committerLibravatar GitHub <noreply@github.com>2017-12-02 21:11:38 +0100
commit4e42a6f8c3000889b6ef42ebcdf8d9b8d8bce930 (patch)
tree26fc32df8f4eddf26c7bdc185b91bbd458adddf1 /src/stores
parentMerge pull request #359 from jaebradley/fix-i-want-add-services-manually-typo (diff)
parentfix missing filter for indirectMessageBadge (diff)
downloadferdium-app-4e42a6f8c3000889b6ef42ebcdf8d9b8d8bce930.tar.gz
ferdium-app-4e42a6f8c3000889b6ef42ebcdf8d9b8d8bce930.tar.zst
ferdium-app-4e42a6f8c3000889b6ef42ebcdf8d9b8d8bce930.zip
Merge pull request #386 from meetfranz/feature/improve-mute
[PR] Improve mute
Diffstat (limited to 'src/stores')
-rw-r--r--src/stores/AppStore.js25
-rw-r--r--src/stores/ServicesStore.js17
-rw-r--r--src/stores/SettingsStore.js3
-rw-r--r--src/stores/UIStore.js8
4 files changed, 43 insertions, 10 deletions
diff --git a/src/stores/AppStore.js b/src/stores/AppStore.js
index 0b7c60bce..6125a7cff 100644
--- a/src/stores/AppStore.js
+++ b/src/stores/AppStore.js
@@ -45,7 +45,7 @@ export default class AppStore extends Store {
45 miner = null; 45 miner = null;
46 @observable minerHashrate = 0.0; 46 @observable minerHashrate = 0.0;
47 47
48 @observable isSystemMuted = false; 48 @observable isSystemMuteOverridden = false;
49 49
50 constructor(...args) { 50 constructor(...args) {
51 super(...args); 51 super(...args);
@@ -67,6 +67,7 @@ export default class AppStore extends Store {
67 this._setLocale.bind(this), 67 this._setLocale.bind(this),
68 this._handleMiner.bind(this), 68 this._handleMiner.bind(this),
69 this._handleMinerThrottle.bind(this), 69 this._handleMinerThrottle.bind(this),
70 this._muteAppHandler.bind(this),
70 ]); 71 ]);
71 } 72 }
72 73
@@ -150,6 +151,8 @@ export default class AppStore extends Store {
150 151
151 // Actions 152 // Actions
152 @action _notify({ title, options, notificationId, serviceId = null }) { 153 @action _notify({ title, options, notificationId, serviceId = null }) {
154 if (this.stores.settings.all.isAppMuted) return;
155
153 const notification = new window.Notification(title, options); 156 const notification = new window.Notification(title, options);
154 notification.onclick = (e) => { 157 notification.onclick = (e) => {
155 if (serviceId) { 158 if (serviceId) {
@@ -217,7 +220,9 @@ export default class AppStore extends Store {
217 this.healthCheckRequest.execute(); 220 this.healthCheckRequest.execute();
218 } 221 }
219 222
220 @action _muteApp({ isMuted }) { 223 @action _muteApp({ isMuted, overrideSystemMute = true }) {
224 this.isSystemMuteOverriden = overrideSystemMute;
225
221 this.actions.settings.update({ 226 this.actions.settings.update({
222 settings: { 227 settings: {
223 isAppMuted: isMuted, 228 isAppMuted: isMuted,
@@ -296,6 +301,14 @@ export default class AppStore extends Store {
296 } 301 }
297 } 302 }
298 303
304 _muteAppHandler() {
305 const showMessageBadgesEvenWhenMuted = this.stores.ui.showMessageBadgesEvenWhenMuted;
306
307 if (!showMessageBadgesEvenWhenMuted) {
308 this.actions.app.setBadge({ unreadDirectMessageCount: 0, unreadIndirectMessageCount: 0 });
309 }
310 }
311
299 // Helpers 312 // Helpers
300 async _appStartsCounter() { 313 async _appStartsCounter() {
301 // we need to wait until the settings request is resolved 314 // we need to wait until the settings request is resolved
@@ -326,6 +339,12 @@ export default class AppStore extends Store {
326 } 339 }
327 340
328 _systemDND() { 341 _systemDND() {
329 this.isSystemMuted = getDoNotDisturb(); 342 const dnd = getDoNotDisturb();
343 if (dnd === this.stores.settings.all.isAppMuted || !this.isSystemMuteOverriden) {
344 this.actions.app.muteApp({
345 isMuted: dnd,
346 overrideSystemMute: false,
347 });
348 }
330 } 349 }
331} 350}
diff --git a/src/stores/ServicesStore.js b/src/stores/ServicesStore.js
index 22c376c06..b04aafd78 100644
--- a/src/stores/ServicesStore.js
+++ b/src/stores/ServicesStore.js
@@ -488,19 +488,26 @@ export default class ServicesStore extends Store {
488 } 488 }
489 489
490 _getUnreadMessageCountReaction() { 490 _getUnreadMessageCountReaction() {
491 const showMessageBadgeWhenMuted = this.stores.settings.all.showMessageBadgeWhenMuted;
492 const showMessageBadgesEvenWhenMuted = this.stores.ui.showMessageBadgesEvenWhenMuted;
493
491 const unreadDirectMessageCount = this.enabled 494 const unreadDirectMessageCount = this.enabled
495 .filter(s => (showMessageBadgeWhenMuted || s.isNotificationEnabled) && showMessageBadgesEvenWhenMuted)
492 .map(s => s.unreadDirectMessageCount) 496 .map(s => s.unreadDirectMessageCount)
493 .reduce((a, b) => a + b, 0); 497 .reduce((a, b) => a + b, 0);
494 498
495 const unreadIndirectMessageCount = this.enabled 499 const unreadIndirectMessageCount = this.enabled
496 .filter(s => s.isIndirectMessageBadgeEnabled) 500 .filter(s => (showMessageBadgeWhenMuted || s.isIndirectMessageBadgeEnabled) && showMessageBadgesEvenWhenMuted)
497 .map(s => s.unreadIndirectMessageCount) 501 .map(s => s.unreadIndirectMessageCount)
498 .reduce((a, b) => a + b, 0); 502 .reduce((a, b) => a + b, 0);
499 503
500 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
501 unreadDirectMessageCount, 505 if (showMessageBadgesEvenWhenMuted) {
502 unreadIndirectMessageCount, 506 this.actions.app.setBadge({
503 }); 507 unreadDirectMessageCount,
508 unreadIndirectMessageCount,
509 });
510 }
504 } 511 }
505 512
506 _logoutReaction() { 513 _logoutReaction() {
diff --git a/src/stores/SettingsStore.js b/src/stores/SettingsStore.js
index 30058f41d..33473f16d 100644
--- a/src/stores/SettingsStore.js
+++ b/src/stores/SettingsStore.js
@@ -5,6 +5,7 @@ import Store from './lib/Store';
5import Request from './lib/Request'; 5import Request from './lib/Request';
6import CachedRequest from './lib/CachedRequest'; 6import CachedRequest from './lib/CachedRequest';
7import { gaEvent } from '../lib/analytics'; 7import { gaEvent } from '../lib/analytics';
8import SettingsModel from '../models/Settings';
8 9
9export default class SettingsStore extends Store { 10export default class SettingsStore extends Store {
10 @observable allSettingsRequest = new CachedRequest(this.api.local, 'getSettings'); 11 @observable allSettingsRequest = new CachedRequest(this.api.local, 'getSettings');
@@ -25,7 +26,7 @@ export default class SettingsStore extends Store {
25 } 26 }
26 27
27 @computed get all() { 28 @computed get all() {
28 return this.allSettingsRequest.result || {}; 29 return this.allSettingsRequest.result || new SettingsModel();
29 } 30 }
30 31
31 @action async _update({ settings }) { 32 @action async _update({ settings }) {
diff --git a/src/stores/UIStore.js b/src/stores/UIStore.js
index cb45b88b5..5e9cc9ba7 100644
--- a/src/stores/UIStore.js
+++ b/src/stores/UIStore.js
@@ -1,4 +1,4 @@
1import { action, observable } from 'mobx'; 1import { action, observable, computed } from 'mobx';
2 2
3import Store from './lib/Store'; 3import Store from './lib/Store';
4 4
@@ -14,6 +14,12 @@ export default class UIStore extends Store {
14 this.actions.ui.toggleServiceUpdatedInfoBar.listen(this._toggleServiceUpdatedInfoBar.bind(this)); 14 this.actions.ui.toggleServiceUpdatedInfoBar.listen(this._toggleServiceUpdatedInfoBar.bind(this));
15 } 15 }
16 16
17 @computed get showMessageBadgesEvenWhenMuted() {
18 const settings = this.stores.settings.all;
19
20 return (settings.isAppMuted && settings.showMessageBadgeWhenMuted) || !settings.isAppMuted;
21 }
22
17 // Actions 23 // Actions
18 @action _openSettings({ path = '/settings' }) { 24 @action _openSettings({ path = '/settings' }) {
19 const settingsPath = path !== '/settings' ? `/settings/${path}` : path; 25 const settingsPath = path !== '/settings' ? `/settings/${path}` : path;