Fossil SCM

Minor cleanups in the chat-internal settings API and menu.

stephan 2021-01-04 03:26 trunk
Commit def06dc645db7edbdf9eee0919c7e2b031e42dbdd15e6503ffb1a6905ee7f5a6
1 file changed +13 -10
+13 -10
--- src/chat.js
+++ src/chat.js
@@ -350,16 +350,23 @@
350350
},
351351
settings:{
352352
get: (k,dflt)=>F.storage.get(k,dflt),
353353
getBool: (k,dflt)=>F.storage.getBool(k,dflt),
354354
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
+ },
355362
defaults:{
356363
"images-inline": !!F.config.chat.imagesInline,
357364
"edit-multiline": false,
358365
"monospace-messages": false,
359366
"chat-only-mode": false,
360
- "audible-alert": true,
367
+ "audible-alert": true
361368
}
362369
},
363370
/** Plays a new-message notification sound IF the audible-alert
364371
setting is true, else this is a no-op. Returns this.
365372
*/
@@ -929,24 +936,20 @@
929936
callback: ()=>Chat.toggleNavButtons()
930937
},{
931938
label: "Images inline",
932939
boolValue: ()=>Chat.settings.getBool('images-inline'),
933940
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")+".");
937943
}
938944
},{
939945
label: "Audible alerts",
940946
boolValue: ()=>Chat.settings.getBool('audible-alert'),
941947
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")+".");
948951
}
949952
}];
950953
951954
/**
952955
Rebuild the menu each time it's shown so that the toggles can
953956
--- 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

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button