Fossil SCM
Minor cleanups in the chat-internal settings API and menu.
Commit
def06dc645db7edbdf9eee0919c7e2b031e42dbdd15e6503ffb1a6905ee7f5a6
Parent
169ba8d4df37b91…
1 file changed
+13
-10
+13
-10
| --- src/chat.js | ||
| +++ src/chat.js | ||
| @@ -350,16 +350,23 @@ | ||
| 350 | 350 | }, |
| 351 | 351 | settings:{ |
| 352 | 352 | get: (k,dflt)=>F.storage.get(k,dflt), |
| 353 | 353 | getBool: (k,dflt)=>F.storage.getBool(k,dflt), |
| 354 | 354 | set: (k,v)=>F.storage.set(k,v), |
| 355 | + /* Toggles the boolean setting specified by k. Returns the | |
| 356 | + new value.*/ | |
| 357 | + toggle: function(k){ | |
| 358 | + const v = this.getBool(k); | |
| 359 | + this.set(k, !v); | |
| 360 | + return !v; | |
| 361 | + }, | |
| 355 | 362 | defaults:{ |
| 356 | 363 | "images-inline": !!F.config.chat.imagesInline, |
| 357 | 364 | "edit-multiline": false, |
| 358 | 365 | "monospace-messages": false, |
| 359 | 366 | "chat-only-mode": false, |
| 360 | - "audible-alert": true, | |
| 367 | + "audible-alert": true | |
| 361 | 368 | } |
| 362 | 369 | }, |
| 363 | 370 | /** Plays a new-message notification sound IF the audible-alert |
| 364 | 371 | setting is true, else this is a no-op. Returns this. |
| 365 | 372 | */ |
| @@ -929,24 +936,20 @@ | ||
| 929 | 936 | callback: ()=>Chat.toggleNavButtons() |
| 930 | 937 | },{ |
| 931 | 938 | label: "Images inline", |
| 932 | 939 | boolValue: ()=>Chat.settings.getBool('images-inline'), |
| 933 | 940 | callback: function(){ |
| 934 | - const v = Chat.settings.getBool('images-inline',true); | |
| 935 | - Chat.settings.set('images-inline', !v); | |
| 936 | - F.toast.message("Image mode set to "+(v ? "hyperlink" : "inline")+"."); | |
| 941 | + const v = Chat.settings.toggle('images-inline'); | |
| 942 | + F.toast.message("Image mode set to "+(v ? "inline" : "hyperlink")+"."); | |
| 937 | 943 | } |
| 938 | 944 | },{ |
| 939 | 945 | label: "Audible alerts", |
| 940 | 946 | boolValue: ()=>Chat.settings.getBool('audible-alert'), |
| 941 | 947 | callback: function(){ |
| 942 | - const v = Chat.settings.getBool('audible-alert'); | |
| 943 | - Chat.settings.set('audible-alert', !v); | |
| 944 | - if(!v){ | |
| 945 | - setTimeout(()=>Chat.playNewMessageSound(), 50); | |
| 946 | - } | |
| 947 | - F.toast.message("Audio notifications "+(v ? "disabled" : "enabled")+"."); | |
| 948 | + const v = Chat.settings.toggle('audible-alert'); | |
| 949 | + if(v) setTimeout(()=>Chat.playNewMessageSound(), 50); | |
| 950 | + F.toast.message("Audio notifications "+(v ? "enabled" : "disabled")+"."); | |
| 948 | 951 | } |
| 949 | 952 | }]; |
| 950 | 953 | |
| 951 | 954 | /** |
| 952 | 955 | Rebuild the menu each time it's shown so that the toggles can |
| 953 | 956 |
| --- src/chat.js | |
| +++ src/chat.js | |
| @@ -350,16 +350,23 @@ | |
| 350 | }, |
| 351 | settings:{ |
| 352 | get: (k,dflt)=>F.storage.get(k,dflt), |
| 353 | getBool: (k,dflt)=>F.storage.getBool(k,dflt), |
| 354 | set: (k,v)=>F.storage.set(k,v), |
| 355 | defaults:{ |
| 356 | "images-inline": !!F.config.chat.imagesInline, |
| 357 | "edit-multiline": false, |
| 358 | "monospace-messages": false, |
| 359 | "chat-only-mode": false, |
| 360 | "audible-alert": true, |
| 361 | } |
| 362 | }, |
| 363 | /** Plays a new-message notification sound IF the audible-alert |
| 364 | setting is true, else this is a no-op. Returns this. |
| 365 | */ |
| @@ -929,24 +936,20 @@ | |
| 929 | callback: ()=>Chat.toggleNavButtons() |
| 930 | },{ |
| 931 | label: "Images inline", |
| 932 | boolValue: ()=>Chat.settings.getBool('images-inline'), |
| 933 | callback: function(){ |
| 934 | const v = Chat.settings.getBool('images-inline',true); |
| 935 | Chat.settings.set('images-inline', !v); |
| 936 | F.toast.message("Image mode set to "+(v ? "hyperlink" : "inline")+"."); |
| 937 | } |
| 938 | },{ |
| 939 | label: "Audible alerts", |
| 940 | boolValue: ()=>Chat.settings.getBool('audible-alert'), |
| 941 | callback: function(){ |
| 942 | const v = Chat.settings.getBool('audible-alert'); |
| 943 | Chat.settings.set('audible-alert', !v); |
| 944 | if(!v){ |
| 945 | setTimeout(()=>Chat.playNewMessageSound(), 50); |
| 946 | } |
| 947 | F.toast.message("Audio notifications "+(v ? "disabled" : "enabled")+"."); |
| 948 | } |
| 949 | }]; |
| 950 | |
| 951 | /** |
| 952 | Rebuild the menu each time it's shown so that the toggles can |
| 953 |
| --- src/chat.js | |
| +++ src/chat.js | |
| @@ -350,16 +350,23 @@ | |
| 350 | }, |
| 351 | settings:{ |
| 352 | get: (k,dflt)=>F.storage.get(k,dflt), |
| 353 | getBool: (k,dflt)=>F.storage.getBool(k,dflt), |
| 354 | set: (k,v)=>F.storage.set(k,v), |
| 355 | /* Toggles the boolean setting specified by k. Returns the |
| 356 | new value.*/ |
| 357 | toggle: function(k){ |
| 358 | const v = this.getBool(k); |
| 359 | this.set(k, !v); |
| 360 | return !v; |
| 361 | }, |
| 362 | defaults:{ |
| 363 | "images-inline": !!F.config.chat.imagesInline, |
| 364 | "edit-multiline": false, |
| 365 | "monospace-messages": false, |
| 366 | "chat-only-mode": false, |
| 367 | "audible-alert": true |
| 368 | } |
| 369 | }, |
| 370 | /** Plays a new-message notification sound IF the audible-alert |
| 371 | setting is true, else this is a no-op. Returns this. |
| 372 | */ |
| @@ -929,24 +936,20 @@ | |
| 936 | callback: ()=>Chat.toggleNavButtons() |
| 937 | },{ |
| 938 | label: "Images inline", |
| 939 | boolValue: ()=>Chat.settings.getBool('images-inline'), |
| 940 | callback: function(){ |
| 941 | const v = Chat.settings.toggle('images-inline'); |
| 942 | F.toast.message("Image mode set to "+(v ? "inline" : "hyperlink")+"."); |
| 943 | } |
| 944 | },{ |
| 945 | label: "Audible alerts", |
| 946 | boolValue: ()=>Chat.settings.getBool('audible-alert'), |
| 947 | callback: function(){ |
| 948 | const v = Chat.settings.toggle('audible-alert'); |
| 949 | if(v) setTimeout(()=>Chat.playNewMessageSound(), 50); |
| 950 | F.toast.message("Audio notifications "+(v ? "enabled" : "disabled")+"."); |
| 951 | } |
| 952 | }]; |
| 953 | |
| 954 | /** |
| 955 | Rebuild the menu each time it's shown so that the toggles can |
| 956 |