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.js42
1 files changed, 38 insertions, 4 deletions
diff --git a/src/stores/ServicesStore.js b/src/stores/ServicesStore.js
index 66f37af26..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
@@ -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() {
@@ -497,12 +530,13 @@ export default class ServicesStore extends Store {
497 .reduce((a, b) => a + b, 0); 530 .reduce((a, b) => a + b, 0);
498 531
499 const unreadIndirectMessageCount = this.allDisplayed 532 const unreadIndirectMessageCount = this.allDisplayed
500 .filter(s => (showMessageBadgeWhenMuted || s.isIndirectMessageBadgeEnabled) && showMessageBadgesEvenWhenMuted && s.isBadgeEnabled) 533 .filter(s => (showMessageBadgeWhenMuted && showMessageBadgesEvenWhenMuted) && (s.isBadgeEnabled && s.isIndirectMessageBadgeEnabled))
501 .map(s => s.unreadIndirectMessageCount) 534 .map(s => s.unreadIndirectMessageCount)
502 .reduce((a, b) => a + b, 0); 535 .reduce((a, b) => a + b, 0);
503 536
504 // We can't just block this earlier, otherwise the mobx reaction won't be aware of the vars to watch in some cases 537 // We can't just block this earlier, otherwise the mobx reaction won't be aware of the vars to watch in some cases
505 if (showMessageBadgesEvenWhenMuted) { 538 if (showMessageBadgesEvenWhenMuted) {
539 console.log('set badge', unreadDirectMessageCount, unreadIndirectMessageCount);
506 this.actions.app.setBadge({ 540 this.actions.app.setBadge({
507 unreadDirectMessageCount, 541 unreadDirectMessageCount,
508 unreadIndirectMessageCount, 542 unreadIndirectMessageCount,